| | |
Getting an input from arrow keys.
Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
Okay, I'm trying to make a python game (not with pygame), I want it to use the arrow keys. But the thing is, I don't know how to get it to respond to the arrow keys. So here's what I want to do.
If the user presses the up arrow key set the variable 'direction' to up, if the press the down arrow key set direction to 'down' etc. Would this be possible? If so, how? The only thing I know is that you need to use KeyboardInterupt or something like that.
If the user presses the up arrow key set the variable 'direction' to up, if the press the down arrow key set direction to 'down' etc. Would this be possible? If so, how? The only thing I know is that you need to use KeyboardInterupt or something like that.
0
#4 Oct 9th, 2009
Here is an example of a Tkinter key logger ...
python Syntax (Toggle Plain Text)
# KeyLogger_tk2.py # show a character key when pressed without using Enter key # hide the Tkinter GUI window, only console shows try: # Python2 import Tkinter as tk except ImportError: # Python3 import tkinter as tk def key(event): """shows key or tk code for the key""" if event.keysym == 'Escape': root.destroy() if event.char == event.keysym: # normal number and letter characters print( 'Normal Key %r' % event.char ) elif len(event.char) == 1: # charcters like []/.,><#$ also Return and ctrl/key print( 'Punctuation Key %r (%r)' % (event.keysym, event.char) ) else: # f1 to f12, shift keys, caps lock, Home, End, Delete ... print( 'Special Key %r' % event.keysym ) root = tk.Tk() print( "Press a key (Escape key to exit):" ) root.bind_all('<Key>', key) # don't show the tk window root.withdraw() root.mainloop()
May 'the Google' be with you!
![]() |
Similar Threads
- Using arrow keys to navigate around a form (PHP)
- How do you check if arrow keys are pressed? (C)
- how to detect arrow keys?? (C)
- SQL Plus command line: Arrow keys not giving previous commands back (Oracle)
- Find if user hit arrow keys (C++)
- moving around in an array with arrow keys (C++)
- need help with the use of arrow keys (C)
Other Threads in the Python Forum
- Previous Thread: Need help with tic tac toe
- Next Thread: Image processing using python
Views: 452 | Replies: 4
| Thread Tools | Search this Thread |
Tag cloud for Python
advanced assignment beginner bluetooth chmod cmd code convert count csv data decimals dictionary dynamic dynamically enter examples excel external file float format frange ftp function gnu gui heads hints homework import input jaunty java leftmouse line linux list lists loan loop module mouse multiple newb number numbers output parsing path pointer port prime program programming projects push py2exe pygame pyglet pyopengl pyqt python random raw_input recursion recursive scrolledtext slicenotation software ssh stderr string strings table tennis terminal text thread threading time tkinter tlapse tooltip tuple tutorial ubuntu unicode unix urllib urllib2 variable variables ventrilo web webservice windows wx.wizard wxpython xlib






. 