问题描述
我需要按照计算机键盘上特定键的按键/释放次序记录事件的相应时间。
问题中的关键也应该在沮丧时发出声音(也许是一个孤独的叹息 - / b
嘻嘻)。从表面上看,使用来自Tkinter的合适组合,时间和
winsound来实现这一目标似乎应该相当简单。如果有人已经这样做了,如果他们愿意与我分享结果,我将不胜感激。如果没有,我会欢迎建议
如何进行。谢谢。
和平
I need to record the respective times of the events in a sequence of
presses/releases of a particular key on the computer keyboard. The key in
question should also make a sound when depressed (perhaps a forlorn sigh - tee
hee). On the face of it, it seems like it should be fairly straightforward to
achieve this with a suitable combination of ingredients from Tkinter, time and
winsound. If someone has already done it, I would be grateful if they were
willing to share the results with me. If not, I would welcome suggestions as to
how to proceed. Thanks.
Peace
推荐答案
这是否必须工作无论计算机上发生了什么?
计算机,或者如果仅在窗口
的情况下才能正常工作申请是否有效? (换句话说,
如果按键只发送到这个程序那么很容易做到,
但是如果你想在任何时候捕获*所有*按键,
你不能这样做,AFAIK,只使用像wxPython这样的GUI工具包
或Tkinter ......你必须使用某种类型的操作系统挂钩。 )
-Peter
Does this have to work regardless of what else is going on on
the computer, or is it okay if it works only when the window
for this particular application is active? (In other words,
it''s easy to do if the keypresses go only to this program,
but if you want to capture *all* keypresses at all times,
you can''t do it, AFAIK, using just a GUI toolkit like wxPython
or Tkinter... you have to use an OS hook of some kind.)
-Peter
然后wxPython中的相关位将涉及这些行
行,从我正在处理的一个小应用程序中删除:
class Frame(wx.Frame):
def __init __(self,title):
wx.Frame .__ init __(self,None,-1,title)
p = wx.Panel(self,-1)
self.Bind(wx.EVT_KEY_DOWN,self.OnKeyDown)
#self.Bind(wx.EVT_KEY_DOWN,self.OnKeyUp)
def OnKeyDown(self,evt):
如果evt.GetKeyCode()== wx.WXK_DELETE:
#whatever
你会的能够使用time.time()或time.clock()来记录按键的次数
,而且我一般不会使用
音频所以我不知道什么是最好的。
替代方案是Pygame,,其中
当然可以处理关键的东西和音频。
而且Tkinter当然可以做到,但我不做Tkinter。 :)
-Peter
Then the relevant bits in wxPython would involve lines like these
lines, pruned from a little app I''ve been working on:
class Frame(wx.Frame):
def __init__(self, title):
wx.Frame.__init__(self, None, -1, title)
p = wx.Panel(self, -1)
self.Bind(wx.EVT_KEY_DOWN, self.OnKeyDown)
# self.Bind(wx.EVT_KEY_DOWN, self.OnKeyUp)
def OnKeyDown(self, evt):
if evt.GetKeyCode() == wx.WXK_DELETE:
# whatever
You would be able to use time.time() or time.clock() to record
the times of the keypresses, and I don''t generally work with
audio so I don''t know what would be best.
An alternative would be Pygame, http://www.pygame.org/, which
certainly could handle both the key stuff and the audio.
And Tkinter could certainly do it to, but I don''t do Tkinter. :)
-Peter
这篇关于'电报'作为数据输入的一种手段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!