Keypress that will always be read by program wether it has focus or not?

Just starting out? Need help? Post your questions and find answers here.
User avatar
matalog
Enthusiast
Enthusiast
Posts: 305
Joined: Tue Sep 05, 2017 10:07 am

Keypress that will always be read by program wether it has focus or not?

Post 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.
User avatar
HeX0R
Addict
Addict
Posts: 1219
Joined: Mon Sep 20, 2004 7:12 am
Location: Hell

Re: Keypress that will always be read by program wether it has focus or not?

Post by HeX0R »

like a keylogger you mean?
User avatar
matalog
Enthusiast
Enthusiast
Posts: 305
Joined: Tue Sep 05, 2017 10:07 am

Re: Keypress that will always be read by program wether it has focus or not?

Post 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.
User avatar
idle
Always Here
Always Here
Posts: 6026
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Keypress that will always be read by program wether it has focus or not?

Post 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 
Quin
Addict
Addict
Posts: 1135
Joined: Thu Mar 31, 2022 7:03 pm
Location: Colorado, United States
Contact:

Re: Keypress that will always be read by program wether it has focus or not?

Post by Quin »

How about using a global hotkey (also Windows-only).
User avatar
idle
Always Here
Always Here
Posts: 6026
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Keypress that will always be read by program wether it has focus or not?

Post 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
Quin
Addict
Addict
Posts: 1135
Joined: Thu Mar 31, 2022 7:03 pm
Location: Colorado, United States
Contact:

Re: Keypress that will always be read by program wether it has focus or not?

Post 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.
AZJIO
Addict
Addict
Posts: 2225
Joined: Sun May 14, 2017 1:48 am

Re: Keypress that will always be read by program wether it has focus or not?

Post by AZJIO »

WM_HOTKEY (example)
Example of use in the TextCorrection program
BarryG
Addict
Addict
Posts: 4219
Joined: Thu Apr 18, 2019 8:17 am

Re: Keypress that will always be read by program wether it has focus or not?

Post by BarryG »

HeX0R wrote: Wed Aug 28, 2024 11:22 pmlike a keylogger you mean?
Another term is macro recorder.
Axolotl
Addict
Addict
Posts: 872
Joined: Wed Dec 31, 2008 3:36 pm

Re: Keypress that will always be read by program wether it has focus or not?

Post 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
Just because it worked doesn't mean it works.
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
User avatar
matalog
Enthusiast
Enthusiast
Posts: 305
Joined: Tue Sep 05, 2017 10:07 am

Re: Keypress that will always be read by program wether it has focus or not?

Post 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.
Post Reply