| | |
KeyPress event with holding down the key
![]() |
Ah, thanks to both of you. Yup, as far as I can tell, it's interpreting the continuous press as you said, as a repeated keypress/keyrelease event pair. My guess is that it's to do with the Mac or possibly the version of Tkinter I'm using.
I'm looking forward to what you find out, Jeff. Could you please post it here or send me a private message when you hear?
Cheers,
Aot
I'm looking forward to what you find out, Jeff. Could you please post it here or send me a private message when you hear?
Cheers,
Aot
You will have to sit there with a stopwatch, but this could do the timing for you ...
python Syntax (Toggle Plain Text)
# count how many times the keyboard is scanned on # one continuous keypress of character 'a' import Tkinter as tk class MyFrame(tk.Frame): def __init__(self, master): tk.Frame.__init__(self, master) # method call counter self.counter_press = 0 self.pack() root.bind_all('<a>', self.key_press) def key_press(self, event): self.counter_press += 1 # show result in title root.title(str(self.counter_press)) root = tk.Tk() root.geometry("400x30+0+0") app1 = MyFrame(root) root.mainloop()
May 'the Google' be with you!
•
•
Join Date: Nov 2007
Posts: 1
Reputation:
Solved Threads: 0
I was having the same problem, the ideas here brought me to the solution, using the after_idle methode:
python Syntax (Toggle Plain Text)
from Tkinter import * class MyFrame(Frame): def __init__(self, master): tk.Frame.__init__(self, master) # method call counter self.pack() self.afterId = None root.bind('<KeyPress-a>', self.key_press) root.bind('<KeyRelease-a>', self.key_release) def key_press(self, event): if self.afterId != None: self.after_cancel( self.afterId ) self.afterId = None else: print 'key pressed %s' % event.time def key_release(self, event): self.afterId = self.after_idle( self.process_release, event ) def process_release(self, event): print 'key release %s' % event.time self.afterId = None root = Tk() root.geometry("400x30+0+0") app1 = MyFrame(root) root.mainloop()
Last edited by Quarks; Nov 4th, 2007 at 6:09 pm.
![]() |
Other Threads in the Python Forum
- Previous Thread: noob: What and when you would use Decimal vs Float Type
- Next Thread: assign the values to each members of a large list of class objects
| Thread Tools | Search this Thread |
accessdenied advanced aliased apache application argv beginner bits calling casino change clear command convert corners count csv cturtle cursor def definedlines dynamic dynamically edit event events file float format frange function google homework i/o iframe inches input jaunty keyboard lapse line linux list lists loop matching microphone mouse movingimageswithpygame multiple newb number numbers numeric obexftp output parameters parsing path prime programming projects py py2exe pygame pyopengl python random rational raw_input recursion remote return reverse session signal software sprite statictext string strings syntax tails text threading time tlapse tuple ubuntu unicode unit urllib urllib2 valueerror variable voip web-scrape whileloop word wxpython






