简体   繁体   English

如何在Linux中获取箭头键并在键盘上输入键以表现得像windows7

[英]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 . 我使用的是Python 2.7Tkinter 8.5 I am using OptionMenu s to allow user to do setup on machine. 我正在使用OptionMenu来允许用户在机器上进行设置。

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. 当我在Windows下运行时,我可以使用键盘上的箭头键遍历下拉列表,然后使用键盘输入选择选项。 This is not working on Linux (Debian Wheezy). 这不适用于Linux(Debian Wheezy)。

How do I bind KP_Enter to behave as return key? 如何绑定KP_Enter以表现为返回键?

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()

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. 使用这个脚本(从这里开始 ),当你按任意键时,很容易识别由Tkinter触发的键事件,无论是<Return><KP_Enter> ,还是(不知何故,也许你的键盘有一个有趣的映射)其他。

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()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM