// returns true if event is handled private bool ProcessKeyPressInt(int nCode, IntPtr wParam, IntPtr lParam) { try { if (nCode < 0) { return(false); } switch (wParam.ToInt32()) { case LowLevelAdapter.WM_KEYDOWN: case LowLevelAdapter.WM_SYSKEYDOWN: var keybdinput = (KEYBDINPUT)Marshal.PtrToStructure(lParam, typeof(KEYBDINPUT)); var keyData = (Keys)keybdinput.Vk; keyData |= LowLevelAdapter.KeyPressed(Keys.ControlKey) ? Keys.Control : 0; keyData |= LowLevelAdapter.KeyPressed(Keys.Menu) ? Keys.Alt : 0; keyData |= LowLevelAdapter.KeyPressed(Keys.ShiftKey) ? Keys.Shift : 0; var winPressed = LowLevelAdapter.KeyPressed(Keys.LWin) || LowLevelAdapter.KeyPressed(Keys.RWin); var args = new KeyboardEventArgs(keyData, winPressed); OnKeyboardEvent(args); return(args.Handled); } } catch { } return(false); }
static void Main() { var f2 = new Form2(); var c = new ApplicationContext(f2); Application.Run(c); return; if (mutex.WaitOne(TimeSpan.Zero, true)) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); var settings = Settings.Init(); var engine = new Switcher(settings); Application.ApplicationExit += (s, a) => { engine.Dispose(); }; var app = new SettingsForm(settings, engine); app.Exit += (s, e) => Application.Exit(); var context = new ApplicationContext(app); Application.Run(context); mutex.ReleaseMutex(); } else { LowLevelAdapter.SendShowSettingsMessage(); } }
private void ConvertSelection() { LowLevelAdapter.BackupClipboard(); LowLevelAdapter.SendCopy(); var selection = Clipboard.GetText(); LowLevelAdapter.RestoreClipboard(); if (String.IsNullOrEmpty(selection)) { return; } LowLevelAdapter.ReleasePressedFnKeys(); var keys = new List <Keys>(selection.Length); for (var i = 0; i < selection.Length; i++) { keys.Add(LowLevelAdapter.ToKey(selection[i])); } LowLevelAdapter.SetNextKeyboardLayout(); foreach (var key in keys) { Debug.Write(key); if (key != Keys.None) { LowLevelAdapter.SendKeyPress(key, (key & Keys.Shift) != Keys.None); } } }
private void InitializeValues() { shortcutTextBox.LostFocus += unsetCurrentInput; shortcutTextBox.Leave += unsetCurrentInput; shortcutTextBox.GotFocus += setCurrentInput; shortcutTextBox.Enter += setCurrentInput; shortcutTextBox.Text = settings.SwitchHotkey.ToString(); List <string> keys = new List <string> { Utils.GetKeyCombinationString(new[] { Keys.CapsLock }), Utils.GetKeyCombinationString(new[] { Keys.Shift, Keys.Alt }), Utils.GetKeyCombinationString(new[] { Keys.ControlKey, Keys.Space }), Utils.GetKeyCombinationString(new[] { Keys.Alt, Keys.Space }), Utils.GetKeyCombinationString(new[] { Keys.ControlKey }) }; keys.ForEach(s => comboBoxAdditionalSwitch.Items.Add(s)); //settings.AdditionalSwitchHotkey = //comboBoxAdditionalSwitch.SelectedIndex = keys.IndexOf(GetKeyCombinationString()) //comboBoxAdditionalSwitch.Items.Add(Keys.); if (settings.AdditionalSwitchHotkey != null) { checkboxAdditionalSwitch.Checked = true; var additionalKeys = Utils.ParseKeys(settings.AdditionalSwitchHotkey); string keyCombinationString = Utils.GetKeyCombinationString(additionalKeys); comboBoxAdditionalSwitch.SelectedIndex = comboBoxAdditionalSwitch.Items.IndexOf(keyCombinationString); } var locales = LowLevelAdapter.GetkeyboardLayouts(); for (int i = 0; i < locales.Length; i++) { Keys userSettings = Keys.None; if (settings.SwitchToParticularLayout != null) { var result = settings.SwitchToParticularLayout.TryGetValue(locales[i].LocaleId, out userSettings); } Label comboBoxKeyboarLayouts = new Label(); ComboBox comboBoxSwitchKey = new ComboBox(); GenerateCombox(locales[i], i, comboBoxKeyboarLayouts, comboBoxSwitchKey); InicializeSwitchSettingsLine(comboBoxKeyboarLayouts, comboBoxSwitchKey, locales[i].Lang, userSettings); } if (settings.SwitchToParticularLayout?.Any() ?? false) { switchKeyboardCheckox.Checked = true; switchToLayoutControls.ForEach(c => c.Enabled = true); } else { switchKeyboardCheckox.Checked = false; switchToLayoutControls.ForEach(c => c.Enabled = false); } }
public void Start() { if (IsStarted()) { return; } hookId = LowLevelAdapter.SetHook(LowLevelAdapter.WH_MOUSE_LL, callback); }
public void Stop() { if (!IsStarted()) { return; } LowLevelAdapter.ReleaseHook(hookId); hookId = IntPtr.Zero; }
/** * SETTINGS */ void SaveSettings() { settings.Save(); if (settings.AutoStart == true) { LowLevelAdapter.CreateAutorunShortcut(); } else { LowLevelAdapter.DeleteAutorunShortcut(); } }
private void ConvertLast() { LowLevelAdapter.ReleasePressedFnKeys(); var word = currentWord.ToList(); var backspaces = Enumerable.Repeat<Keys>(Keys.Back, word.Count); foreach (var vkCode in backspaces) { LowLevelAdapter.SendKeyPress(vkCode, false); } // funny fix for my skype Thread.Sleep(20); LowLevelAdapter.SetNextKeyboardLayout(); foreach (var data in word) { LowLevelAdapter.SendKeyPress(data.KeyCode, data.Shift); } }
private void OnKeyPress(KeyboardEventArgs evtData) { var vkCode = evtData.KeyCode; if (evtData.Equals(SwitchHotkey)) { ConvertLast(); evtData.Handled = true; return; } if (evtData.Equals(AdditionalSwitch)) { LowLevelAdapter.SetNextKeyboardLayout(); evtData.Handled = true; return; } if (SwitchToLocale.Keys.Any(t=>t.Equals(evtData))) { uint locale = SwitchToLocale.First(t=>Equals(t.Key, evtData)).Value; LowLevelAdapter.SetLayout(locale); } if (evtData.Equals(ConvertSelectionHotkey)) { ConvertSelection(); } if (this.HaveTrackingKeys(evtData)) return; var notModified = !this.HaveModifiers(evtData); if (vkCode == Keys.Space && notModified) { AddToCurrentWord(evtData); return; } if (vkCode == Keys.Back && notModified) { RemoveLast(); return; } if (IsPrintable(evtData)) { if (GetPreviousVkCode() == Keys.Space) { BeginNewWord(); } AddToCurrentWord(evtData); return; } // default: BeginNewWord(); }
private IntPtr ProcessMouse(int nCode, IntPtr wParam, IntPtr lParam) { try { if (nCode >= 0) { switch (wParam.ToInt32()) { case LowLevelAdapter.WM_LBUTTONDOWN: case LowLevelAdapter.WM_RBUTTONDOWN: OnMouseEvent(new EventArgs()); break; } } } catch { } return(LowLevelAdapter.NextHook(nCode, wParam, lParam)); }
private IntPtr ProcessKeyPress(int nCode, IntPtr wParam, IntPtr lParam) { return(ProcessKeyPressInt(nCode, wParam, lParam) ? new IntPtr(1) : LowLevelAdapter.NextHook(nCode, wParam, lParam)); }
private void SwitchLayout() { BeginNewWord(); LowLevelAdapter.SetNextKeyboardLayout(); }