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
elif
is 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 pressedshift
ands
anddown
, and theelif
is 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.