![]() |
|
[A5] Keyboard state without a display |
kenmasters1976
Member #8,794
July 2007
|
Is it possible to use al_get_keyboard_state() without a display or with no display focused?. I've tried and it seems it only works with a display and only if it is the currently active window. Needless to say, keyboard events won't work without a display either.
|
Chris Katko
Member #1,881
January 2002
![]() |
kenmasters1976 said: I've tried and it seems it only works with a display and only if it is the currently active window. I think that's Allegro's choice of API (which is not atypical). You can only process EVENT's that are actually sent to your window because that's the normal "windows/GUI" expectation. There are global API's for keyboard events but it's not coming from DirectX, IIRC. According to here, DirectX doesn't support global keys. But they could be wrong. https://hydrogenaud.io/index.php/topic,63872.0.html In my google searching "DirectX" and "global hotkeys" came up with almost no useful results. [edit] If you have a few specific keys, there is RegisterHotKey. Otherwise, it looks like you hook into a low-level keyboard handler. Per this: https://stackoverflow.com/questions/5259322/catching-global-hotkeys-windows -----sig: |
Edgar Reynaldo
Major Reynaldo
May 2007
![]() |
Allegro's KB state comes from the window events. You need a window to get events. Hence, you need a window to get KB input. Otherwise, you need to do what Katko suggested, and hook the low level keyboard process. Just google code for a keylogger. My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
kenmasters1976
Member #8,794
July 2007
|
Thanks for your replies. I wanted to use Allegro for a background process (no display) that would stop whenever a key is pressed. I guess it's not possible with Allegro alone, then, and I will have to look into those low-level routines. Thanks for the links. Quote: Just google code for a keylogger. Yeah, I guess that's kinda what I need, thanks.
|
Edgar Reynaldo
Major Reynaldo
May 2007
![]() |
It looks like you might be able to capture key presses with WM_INPUT as well, even if the window is not in the foreground, as alluded to by : MSDN WM_INPUT message said: Parameters wParam The input code. This parameter can be one of the following values. RIM_INPUT Input occurred while the application was in the foreground. The application must call DefWindowProc so the system can perform cleanup. RIM_INPUTSINK Input occurred while the application was not in the foreground. The application must call DefWindowProc so the system can perform the cleanup. lParam A handle to the RAWINPUT structure that contains the raw input from the device.
So you might want to look into Raw Input : Low level hooks have some restrictions and caveats. IIRC, back when I wrote ManyMouse, I had to hook the low level mouse handler, but it had to be stored inside a dll for it to work properly, at least according to Microsoft. My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
kenmasters1976
Member #8,794
July 2007
|
Thanks for the link and sorry for the late reply. I found this library which offers "A multi-platform C library to provide global keyboard and mouse hooks from userland". I'm currently trying it on Linux.
|
Doctor Cop
Member #16,833
April 2018
![]() |
What are you trying to do?
|
|