0

I developing small Windows Form By C# contain two Buttons to handle keys, button1 handle (Ctrl+q) and button2 handle (Ctrl+e) , I using these Shortcuts when Reading Text in PDF viewer App , I prefer use mouse or Touchscreen to do these two actions enter image description here Any help will appreciated thanks

I tried to do send.keys function but did`t work

Ali Sami
  • 1
  • 2
  • 1
    Well, if you use Buttons to send keys, when you click a Button you make your Form the foreground Window, so the keys combination is sent to your Form's active Control, which is the Button you just pressed. You may want to activate the external app first. Or, code your Form and Buttons not to receive Focus, so the active application is not changed when you click a Button in your Form – Jimi Nov 20 '22 at 11:34
  • That is Right , So I tried to make this form like as (on screen Keyboard) and don`t effect on foreground application if you find solution for that it will be appreciated. – Ali Sami Nov 20 '22 at 13:08
  • You can take the code here: [How to keep a Form always on top without stealing focus from the active Window?](https://stackoverflow.com/a/65439642/7444103). The Form sets a couple of styles in CreateParams (`WS_EX_NOACTIVATE = 0x08000000` and `WS_EX_TOOLWINDOW = 0x00000080`). The Button is a Custom Control that just sets `SetStyle(ControlStyles.Selectable, false);` in its Constructor -- As you can see in the animation, that Form doesn't steal the Focus from the active application when a Button is clicked – Jimi Nov 20 '22 at 13:33
  • You could also attach your Form to the eternal application's Window like this: [Move window when external application's window moves](https://stackoverflow.com/a/48812831/7444103). See the notes about also hooking `EVENT_SYSTEM_FOREGROUND` (you just add another event to watch), so you don't need to keep *the Form on top*, you just move to the foreground when the hooked app does – Jimi Nov 20 '22 at 13:37

0 Answers0