Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get arrow keys and enter key on key pad in Linux to behave like windows7

I am developing a program to control a machine that will have only a keypad connected. I am using Python 2.7 and Tkinter 8.5. I am using OptionMenus to allow user to do setup on machine.

When I run under Windows I am able to use arrow keys on keypad to traverse thru drop down list, then use key pad enter to pick option. This is not working on Linux (Debian Wheezy).

How do I bind KP_Enter to behave as return key?

import Tkinter

def c(self, event):
   event.b[".keysym"] = "<<space>>"
   print "button invoked"

t = Tkinter.Tk()

b = Tkinter.OptionMenu(t, ".500", ".510", ".520", 
                       ".550", ".560", ".570", ".580", command=c)
t.bind("<KP_Enter>", c)
e = Tkinter.Entry()
e.pack()
b.pack(anchor=Tkinter.E)

t.mainloop()
like image 749
pglitt Avatar asked Mar 28 '14 22:03

pglitt


People also ask

How do I switch the numeric keypad from arrow keys back to number keys?

Yes, it was as you say: pressing the arrow (shift) + delete (NumLock) wich you can find it above of "7" button of the keypad.

How do you set WASD as an arrow key?

To switch wasd keys and arrow keys, please presss FN + W .


Video Answer


1 Answers

With this script (from here), it should be easy to identify the key event triggered by Tkinter when you press any key, whether that is <Return>, <KP_Enter>, or (somehow, maybe your keypad has a funny mapping) something else.

Just look at the console output when you press the desired button, and use that key event name in your actual code.

import Tkinter

def callback(e):
    print e.keysym

w = Tkinter.Frame(width=512, height=512)
w.bind("<KeyPress>", callback)
w.focus_set()
w.pack()
w.mainloop()
like image 198
Junuxx Avatar answered Oct 17 '22 16:10

Junuxx