0

I'm actually coding a game and i have a problem in that following situation ... When i press Up and Then Down it only recognize one at the same time.

So my question is : How can i make my program recognize both keys at the same time ?

Thanks in advance

from lycee import *
from tkinter import *

fenetre=Tk()

def print_flèche_haut(event):
   print("Flèche haut")

def print_flèche_bas(event):
   print("Flèche bas")

fenetre.bind("<Up>",print_flèche_haut)
fenetre.bind("<Down>",print_flèche_bas)

fenetre.mainloop()
  • What do you mean by "at the same time"? Do you mean your program either recognizes up or down, but not the other? When I run your code, both bindings work. – FamousJameous Nov 17 '17 at 17:56
  • They both work but not at the same time, if i press Down and then Up, it forgets the first one that is still pressed. I wanna my code execute the both functions if i press the two keys. An exemple : Flèche haut Flèche bas Flèche bas Flèche bas Flèche bas Flèche bas Flèche bas – Flavien Rey Nov 17 '17 at 17:59
  • Okay, so you press and hold up and it prints "haut" repeatedly until you press down. When you release down, you want it to resume repeatedly printing "haut". Is that correct? Or you want it to print both while they are both pressed? – FamousJameous Nov 17 '17 at 18:03
  • No, the thing i want it to do is when i press continuously Down and then i press Up without holding Down, i want my game to executing in the same time the both functions binded to Up and Down. For exemple, in my game, i have to functions, one to jump and the other to move my hero to the right. But with this type of code i can't jump and move to the right in the same time, for exemple, when i press Right continuously and then i wanna jump, if i press the key corresponding to jump, it stops my movement to the right, even if i don't hold my key uesd to go to the right, and it executes the jump. – Flavien Rey Nov 17 '17 at 18:15
  • Thank you all, you were amazing, it works, ican do my game now !!! – Flavien Rey Nov 17 '17 at 19:38

0 Answers0