I have this problem. I'm trying trigger my diagonal idle animations when when two keys are released ('s' and 'd') but this does not seem to work. I could not seem to find an answer on these forums. This is what i have:
First of all, consider using scancodes instead of key characters. Former are universal on all keyboards to match standard latin layout, latter are locale-dependent. 2nd argument to the keyreleased function is its scancode.
Second of all, one variable can only contain one value, so key variable can't simultaneously be "s" and "d" so it never would have worked. This is why you need to handle key strokes one at a time. Additionally, events are activated one at a time, so you can't catch simultaneous keystrokes with this anyhow.
Third of all, you probably don't want to detect if keystrokes happen simultaneously because computers have high temporal resolution, what to you look simultaneous, to computer it looks like there's gaping void in between. You may simply end up in a situation where you can't press or release keys in close enough succession to trigger diagonal logic, it'll instead be just cardinal directions. Again, nothing is truly simultaneous because things are processed one at a time - even if they're extremely close. You'll have to use some additional logic to keep animation angle diagonal.
Lastly, if you want to implement such logic, you probably should do that in update function rather than in event handler.
First of all, consider using scancodes instead of key characters. Former are universal on all keyboards to match standard latin layout, latter are locale-dependent. 2nd argument to the keyreleased function is its scancode.
Second of all, one variable can only contain one value, so key variable can't simultaneously be "s" and "d" so it never would have worked. This is why you need to handle key strokes one at a time. Additionally, events are activated one at a time, so you can't catch simultaneous keystrokes with this anyhow.
Third of all, you probably don't want to detect if keystrokes happen simultaneously because computers have high temporal resolution, what to you look simultaneous, to computer it looks like there's gaping void in between. You may simply end up in a situation where you can't press or release keys in close enough succession to trigger diagonal logic, it'll instead be just cardinal directions. Again, nothing is truly simultaneous because things are processed one at a time - even if they're extremely close. You'll have to use some additional logic to keep animation angle diagonal.
Lastly, if you want to implement such logic, you probably should do that in update function rather than in event handler.
Thank you, that also helped me out. I've checked the love2d wiki for scancodes, but it doesnt show any scancode in particular, could you give or cite an example of scancode? like A,D ?
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.