private void OnKeyPress(object sender, KeyMapperKeyPressedEventArgs e) { int scancode = e.Key.Scancode; int extended = e.Key.Extended; if (capturingFromKey) { // Have we been sent a dud?? if (scancode == 0) { // Can't use a disabled key as From map = new KeyMapping(); } else { SetMapToBlankMapping(scancode, extended); } } else { // Can't tell from the passed key whether it's mapped or not as // if it is, we get the mapped scancode and have no way of telling // what the original key was (it's possible 2 keys could be mapped to the // same key, meaning can't just do a reverse lookup.) // So, mapping to a mapped key is de facto allowed. map = new KeyMapping(map.From, new Key(scancode, extended)); } SetupForm(); }
private void ReceiveKeyPress(object sender, KeyMapperKeyPressedEventArgs e) { if (e != null) { KBHookStruct key = e.Key; // Because we are intercepting a keypress before it is processed, can't ask // what state the keyboard is in using Form.IsKeySet or WIN32API funcs like // GetKeyState. So, using fields for the state of each key. // (In fact, the only thing this achieves is live updating of the Toggle Lock Menu if user presses // a lock key while menu is open. It's a small thing, but would be a shame to lose it) switch (key.VirtualKeyCode) { case (int)KeyboardHelper.ToggleKey.CapsLock: _isCapsLockOn = !_isCapsLockOn; SetToggleMenuButtonStates(); break; case (int)KeyboardHelper.ToggleKey.NumLock: _isNumLockOn = !_isNumLockOn; SetToggleMenuButtonStates(); break; case (int)KeyboardHelper.ToggleKey.ScrollLock: _isScrollLockOn = !_isScrollLockOn; if (_isScrollLockOn != Form.IsKeyLocked(Keys.Scroll)) { SetToggleMenuButtonStates(); } break; } } }