private void TextBoxKeyDown(object sender, KeyEventArgs e) { Microsoft.VisualBasic.Devices.Keyboard UserKeyBoard = new Microsoft.VisualBasic.Devices.Keyboard(); bool AltPressed = UserKeyBoard.AltKeyDown; bool ControlPressed = UserKeyBoard.CtrlKeyDown; bool ShiftPressed = UserKeyBoard.ShiftKeyDown; ModifierKeys LocalModifier = ModifierKeys.None; if (AltPressed) { LocalModifier = ModifierKeys.Alt; } if (ControlPressed) { LocalModifier |= ModifierKeys.Control; } if (ShiftPressed) { LocalModifier |= ModifierKeys.Shift; } switch (e.Key) { case Key.Back: this.Text = CheckModifier(LocalModifier) ? HotKeyShared.CombineShortcut(LocalModifier, Keys.Back) : ""; e.Handled = true; break; case Key.Space: this.Text = CheckModifier(LocalModifier) ? HotKeyShared.CombineShortcut(LocalModifier, Keys.Space) : ""; e.Handled = true; break; case Key.Delete: this.Text = CheckModifier(LocalModifier) ? HotKeyShared.CombineShortcut(LocalModifier, Keys.Delete) : ""; e.Handled = true; break; case Key.Home: this.Text = CheckModifier(LocalModifier) ? HotKeyShared.CombineShortcut(LocalModifier, Keys.Home) : ""; e.Handled = true; break; case Key.PageUp: this.Text = CheckModifier(LocalModifier) ? HotKeyShared.CombineShortcut(LocalModifier, Keys.PageUp) : ""; e.Handled = true; break; case Key.Next: this.Text = CheckModifier(LocalModifier) ? HotKeyShared.CombineShortcut(LocalModifier, Keys.Next) : ""; e.Handled = true; break; case Key.End: this.Text = CheckModifier(LocalModifier) ? HotKeyShared.CombineShortcut(LocalModifier, Keys.End) : ""; break; case Key.Up: this.Text = CheckModifier(LocalModifier) ? HotKeyShared.CombineShortcut(LocalModifier, Keys.Up) : ""; break; case Key.Down: this.Text = CheckModifier(LocalModifier) ? HotKeyShared.CombineShortcut(LocalModifier, Keys.Down) : ""; break; case Key.Right: this.Text = CheckModifier(LocalModifier) ? HotKeyShared.CombineShortcut(LocalModifier, Keys.Right) : ""; break; case Key.Left: this.Text = CheckModifier(LocalModifier) ? HotKeyShared.CombineShortcut(LocalModifier, Keys.Left) : ""; break; } }
private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled) { try { Keys KeyPressed = (Keys)wParam; Microsoft.VisualBasic.Devices.Keyboard UserKeyBoard = new Microsoft.VisualBasic.Devices.Keyboard(); bool AltPressed = UserKeyBoard.AltKeyDown; bool ControlPressed = UserKeyBoard.CtrlKeyDown; bool ShiftPressed = UserKeyBoard.ShiftKeyDown; ModifierKeys LocalModifier = ModifierKeys.None; if (AltPressed) { LocalModifier = ModifierKeys.Alt; } if (ControlPressed) { LocalModifier |= ModifierKeys.Control; } if (ShiftPressed) { LocalModifier |= ModifierKeys.Shift; } switch ((KeyboardMessages)msg) { case KeyboardMessages.WmSyskeydown: case KeyboardMessages.WmKeydown: switch (KeyPressed) { case Keys.Control: case Keys.ControlKey: case Keys.LControlKey: case Keys.RControlKey: case Keys.Shift: case Keys.ShiftKey: case Keys.LShiftKey: case Keys.RShiftKey: case Keys.Alt: case Keys.Menu: case Keys.LMenu: case Keys.RMenu: case Keys.LWin: return(IntPtr.Zero); //case Keys.Back: // this.Text = Keys.None.ToString(); // return IntPtr.Zero; } if (LocalModifier != ModifierKeys.None) { this.Text = HotKeyShared.CombineShortcut(LocalModifier, KeyPressed); } else { if (ForceModifiers) { this.Text = ""; this.isFocused = false; this.UpdateState(); System.Media.SystemSounds.Asterisk.Play(); MessageBox.Show("You have to specify a modifier like 'Control', 'Alt' or 'Shift'"); } else { this.Text = KeyPressed.ToString(); } } return(IntPtr.Zero);; case KeyboardMessages.WmSyskeyup: case KeyboardMessages.WmKeyup: if (!String.IsNullOrWhiteSpace(Text.Trim()) || this.Text != Keys.None.ToString()) { if (HotKeyIsSetEvent != null) { var e = new HotKeyIsSetEventArgs(HotKeyIsSetEvent, UserKey, UserModifier); base.RaiseEvent(e); if (e.Cancel) { this.Text = ""; isFocused = false; UpdateState(); } } } return(IntPtr.Zero); } } catch (OverflowException) { } return(IntPtr.Zero); }
private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled) { try { Keys KeyPressed = (Keys)wParam; Microsoft.VisualBasic.Devices.Keyboard UserKeyBoard = new Microsoft.VisualBasic.Devices.Keyboard(); bool AltPressed = UserKeyBoard.AltKeyDown; bool ControlPressed = UserKeyBoard.CtrlKeyDown; bool ShiftPressed = UserKeyBoard.ShiftKeyDown; ModifierKeys LocalModifier = ModifierKeys.None; if (AltPressed) { LocalModifier = ModifierKeys.Alt; } if (ControlPressed) { LocalModifier |= ModifierKeys.Control; } if (ShiftPressed) { LocalModifier |= ModifierKeys.Shift; } switch ((KeyboardMessages)msg) { case KeyboardMessages.WmSyskeydown: case KeyboardMessages.WmKeydown: switch (KeyPressed) { case Keys.Control: case Keys.ControlKey: case Keys.LControlKey: case Keys.RControlKey: case Keys.Shift: case Keys.ShiftKey: case Keys.LShiftKey: case Keys.RShiftKey: case Keys.Alt: case Keys.Menu: case Keys.LMenu: case Keys.RMenu: case Keys.LWin: return IntPtr.Zero; //case Keys.Back: // this.Text = Keys.None.ToString(); // return IntPtr.Zero; } if (LocalModifier != ModifierKeys.None) { this.Text = HotKeyShared.CombineShortcut(LocalModifier, KeyPressed); } else { if (ForceModifiers) { this.Text = ""; this.isFocused = false; this.UpdateState(); System.Media.SystemSounds.Asterisk.Play(); MessageBox.Show("You have to specify a modifier like 'Control', 'Alt' or 'Shift'"); } else { this.Text = KeyPressed.ToString(); } } return IntPtr.Zero; ; case KeyboardMessages.WmSyskeyup: case KeyboardMessages.WmKeyup: if (!String.IsNullOrWhiteSpace(Text.Trim()) || this.Text != Keys.None.ToString()) { if (HotKeyIsSetEvent != null) { var e = new HotKeyIsSetEventArgs(HotKeyIsSetEvent, UserKey, UserModifier); base.RaiseEvent(e); if (e.Cancel) { this.Text = ""; isFocused = false; UpdateState(); } } } return IntPtr.Zero; } } catch (OverflowException) { } return IntPtr.Zero; }
private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled) { if (!Enabled) { return IntPtr.Zero; } //For LocalHotKeys, determine if modifiers Alt, Shift and Control is pressed. Microsoft.VisualBasic.Devices.Keyboard UserKeyBoard = new Microsoft.VisualBasic.Devices.Keyboard(); bool AltPressed = UserKeyBoard.AltKeyDown; bool ControlPressed = UserKeyBoard.CtrlKeyDown; bool ShiftPressed = UserKeyBoard.ShiftKeyDown; ModifierKeys LocalModifier = ModifierKeys.None; if (AltPressed) { LocalModifier = ModifierKeys.Alt; } if (ControlPressed) { LocalModifier |= ModifierKeys.Control; } if (ShiftPressed) { LocalModifier |= ModifierKeys.Shift; } switch ((KeyboardMessages)msg) { case (KeyboardMessages.WmSyskeydown): case (KeyboardMessages.WmKeydown): Keys keydownCode = (Keys)(int)wParam; if (KeyPressEvent != null) KeyPressEvent(this, new HotKeyEventArgs(keydownCode, LocalModifier, RaiseLocalEvent.OnKeyDown)); //Check if a chord has started. if (InChordMode) { //Check if the Key down is a modifier, we'll have to wait for a real key. switch (keydownCode) { case Keys.Control: case Keys.ControlKey: case Keys.LControlKey: case Keys.RControlKey: case Keys.Shift: case Keys.ShiftKey: case Keys.LShiftKey: case Keys.RShiftKey: case Keys.Alt: case Keys.Menu: case Keys.LMenu: case Keys.RMenu: case Keys.LWin: return IntPtr.Zero; } ChordHotKey ChordMain = ChordHotKeyContainer.Find ( delegate(ChordHotKey cm) { return ((cm.BaseKey == PreChordKey) && (cm.BaseModifier == PreChordModifier) && (cm.ChordKey == keydownCode) && (cm.ChordModifier == LocalModifier)); } ); if (ChordMain != null) { ChordMain.RaiseOnHotKeyPressed(); if (ChordPressed != null && ChordMain.Enabled == true) ChordPressed(this, new ChordHotKeyEventArgs(ChordMain)); InChordMode = false; return IntPtr.Zero; } InChordMode = false; new Microsoft.VisualBasic.Devices.Computer().Audio.PlaySystemSound(System.Media.SystemSounds.Exclamation); return IntPtr.Zero; } //Check for a LocalHotKey. LocalHotKey KeyDownHotkey = LocalHotKeyContainer.Find ( delegate(LocalHotKey d) { return ((d.Key == keydownCode) && (d.Modifier == LocalModifier) && (d.WhenToRaise == RaiseLocalEvent.OnKeyDown)); } ); if (KeyDownHotkey != null) { KeyDownHotkey.RaiseOnHotKeyPressed(); if (LocalHotKeyPressed != null && KeyDownHotkey.Enabled == true) LocalHotKeyPressed(this, new LocalHotKeyEventArgs(KeyDownHotkey)); return IntPtr.Zero; } //Check for ChordHotKeys. ChordHotKey ChordBase = ChordHotKeyContainer.Find ( delegate(ChordHotKey c) { return ((c.BaseKey == keydownCode) && (c.BaseModifier == LocalModifier)); } ); if (ChordBase != null) { PreChordKey = ChordBase.BaseKey; PreChordModifier = ChordBase.BaseModifier; var e = new PreChordHotKeyEventArgs(new LocalHotKey(ChordBase.Name, ChordBase.BaseModifier, ChordBase.BaseKey)); if (ChordStarted != null) ChordStarted(this, e); InChordMode = !e.HandleChord; return IntPtr.Zero; } InChordMode = false; return IntPtr.Zero; case (KeyboardMessages.WmSyskeyup): case (KeyboardMessages.WmKeyup): Keys keyupCode = (Keys)(int)wParam; if (KeyPressEvent != null) KeyPressEvent(this, new HotKeyEventArgs(keyupCode, LocalModifier, RaiseLocalEvent.OnKeyDown)); LocalHotKey KeyUpHotkey = LocalHotKeyContainer.Find ( delegate(LocalHotKey u) { return ((u.Key == keyupCode) && (u.Modifier == LocalModifier) && (u.WhenToRaise == RaiseLocalEvent.OnKeyUp)); } ); if (KeyUpHotkey != null) { KeyUpHotkey.RaiseOnHotKeyPressed(); if (LocalHotKeyPressed != null && KeyUpHotkey.Enabled == true) LocalHotKeyPressed(this, new LocalHotKeyEventArgs(KeyUpHotkey)); return IntPtr.Zero; } return IntPtr.Zero; case KeyboardMessages.WmHotKey: GlobalHotKey Pressed = GlobalHotKeyContainer.Find ( delegate(GlobalHotKey g) { return (g.Id == (int)wParam); } ); Pressed.RaiseOnHotKeyPressed(); if (GlobalHotKeyPressed != null) GlobalHotKeyPressed(this, new GlobalHotKeyEventArgs(Pressed)); break; } return IntPtr.Zero; }
private void TextBoxKeyDown(object sender, KeyEventArgs e) { Microsoft.VisualBasic.Devices.Keyboard UserKeyBoard = new Microsoft.VisualBasic.Devices.Keyboard(); bool AltPressed = UserKeyBoard.AltKeyDown; bool ControlPressed = UserKeyBoard.CtrlKeyDown; bool ShiftPressed = UserKeyBoard.ShiftKeyDown; ModifierKeys LocalModifier = ModifierKeys.None; if (AltPressed) { LocalModifier = ModifierKeys.Alt; } if (ControlPressed) { LocalModifier |= ModifierKeys.Control; } if (ShiftPressed) { LocalModifier |= ModifierKeys.Shift; } switch (e.Key) { case Key.Back: this.Text = CheckModifier(LocalModifier) ? HotKeyShared.CombineShortcut(LocalModifier, Keys.Back) : ""; e.Handled = true; break; case Key.Space: this.Text = CheckModifier(LocalModifier) ? HotKeyShared.CombineShortcut(LocalModifier, Keys.Space) : ""; e.Handled = true; break; case Key.Delete: this.Text = CheckModifier(LocalModifier) ? HotKeyShared.CombineShortcut(LocalModifier, Keys.Delete) : ""; e.Handled = true; break; case Key.Home: this.Text = CheckModifier(LocalModifier) ? HotKeyShared.CombineShortcut(LocalModifier, Keys.Home) : ""; e.Handled = true; break; case Key.PageUp: this.Text = CheckModifier(LocalModifier) ? HotKeyShared.CombineShortcut(LocalModifier, Keys.PageUp) : ""; e.Handled = true; break; case Key.Next: this.Text = CheckModifier(LocalModifier) ? HotKeyShared.CombineShortcut(LocalModifier, Keys.Next) : ""; e.Handled = true; break; case Key.End: this.Text = CheckModifier(LocalModifier) ? HotKeyShared.CombineShortcut(LocalModifier, Keys.End) : ""; break; case Key.Up: this.Text = CheckModifier(LocalModifier) ? HotKeyShared.CombineShortcut(LocalModifier, Keys.Up) : ""; break; case Key.Down: this.Text = CheckModifier(LocalModifier) ? HotKeyShared.CombineShortcut(LocalModifier, Keys.Down) : ""; break; case Key.Right: this.Text = CheckModifier(LocalModifier) ? HotKeyShared.CombineShortcut(LocalModifier, Keys.Right) : ""; break; case Key.Left: this.Text = CheckModifier(LocalModifier) ? HotKeyShared.CombineShortcut(LocalModifier, Keys.Left) : ""; break; } }
public bool PreFilterMessage(ref Message m) { if (!Enabled) { return(false); } //Check if the form that the HotKeyManager is registered to is inactive. if (DisableOnManagerFormInactive) { if (Form.ActiveForm != null && this.ManagerForm != Form.ActiveForm) { return(false); } } //For LocalHotKeys, determine if modifiers Alt, Shift and Control is pressed. Microsoft.VisualBasic.Devices.Keyboard UserKeyBoard = new Microsoft.VisualBasic.Devices.Keyboard(); bool AltPressed = UserKeyBoard.AltKeyDown; bool ControlPressed = UserKeyBoard.CtrlKeyDown; bool ShiftPressed = UserKeyBoard.ShiftKeyDown; Modifiers LocalModifier = Modifiers.None; if (AltPressed) { LocalModifier = Modifiers.Alt; } if (ControlPressed) { LocalModifier |= Modifiers.Control; } if (ShiftPressed) { LocalModifier |= Modifiers.Shift; } switch ((KeyboardMessages)m.Msg) { case (KeyboardMessages.WmSyskeydown): case (KeyboardMessages.WmKeydown): Keys keydownCode = (Keys)(int)m.WParam & Keys.KeyCode; if (KeyPressEvent != null) { KeyPressEvent(this, new HotKeyEventArgs(keydownCode, LocalModifier, RaiseLocalEvent.OnKeyDown)); } //Check if a chord has started. if (InChordMode) { //Check if the Key down is a modifier, we'll have to wait for a real key. switch (keydownCode) { case Keys.Control: case Keys.ControlKey: case Keys.LControlKey: case Keys.RControlKey: case Keys.Shift: case Keys.ShiftKey: case Keys.LShiftKey: case Keys.RShiftKey: case Keys.Alt: case Keys.Menu: case Keys.LMenu: case Keys.RMenu: case Keys.LWin: return(true); } ChordHotKey ChordMain = Program.SysConfig.ChordHotKeyContainer.Find ( delegate(ChordHotKey cm) { return((cm.BaseKey == PreChordKey) && (cm.BaseModifier == PreChordModifier) && (cm.ChordKey == keydownCode) && (cm.ChordModifier == LocalModifier)); } ); if (ChordMain != null) { ChordMain.RaiseOnHotKeyPressed(); if (ChordPressed != null && ChordMain.Enabled == true) { ChordPressed(this, new ChordHotKeyEventArgs(ChordMain)); } InChordMode = false; return(true); } InChordMode = false; new Microsoft.VisualBasic.Devices.Computer().Audio.PlaySystemSound(System.Media.SystemSounds.Exclamation); return(true); } //Check for a LocalHotKey. LocalHotKey KeyDownHotkey = Program.SysConfig.LocalHotKeyContainer.Find ( delegate(LocalHotKey d) { return((d.Key == keydownCode) && (d.Modifier == LocalModifier) && (d.WhenToRaise == RaiseLocalEvent.OnKeyDown)); } ); if (KeyDownHotkey != null) { KeyDownHotkey.RaiseOnHotKeyPressed(); if (LocalHotKeyPressed != null && KeyDownHotkey.Enabled == true) { LocalHotKeyPressed(this, new LocalHotKeyEventArgs(KeyDownHotkey)); } return(KeyDownHotkey.SuppressKeyPress); } //Check for ChordHotKeys. ChordHotKey ChordBase = Program.SysConfig.ChordHotKeyContainer.Find ( delegate(ChordHotKey c) { return((c.BaseKey == keydownCode) && (c.BaseModifier == LocalModifier)); } ); if (ChordBase != null) { PreChordKey = ChordBase.BaseKey; PreChordModifier = ChordBase.BaseModifier; var e = new PreChordHotKeyEventArgs(new LocalHotKey(ChordBase.Name, ChordBase.BaseModifier, ChordBase.BaseKey)); if (ChordStarted != null) { ChordStarted(this, e); } InChordMode = !e.HandleChord; return(true); } InChordMode = false; return(false); case (KeyboardMessages.WmSyskeyup): case (KeyboardMessages.WmKeyup): Keys keyupCode = (Keys)(int)m.WParam & Keys.KeyCode; if (KeyPressEvent != null) { KeyPressEvent(this, new HotKeyEventArgs(keyupCode, LocalModifier, RaiseLocalEvent.OnKeyDown)); } LocalHotKey KeyUpHotkey = Program.SysConfig.LocalHotKeyContainer.Find ( delegate(LocalHotKey u) { return((u.Key == keyupCode) && (u.Modifier == LocalModifier) && (u.WhenToRaise == RaiseLocalEvent.OnKeyUp)); } ); if (KeyUpHotkey != null) { KeyUpHotkey.RaiseOnHotKeyPressed(); if (LocalHotKeyPressed != null && KeyUpHotkey.Enabled == true) { LocalHotKeyPressed(this, new LocalHotKeyEventArgs(KeyUpHotkey)); } return(KeyUpHotkey.SuppressKeyPress); } return(false); case (KeyboardMessages.WmHotKey): //var lpInt = (int)m.LParam; //Keys Key = (Keys)((lpInt >> 16) & 0xFFFF); //Modifiers modifier = (Modifiers)(lpInt & 0xFFFF); int Id = (int)m.WParam; GlobalHotKey Pressed = Program.SysConfig.GlobalHotKeyContainer.Find ( delegate(GlobalHotKey g) { return((g.Id == (int)Id)); } ); Pressed.RaiseOnHotKeyPressed(); if (GlobalHotKeyPressed != null) { GlobalHotKeyPressed(this, new GlobalHotKeyEventArgs(Pressed)); } return(true); default: return(false); } }
private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled) { if (!Enabled) { return(IntPtr.Zero); } //For LocalHotKeys, determine if modifiers Alt, Shift and Control is pressed. Microsoft.VisualBasic.Devices.Keyboard UserKeyBoard = new Microsoft.VisualBasic.Devices.Keyboard(); bool AltPressed = UserKeyBoard.AltKeyDown; bool ControlPressed = UserKeyBoard.CtrlKeyDown; bool ShiftPressed = UserKeyBoard.ShiftKeyDown; ModifierKeys LocalModifier = ModifierKeys.None; if (AltPressed) { LocalModifier = ModifierKeys.Alt; } if (ControlPressed) { LocalModifier |= ModifierKeys.Control; } if (ShiftPressed) { LocalModifier |= ModifierKeys.Shift; } switch ((KeyboardMessages)msg) { case (KeyboardMessages.WmSyskeydown): case (KeyboardMessages.WmKeydown): Keys keydownCode = (Keys)(int)wParam; if (KeyPressEvent != null) { KeyPressEvent(this, new HotKeyEventArgs(keydownCode, LocalModifier, RaiseLocalEvent.OnKeyDown)); } //Check if a chord has started. if (InChordMode) { //Check if the Key down is a modifier, we'll have to wait for a real key. switch (keydownCode) { case Keys.Control: case Keys.ControlKey: case Keys.LControlKey: case Keys.RControlKey: case Keys.Shift: case Keys.ShiftKey: case Keys.LShiftKey: case Keys.RShiftKey: case Keys.Alt: case Keys.Menu: case Keys.LMenu: case Keys.RMenu: case Keys.LWin: return(IntPtr.Zero); } ChordHotKey ChordMain = ChordHotKeyContainer.Where( item => (item.BaseKey == PreChordKey && item.BaseModifier == PreChordModifier && item.ChordKey == keydownCode && item.ChordModifier == LocalModifier)) .FirstOrDefault(); // ChordHotKey ChordMain = ChordHotKeyContainer.Find // ( // delegate(ChordHotKey cm) // { // return ((cm.BaseKey == PreChordKey) && (cm.BaseModifier == PreChordModifier) && (cm.ChordKey == keydownCode) && (cm.ChordModifier == LocalModifier)); // } //); if (ChordMain != null) { ChordMain.RaiseOnHotKeyPressed(); if (ChordPressed != null && ChordMain.Enabled == true) { ChordPressed(this, new ChordHotKeyEventArgs(ChordMain)); } InChordMode = false; new Microsoft.VisualBasic.Devices.Computer().Audio.PlaySystemSound(System.Media.SystemSounds.Exclamation); return(IntPtr.Zero); } InChordMode = false; return(IntPtr.Zero); } //Check for a LocalHotKey. LocalHotKey KeyDownHotkey = (from items in LocalHotKeyContainer where items.Key == keydownCode && items.Modifier == LocalModifier where items.WhenToRaise == RaiseLocalEvent.OnKeyDown select items).FirstOrDefault(); //LocalHotKey KeyDownHotkey = LocalHotKeyContainer.Find // ( // delegate(LocalHotKey d) // { // return ((d.Key == keydownCode) && (d.Modifier == LocalModifier)); // } //); if (KeyDownHotkey != null) { KeyDownHotkey.RaiseOnHotKeyPressed(); if (LocalHotKeyPressed != null && KeyDownHotkey.Enabled == true) { LocalHotKeyPressed(this, new LocalHotKeyEventArgs(KeyDownHotkey)); } return(IntPtr.Zero); } //Check for ChordHotKeys. ChordHotKey ChordBase = System.Linq.Enumerable.Where( ChordHotKeyContainer, item => item.BaseKey == keydownCode && item.BaseModifier == LocalModifier) .FirstOrDefault(); //ChordHotKey ChordBase = ChordHotKeyContainer.Find // ( // delegate(ChordHotKey c) // { // return ((c.BaseKey == keydownCode) && (c.BaseModifier == LocalModifier)); // } //); if (ChordBase != null) { PreChordKey = ChordBase.BaseKey; PreChordModifier = ChordBase.BaseModifier; var e = new PreChordHotKeyEventArgs(new LocalHotKey(ChordBase.Name, ChordBase.BaseModifier, ChordBase.BaseKey)); if (ChordStarted != null) { ChordStarted(this, e); } InChordMode = !e.HandleChord; return(IntPtr.Zero); } InChordMode = false; return(IntPtr.Zero); case (KeyboardMessages.WmSyskeyup): case (KeyboardMessages.WmKeyup): Keys keyupCode = (Keys)(int)wParam; if (KeyPressEvent != null) { KeyPressEvent(this, new HotKeyEventArgs(keyupCode, LocalModifier, RaiseLocalEvent.OnKeyDown)); } LocalHotKey KeyUpHotkey = (from items in LocalHotKeyContainer where items.Key == keyupCode && items.Modifier == LocalModifier where items.WhenToRaise == RaiseLocalEvent.OnKeyUp select items).FirstOrDefault(); //LocalHotKey KeyUpHotkey = LocalHotKeyContainer.Find // ( // delegate(LocalHotKey u) // { // return ((u.Key == keyupCode) && (u.Modifier == LocalModifier)); // } //); if (KeyUpHotkey != null) { KeyUpHotkey.RaiseOnHotKeyPressed(); if (LocalHotKeyPressed != null && KeyUpHotkey.Enabled == true) { LocalHotKeyPressed(this, new LocalHotKeyEventArgs(KeyUpHotkey)); } return(IntPtr.Zero); } return(IntPtr.Zero); case KeyboardMessages.WmHotKey: GlobalHotKey Pressed = GlobalHotKeyContainer.Where(item => item.Id == (int)wParam).FirstOrDefault(); //GlobalHotKey Pressed = GlobalHotKeyContainer.Find // ( // delegate(GlobalHotKey g) // { // return (g.Id == (int)wParam); // } //); Pressed.RaiseOnHotKeyPressed(); if (GlobalHotKeyPressed != null) { GlobalHotKeyPressed(this, new GlobalHotKeyEventArgs(Pressed)); } break; } return(IntPtr.Zero); }
public bool PreFilterMessage(ref Message m) { if (!Enabled) { return false; } //Check if the form that the HotKeyManager is registered to is inactive. if (DisableOnManagerFormInactive) if (Form.ActiveForm != null && this.ManagerForm != Form.ActiveForm) { return false; } //For LocalHotKeys, determine if modifiers Alt, Shift and Control is pressed. Microsoft.VisualBasic.Devices.Keyboard UserKeyBoard = new Microsoft.VisualBasic.Devices.Keyboard(); bool AltPressed = UserKeyBoard.AltKeyDown; bool ControlPressed = UserKeyBoard.CtrlKeyDown; bool ShiftPressed = UserKeyBoard.ShiftKeyDown; Modifiers LocalModifier = Modifiers.None; if (AltPressed) { LocalModifier = Modifiers.Alt; } if (ControlPressed) { LocalModifier |= Modifiers.Control; } if (ShiftPressed) { LocalModifier |= Modifiers.Shift; } switch ((KeyboardMessages)m.Msg) { case (KeyboardMessages.WmSyskeydown): case (KeyboardMessages.WmKeydown): Keys keydownCode = (Keys)(int)m.WParam & Keys.KeyCode; if (KeyPressEvent != null) KeyPressEvent(this, new HotKeyEventArgs(keydownCode, LocalModifier, RaiseLocalEvent.OnKeyDown)); //Check if a chord has started. if (InChordMode) { //Check if the Key down is a modifier, we'll have to wait for a real key. switch (keydownCode) { case Keys.Control: case Keys.ControlKey: case Keys.LControlKey: case Keys.RControlKey: case Keys.Shift: case Keys.ShiftKey: case Keys.LShiftKey: case Keys.RShiftKey: case Keys.Alt: case Keys.Menu: case Keys.LMenu: case Keys.RMenu: case Keys.LWin: return true; } ChordHotKey ChordMain = ChordHotKeyContainer.Find ( delegate(ChordHotKey cm) { return ((cm.BaseKey == PreChordKey) && (cm.BaseModifier == PreChordModifier) && (cm.ChordKey == keydownCode) && (cm.ChordModifier == LocalModifier)); } ); if (ChordMain != null) { ChordMain.RaiseOnHotKeyPressed(); if (ChordPressed != null && ChordMain.Enabled == true) ChordPressed(this, new ChordHotKeyEventArgs(ChordMain)); InChordMode = false; return true; } InChordMode = false; new Microsoft.VisualBasic.Devices.Computer().Audio.PlaySystemSound(System.Media.SystemSounds.Exclamation); return true; } //Check for a LocalHotKey. LocalHotKey KeyDownHotkey = LocalHotKeyContainer.Find ( delegate(LocalHotKey d) { return ((d.Key == keydownCode) && (d.Modifier == LocalModifier) && (d.WhenToRaise == RaiseLocalEvent.OnKeyDown)); } ); if (KeyDownHotkey != null) { KeyDownHotkey.RaiseOnHotKeyPressed(); if (LocalHotKeyPressed != null && KeyDownHotkey.Enabled == true) LocalHotKeyPressed(this, new LocalHotKeyEventArgs(KeyDownHotkey)); return KeyDownHotkey.SuppressKeyPress; } //Check for ChordHotKeys. ChordHotKey ChordBase = ChordHotKeyContainer.Find ( delegate(ChordHotKey c) { return ((c.BaseKey == keydownCode) && (c.BaseModifier == LocalModifier)); } ); if (ChordBase != null) { PreChordKey = ChordBase.BaseKey; PreChordModifier = ChordBase.BaseModifier; var e = new PreChordHotKeyEventArgs(new LocalHotKey(ChordBase.Name, ChordBase.BaseModifier, ChordBase.BaseKey)); if (ChordStarted != null) ChordStarted(this, e); InChordMode = !e.HandleChord; return true; } InChordMode = false; return false; case (KeyboardMessages.WmSyskeyup): case (KeyboardMessages.WmKeyup): Keys keyupCode = (Keys)(int)m.WParam & Keys.KeyCode; if (KeyPressEvent != null) KeyPressEvent(this, new HotKeyEventArgs(keyupCode, LocalModifier, RaiseLocalEvent.OnKeyDown)); LocalHotKey KeyUpHotkey = LocalHotKeyContainer.Find ( delegate(LocalHotKey u) { return ((u.Key == keyupCode) && (u.Modifier == LocalModifier) && (u.WhenToRaise == RaiseLocalEvent.OnKeyUp)); } ); if (KeyUpHotkey != null) { KeyUpHotkey.RaiseOnHotKeyPressed(); if (LocalHotKeyPressed != null && KeyUpHotkey.Enabled == true) LocalHotKeyPressed(this, new LocalHotKeyEventArgs(KeyUpHotkey)); return KeyUpHotkey.SuppressKeyPress; } return false; case (KeyboardMessages.WmHotKey): //var lpInt = (int)m.LParam; //Keys Key = (Keys)((lpInt >> 16) & 0xFFFF); //Modifiers modifier = (Modifiers)(lpInt & 0xFFFF); int Id = (int)m.WParam; GlobalHotKey Pressed = GlobalHotKeyContainer.Find ( delegate(GlobalHotKey g) { return ((g.Id == (int)Id)); } ); Pressed.RaiseOnHotKeyPressed(); if (GlobalHotKeyPressed != null) GlobalHotKeyPressed(this, new GlobalHotKeyEventArgs(Pressed)); return true; default: return false; } }
public static void UpdateSharePoint(string id, string age, string gender) { using (var context = new ClientContext(Constants.URL)) { context.Credentials = new SharePointOnlineCredentials(Constants.User, Program.GetPassSecure(Constants.Pass)); // Assume that the web has a list named "Announcements". List twitterList = context.Web.Lists.GetByTitle(Constants.ListTwitter); ListItem listItem = twitterList.GetItemById(id); listItem["Edad"] = age; listItem["Sexo"] = gender; listItem.Update(); context.ExecuteQuery(); Console.WriteLine("Actualizado"); Microsoft.VisualBasic.Devices.Keyboard keyboard = new Microsoft.VisualBasic.Devices.Keyboard(); Environment.Exit(0); } }