This is my code:
import keyboard as kb
def key_selected():
if kb.is_pressed('shift+s+down'):
return 'True1'
elif kb.is_pressed('shift+s+right+down'):
return 'True2'
else:
return 'NOTHING'
while True:
x = key_selected()
print(x)
It returns True1 even when I press 'shift+s+right+down'. How can resolve this?
The thing with
elifis that the condition is tested only if the previous conditions wereFalse. So when you pressshift + s + down + right,if kb.is_pressed('shift+s+down')is triggered because you have pressedshiftandsanddown, and theelifis ignored.If you reverse the order so that you check for the more specific condition first, it should work just fine.
does what you expect.