Page 1 of 1

Can love2D detect keypresses when unfocused?

Posted: Thu Sep 23, 2021 7:41 pm
by Connorses
I would like to press a key and have my love2D program respond without me first focusing the love2D window by clicking it. Would be useful for, say, a livestream visual that I can alter with a key press.

Re: Can love2D detect keypresses when unfocused?

Posted: Thu Sep 23, 2021 10:20 pm
by BrotSagtMist
Doesnt look like it.
If youre the only user a quick hack in would be to just read from /dev/input in a thread.
I am not aware of other simple ways, let alone one that universally works.

Re: Can love2D detect keypresses when unfocused?

Posted: Fri Sep 24, 2021 7:47 am
by zorg
While keyboard and mouse won't really work like that, you can try whether gamepad input works when unfocused, that has a higher chance i think.

Re: Can love2D detect keypresses when unfocused?

Posted: Fri Sep 24, 2021 3:54 pm
by grump
There's always the option to poll the keyboard through FFI, but that's OS-specific. For example, on Windows you can import and call GetAsyncKeyState to query the state of a key.