Page 1 of 1
Keypress that will always be read by program wether it has focus or not?
Posted: Wed Aug 28, 2024 11:18 pm
by matalog
Is there any way to get a key or combination of keys to always be recognised by a running program whether the running program is the one last clicked with the mouse or not? That is, it may not have the system's focus.
Re: Keypress that will always be read by program wether it has focus or not?
Posted: Wed Aug 28, 2024 11:22 pm
by HeX0R
like a keylogger you mean?
Re: Keypress that will always be read by program wether it has focus or not?
Posted: Thu Aug 29, 2024 12:01 am
by matalog
HeX0R wrote: Wed Aug 28, 2024 11:22 pm
like a keylogger you mean?
I have never heard the term, but searched and it is a horrible thing. I had a third party Android keyboard app once, and I happened to press shift and something by accident, and every single thing I typed on that phone in the previous months was pasted to the document I was in at the time. I guessed that that was how some people harvest passwords etc.
I suppose a keylogger would use the same procedure, but I just want one key or combination to definitely be recognised by a window, that I suspect not all users will remember to click before following the on screen instructions, as it is a stickywindow, it will always be on top and may not be obvious that it isn't active.
Re: Keypress that will always be read by program wether it has focus or not?
Posted: Thu Aug 29, 2024 1:49 am
by idle
windows only you can do it like this
Code: Select all
If Bool(GetAsyncKeyState_(#VK_SHIFT) And GetAsyncKeyState_(#VK_S))
Debug "shift + S "
EndIf
Re: Keypress that will always be read by program wether it has focus or not?
Posted: Thu Aug 29, 2024 2:59 am
by Quin
How about using a
global hotkey (also Windows-only).
Re: Keypress that will always be read by program wether it has focus or not?
Posted: Thu Aug 29, 2024 3:15 am
by idle
Quin wrote: Thu Aug 29, 2024 2:59 am
How about using a
global hotkey (also Windows-only).
I think you would need to set a window callback for that to work as it doesn't come through the pb event loop
Re: Keypress that will always be read by program wether it has focus or not?
Posted: Thu Aug 29, 2024 4:23 am
by Quin
You're correct, in fact one of my main PB projects has a massive WndProc bound with SetWindowCallback mostly for hotkeys like this.
Re: Keypress that will always be read by program wether it has focus or not?
Posted: Thu Aug 29, 2024 5:22 am
by AZJIO
WM_HOTKEY (example)
Example of use in the
TextCorrection program
Re: Keypress that will always be read by program wether it has focus or not?
Posted: Thu Aug 29, 2024 9:12 am
by BarryG
HeX0R wrote: Wed Aug 28, 2024 11:22 pmlike a keylogger you mean?
Another term is macro recorder.
Re: Keypress that will always be read by program wether it has focus or not?
Posted: Fri Aug 30, 2024 10:30 am
by Axolotl
At least on windows you can use a keyboard hook when RegisterHotkey_() failed.
I once made a small example years ago:
LowLevelKeyboardHook.pb
Re: Keypress that will always be read by program wether it has focus or not?
Posted: Fri Aug 30, 2024 10:29 pm
by matalog
Axolotl wrote: Fri Aug 30, 2024 10:30 am
At least on windows you can use a keyboard hook when RegisterHotkey_() failed.
I once made a small example years ago:
LowLevelKeyboardHook.pb
Thanks for all of the suggestions, I went with the last eample from Axolotl on their link and it works great with VK's.