Code: Select all
exceptions = { space = true }
if #key == 1 or #key == 3 and key:sub(1, 2) == "kp" or exceptions[key] then
-- it's a key that generates text input
else
-- it's not
end
Code: Select all
exceptions = { space = true }
if #key == 1 or #key == 3 and key:sub(1, 2) == "kp" or exceptions[key] then
-- it's a key that generates text input
else
-- it's not
end
Thanks for the suggestion, it beats mapping every single key (that was going to be my last resort). I guess it will need more exceptions for some weird keypad things like kp00, kp000, kp&&, kp||. It will also need more maintenance for future updates, for example if 'kp ' changes to 'kpspace' at some point. It's not as clean as having that extra bit of information available in the callback, and I suspect it won't handle unknown keys as well as the other solution would, but it should work for now. I'll open a ticket in the issue tracker later.pgimeno wrote:A fairly reasonable way to distinguish keypresses that generate text input
Code: Select all
local isCurrentlyEnteringText = false
function textBox:enter()
isCurrentlyEnteringText = true
end
function textBox:exit()
isCurrentlyEnteringText = false
end
function love.keypressed( key )
if not isCurrentlyEnteringText then
if key == 'q' or key == 'escape' then love.event.quit() end
end
end
With you so far.airstruck wrote:- The user can bind keypress combinations to actions. For example, the user could bind ctrl-s to save, f1 to show help, and backtick (tilde) to show a console. The program has no way of knowing in advance what keybinds the user will set up.
- The user can press keys on his keyboard. Some of these key presses will result in text input events, like the backtick key. Others will not, like the 'f1' key, or the 's' key when ctrl is also pressed.
- Text boxes exist, which can be focused by clicking on them, and unfocused by clicking somewhere else.
My last message was related to this though, maybe i couldn't explain my idea good enough eitherairstruck wrote:When a text box is focused, any keypresses that generate text input events, like the backtick key, should not trigger any action the user may have bound to that key. You want to be able to type a backtick in the text box without the console opening. However, any keypresses that do not generate text input should still trigger any action the user bound to them. You always want to be able to press f1 for help, or ctrl-s to save, regardless of whether a text box has focus.
Users browsing this forum: No registered users and 5 guests