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.
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
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.
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.
Just google code for a keylogger.
Yeah, I guess that's kinda what I need, thanks.
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 :
Parameters
wParam
The input code. This parameter can be one of the following values.
Value Meaning
RIM_INPUT
0
Input occurred while the application was in the foreground. The application must call DefWindowProc so the system can perform cleanup.
RIM_INPUTSINK
1
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 :
https://docs.microsoft.com/en-us/windows/desktop/inputdev/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.
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.
What are you trying to do?