Receive events on inactive Windows?
Receive events on inactive Windows?
Is it possible for an application to continue receiving events when its window is not the active one?
I am making an application which has a window of size 1x1 outside of the screen range (positioned at -1, -1). When the user presses an specific key (for example, F1), the window will be resized to an appropiate size, and put on the center of the desktop. The problem is that the application only receives the input events (a #WM_KEYDOWN message) when the application is the currently running one, not when it is working on the background.
Is it possible to change this behaviour so the application still receives events when in the background?
I am making an application which has a window of size 1x1 outside of the screen range (positioned at -1, -1). When the user presses an specific key (for example, F1), the window will be resized to an appropiate size, and put on the center of the desktop. The problem is that the application only receives the input events (a #WM_KEYDOWN message) when the application is the currently running one, not when it is working on the background.
Is it possible to change this behaviour so the application still receives events when in the background?
==Jedive==
MacBook Core Duo 2Ghz, 2GB, Intel GMA950, Leopard
Celeron M 1.5, 512MB, Intel 915GM, WinXP/DX9, Ubuntu
MacBook Core Duo 2Ghz, 2GB, Intel GMA950, Leopard
Celeron M 1.5, 512MB, Intel 915GM, WinXP/DX9, Ubuntu
-
- Addict
- Posts: 1073
- Joined: Fri Apr 25, 2003 11:13 pm
- Location: Netherlands
- Contact:
Using a global keyboard hook you can do anything you like.
However, the hook must reside in a dll.
Each app *will* load the dll.. when active + any key is pressed.
You'll need to manage a communication between the dll and your exe since the app actually loading the dll will not be in yopur exe's process.
I know since i did a similar thing (nocaps32.zip in my dl folder)
There is also the HOTKEY approach which is bad.
However, the hook must reside in a dll.
Each app *will* load the dll.. when active + any key is pressed.
You'll need to manage a communication between the dll and your exe since the app actually loading the dll will not be in yopur exe's process.
I know since i did a similar thing (nocaps32.zip in my dl folder)
There is also the HOTKEY approach which is bad.
-
- Addict
- Posts: 1073
- Joined: Fri Apr 25, 2003 11:13 pm
- Location: Netherlands
- Contact:
-
- Addict
- Posts: 1073
- Joined: Fri Apr 25, 2003 11:13 pm
- Location: Netherlands
- Contact:
Thanks everyone for your comments. It id working correctly now 
I done it by using the GlobalHotKeys PureLibrary, but I dodn't need to put anything in a dll, Edwin. Everything is on a single executable.
About putting the window on -1, -1, yeah, I did that because I was not sure if it was possible at all to capture events on hidden windows, so instead of hiding it, I moved to that location. Now I have seen that GlobalHotKeys works perfectly even when the window is hidden, so that's what I am doing now
Thanks everyone.

I done it by using the GlobalHotKeys PureLibrary, but I dodn't need to put anything in a dll, Edwin. Everything is on a single executable.
About putting the window on -1, -1, yeah, I did that because I was not sure if it was possible at all to capture events on hidden windows, so instead of hiding it, I moved to that location. Now I have seen that GlobalHotKeys works perfectly even when the window is hidden, so that's what I am doing now

Thanks everyone.
==Jedive==
MacBook Core Duo 2Ghz, 2GB, Intel GMA950, Leopard
Celeron M 1.5, 512MB, Intel 915GM, WinXP/DX9, Ubuntu
MacBook Core Duo 2Ghz, 2GB, Intel GMA950, Leopard
Celeron M 1.5, 512MB, Intel 915GM, WinXP/DX9, Ubuntu
- DoubleDutch
- Addict
- Posts: 3220
- Joined: Thu Aug 07, 2003 7:01 pm
- Location: United Kingdom
- Contact:
Use this OS call to register a hotkey...
Use this to unregister it...
When registered check for the message in your window callback.
This is all the library your using probabily does, but may take up less memory.
-Anthony
Code: Select all
RegisterHotKey_(WindowID(),1,modifier,key)
Code: Select all
UnregisterHotKey_(WindowID(),1)
Code: Select all
#WM_HOTKEY
This is all the library your using probabily does, but may take up less memory.
-Anthony
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
https://reportcomplete.com <- School end of term reports system
-
- Addict
- Posts: 1073
- Joined: Fri Apr 25, 2003 11:13 pm
- Location: Netherlands
- Contact:
It's obvious, you might mess with ordinary application behaviour.PB wrote:> There is also the HOTKEY approach which is bad
Why? A lot simpler than using a DLL and it doesn't require constant polling.
Capturing a key but continue in a global hook is different.
I'm not sure but i thought the hotkey will cancel an app's key.
Also, you might overide a previously hotkey set.. exactly why i think HK's are a bad approach.
-
- Addict
- Posts: 1073
- Joined: Fri Apr 25, 2003 11:13 pm
- Location: Netherlands
- Contact:
- DoubleDutch
- Addict
- Posts: 3220
- Joined: Thu Aug 07, 2003 7:01 pm
- Location: United Kingdom
- Contact:
If you try to set a hotkey that already is in use, the result will tell you.Also, you might overide a previously hotkey set.. exactly why i think HK's are a bad approach
-Anthony
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
https://reportcomplete.com <- School end of term reports system
> I'm not sure but i thought the hotkey will cancel an app's key
True, but only if you set a common key... for example setting "A" as a
hotkey will stop "A" being used in all other apps, but that would be a silly
thing to do.
> you might overide a previously hotkey set
Impossible, because the system would reject it and fail the registration.
> To be clear, i did not suggest a timer in a dll
I didn't mean the DLL was polling, I meant it as a separate solution, as in:
True, but only if you set a common key... for example setting "A" as a
hotkey will stop "A" being used in all other apps, but that would be a silly
thing to do.

> you might overide a previously hotkey set
Impossible, because the system would reject it and fail the registration.
> To be clear, i did not suggest a timer in a dll
I didn't mean the DLL was polling, I meant it as a separate solution, as in:
Code: Select all
; This halts your app until F1 is pressed when any window has the focus.
Repeat : Sleep_(1) : Until GetAsyncKeyState_(#VK_F1)<>0
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
"PureBasic won't be object oriented, period" - Fred.
-
- Addict
- Posts: 1073
- Joined: Fri Apr 25, 2003 11:13 pm
- Location: Netherlands
- Contact:
-
- Addict
- Posts: 1073
- Joined: Fri Apr 25, 2003 11:13 pm
- Location: Netherlands
- Contact:
>Repeat : Sleep_(1) : Until GetAsyncKeyState_(#VK_F1)<>0
Also a bad loop, it will most likely eat processortime.
While a timer loop only does on idle state.
I know this is prob. for hobby anyway, for real apps it remains a bad approach.
You should go back what it should do, you want to know if a certain key is pressed...
All the HK and even the timer is a so-so solution.
Maybe even the purpose might be so so.
(In fact, the purpose is unclear, it was only a request how to deal with this)
Also a bad loop, it will most likely eat processortime.
While a timer loop only does on idle state.
I know this is prob. for hobby anyway, for real apps it remains a bad approach.
You should go back what it should do, you want to know if a certain key is pressed...
All the HK and even the timer is a so-so solution.
Maybe even the purpose might be so so.
(In fact, the purpose is unclear, it was only a request how to deal with this)
- DoubleDutch
- Addict
- Posts: 3220
- Joined: Thu Aug 07, 2003 7:01 pm
- Location: United Kingdom
- Contact:
I don't understand what you mean, the result will mean that your request has failed - so pick another key.Can be, therefore it remains a bad scenario..
What does "Can be, therefore it remains a bad scenario" mean???
-Anthony
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
https://reportcomplete.com <- School end of term reports system