How to prevent command key's default OS behavior using Love2d (LÖVE) or Lua

80 views Asked by At

Is there a way to prevent the default OS behavior for a command key (i.e. prevent start menu opening and focus loss when the windows key is pressed) using Love2d (LÖVE) in particular, or Lua more generally. If I understand correctly, LÖVE uses LuaJIT, so it would be helpful if a Lua based approach did not involve Lua 5.2/5.3 functions that are not implemented in LuaJIT, but I could rebuild with the appropriate module or shim the LÖVE interpreter if necessary.

Having failed to find a simple solution on my own, I'm currently thinking I will have to create a Lua-C Module. If that is the case, any advice/links along those lines would be greatly appreciated. Thanks!

1

There are 1 answers

3
Nicol Bolas On

Lua certainly has no functionality for hijacking OS key functionality of this kind. Such things are too OS-specific for Lua to expose. And from its documentation, Love2D has no such functionality either.

While we're on the subject:

prevent start menu opening and focus loss when the windows key is pressed

It would be exceedingly rude to have your application prevent basic OS functionality like this from working. However good your game may be, it is not as important as the user being able to do what they actually want. If the user wants to switch to something else, that's their right, and you should not interfere. If the user accidentally pressed that button, that's their responsibility.

The only thing you should do is set up a love.focus callback, so that when the application loses focus you can automatically pause.