Exemplo n.º 1
0
        //====================== Functions ======================
        public static IntPtr HookCallback(int nCode, IntPtr wParam, IntPtr lParam) // 2. delegate method
        {
            if (nCode >= 0 && wParam == (IntPtr)WM_KEYDOWN)
            {
                int vkCode = Marshal.ReadInt32(lParam);

                //Console.WriteLine(vkCode);

                Keys PlayPause = Control.KeyPlayPause;

                if ((Keys)vkCode == Control.KeyPlayPause)
                {
                    VirtualKeyPress.PressPlayPause();
                }

                if ((Keys)vkCode == Control.KeyStop)
                {
                    VirtualKeyPress.PressStop();
                }

                if ((Keys)vkCode == Control.KeyNext)
                {
                    VirtualKeyPress.PressNext();
                }

                if ((Keys)vkCode == Control.KeyPrevious)
                {
                    VirtualKeyPress.PressPrevious();
                }
            }

            return(CallNextHookEx(Control.HookID, nCode, wParam, lParam));
        }
Exemplo n.º 2
0
        private void TB_ANY_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
        {
            System.Windows.Controls.TextBox CurrentTextBox = sender as System.Windows.Controls.TextBox;

            // Check if the pressed key is not a modifier key like "ctrl" or "shift" ...
            if (e.Key != Key.Tab && e.Key != (Key.LeftShift | Key.RightShift) && e.Key != (Key.LeftCtrl | Key.RightCtrl) && e.Key != (Key.LeftAlt | Key.RightAlt))             //(Keyboard.Modifiers & (ModifierKeys.Control | ModifierKeys.Shift)) == (ModifierKeys.Control | ModifierKeys.Shift))
            {
                // check if the pressed key is a system key like "F10" /bc they are toggels
                if (e.Key == Key.System)
                {
                    int hash = 0;
                    switch (e.SystemKey)
                    {
                    case Key.F10:
                        hash = e.Key.GetHashCode();
                        CurrentTextBox.Text = Key.F10.ToString();

                        // Press F10 again because its a toggle like he ALT key
                        VirtualKeyPress.PressKeyByByteValue((byte)hash);
                        break;

                    case (Key.LeftAlt):
                        hash = e.Key.GetHashCode();
                        CurrentTextBox.Text = "Alt";

                        // Press LeftAlt again because its a toggle like he ALT key
                        VirtualKeyPress.PressKeyByByteValue((byte)hash);
                        break;
                    }
                }

                else
                {
                    // Write pressed key in textbox
                    CurrentTextBox.Text = e.Key.ToString();
                }
            }
        }