473,466 Members | 1,456 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

'telegraphy' as a means of data entry

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
Jul 18 '05 #1
11 1514
Elaine Jackson wrote:
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.


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
Jul 18 '05 #2

"Peter Hansen" <pe***@engcorp.com> wrote in message
news:8Y********************@powergate.ca...
| Elaine Jackson wrote:
|
| > 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.
|
| 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

Just when the window is active.
Jul 18 '05 #3
Elaine Jackson wrote:
"Peter Hansen" <pe***@engcorp.com> wrote:
| Elaine Jackson wrote:
|
| > I need to record the respective times of the events in a sequence of
| > presses/releases of a particular key on the computer keyboard.
|
| 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?

Just when the window is active.


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
Jul 18 '05 #4
Peter Hansen wrote:
| > I need to record the respective times of the events in a sequence of
| > presses/releases of a particular key on the computer keyboard.
And Tkinter could certainly do it to, but I don't do Tkinter. :)


in Tkinter, you'll find the event time (in milliseconds) in the time
attribute of the event descriptor:

from Tkinter import *

frame = Frame(width=100, height=100)
frame.pack()
frame.focus()

def handler(event):
print event.time / 1000.0

frame.bind("<Key>", handler)

mainloop()

the above only tracks key presses; if you need to track releases
as well, add an extra binding for KeyRelease.

also note that unlike Peter's example, the time attribute contains
the time when the event was generated, not when it reached your
program.

</F>

Jul 18 '05 #5
> Just when the window is active.
On windows use msvcrt module and on unix curses should do it.
They both have a getch() function.
http://effbot.org/zone/librarybook/p...ic-modules.pdf
HTH,
M.E.Farmer
Jul 18 '05 #6
Fredrik Lundh wrote:
in Tkinter, you'll find the event time (in milliseconds) in the time
attribute of the event descriptor: .... also note that unlike Peter's example, the time attribute contains
the time when the event was generated, not when it reached your
program.


My example didn't show the time at all. If you want
the time of the event generation in wxPython, you would
use the evt.GetTimestamp() call, which returns the
time of the event generation in milliseconds.

-Peter
Jul 18 '05 #7
"Peter Hansen wrote:
also note that unlike Peter's example, the time attribute contains
the time when the event was generated, not when it reached your
program.


My example didn't show the time at all.


and you probably didn't write

"you would be able to use time.time() or time.clock() to record
the times of the keypresses"

either. must be a bug in my newsreader; sorry for that.

</F>

Jul 18 '05 #8
Fredrik Lundh wrote:
"Peter Hansen wrote:
also note that unlike Peter's example, the time attribute contains
the time when the event was generated, not when it reached your
program.


My example didn't show the time at all.


and you probably didn't write

"you would be able to use time.time() or time.clock() to record
the times of the keypresses"

either. must be a bug in my newsreader; sorry for that.


Of course I wrote that, obviously. What I didn't do
was include that code in my example... you know, the
code. At least, I don't see that in any of my code,
but perhaps it's a bug in _my_ newsreader.

The reference to using the time module actually comes from
the OP, and I was merely agreeing that it could be possible to
use that module for the purpose intended (presumably what
is best depends on requirements we don't yet know about).

I point that out merely because one might infer from your
reply that Tkinter was capable of something that wxPython
was not in this case, which wouldn't be true.

-Peter
Jul 18 '05 #9
This is exactly what I was looking for. Thanks very much for the assist.

"Fredrik Lundh" <fr*****@pythonware.com> wrote in message
news:ma**************************************@pyth on.org...
| Peter Hansen wrote:
|
| > > | > I need to record the respective times of the events in a sequence of
| > > | > presses/releases of a particular key on the computer keyboard.
|
| > And Tkinter could certainly do it to, but I don't do Tkinter. :)
|
| in Tkinter, you'll find the event time (in milliseconds) in the time
| attribute of the event descriptor:
|
| from Tkinter import *
|
| frame = Frame(width=100, height=100)
| frame.pack()
| frame.focus()
|
| def handler(event):
| print event.time / 1000.0
|
| frame.bind("<Key>", handler)
|
| mainloop()
|
| the above only tracks key presses; if you need to track releases
| as well, add an extra binding for KeyRelease.
|
| also note that unlike Peter's example, the time attribute contains
| the time when the event was generated, not when it reached your
| program.
|
| </F>
|
|
|
Jul 18 '05 #10
On Sun, 2004-09-12 at 15:44 +0200, Fredrik Lundh wrote:
Peter Hansen wrote:
| > I need to record the respective times of the events in a sequence of
| > presses/releases of a particular key on the computer keyboard.
And Tkinter could certainly do it to, but I don't do Tkinter. :)


in Tkinter, you'll find the event time (in milliseconds) in the time
attribute of the event descriptor:

also note that unlike Peter's example, the time attribute contains
the time when the event was generated, not when it reached your
program.

Here's a more complete example in wxPython. Like the effbot's example,
this uses the time the event was generated. I didn't really feel like
examining all the possible places a wav file might exist on all
platforms, but here's a start:
import wx

SOUND = {
'__WXMSW__': 'c:/winnt/media/ding.wav',
'__WXGTK__': '/usr/share/sounds/generic.wav',
}[wx.Platform]

class Panel(wx.Panel):
def __init__(self, parent, id):
wx.Panel.__init__(self, parent, id)
self.ts = None
self.sound = wx.Sound(SOUND)
if not self.sound.IsOk():
self.sound = None
print "Your sound file is bad."
self.Bind(wx.EVT_KEY_DOWN, self.OnKeyDown)

def OnKeyDown(self, evt):
if evt.GetKeyCode() == wx.WXK_DELETE:
t = evt.GetTimestamp() / 1000.0
if self.ts is not None:
print "time between", t - self.ts
self.ts = t
if self.sound:
self.sound.Play(wx.SOUND_ASYNC)

class Frame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1, 'test')
p = Panel(self, -1)

if __name__ == '__main__':
app = wx.PySimpleApp()
frame = Frame()
frame.Show()
app.MainLoop()
Regards,
Cliff

--
Cliff Wells <cl************@comcast.net>

Jul 18 '05 #11
On Sun, Sep 12, 2004 at 03:44:03PM +0200, Fredrik Lundh wrote:
also note that unlike Peter's example, the time attribute contains
the time when the event was generated, not when it reached your
program.


Beware! In at least some old versions of Tk, the Windows version used a
function TkpGetMS to find the timestamp for an event, and TkpGetMS calls
GetTickCount(), which as far as I can tell from the documentation is the
wall time now, not when the event was generated.

In fact, this code still seems to be in the HEAD revision of tkWinX.c.
Well, it's my own fault for only fixing the bug locally, not filing any
kind of bug report with the tcl/tk people.

Jeff

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)

iD8DBQFBRZUSJd01MZaTXX0RAtQnAJ43jHMPRgF5J1Wf2t/xMv7sdo4HFgCdH7lF
bxf+ZOX/W4LczGoCQLbD3Jk=
=qRUz
-----END PGP SIGNATURE-----

Jul 18 '05 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: lawrence | last post by:
I had some code that worked fine for several weeks, and then yesterday it stopped working. I'm not sure what I did. Nor can I make out why it isn't working. I'm running a query that should return 3...
1
by: swestenra | last post by:
I am trying to build a screen scraper. But not just a plain screen scraper, it must also automate the entry of data. Background: We have a new intranet system that goes in to production soon. ...
3
by: Lynn McGuire | last post by:
I am creating a function prototype for a DLL entry point. I dynamically load the DLL at runtime and then map the entry points. typedef SP_STATUS SP_API (* myRNBOsproReadProc) ( SP_IN...
20
by: hippomedon | last post by:
Hello everyone, I'm looking for some advice on whether I should break the normalization rule. Normally, I would not consider it, but this seems to be a special case. I have created an...
11
by: RobertJohn | last post by:
Hi all I am using Access 2007 to start a small home library application, and so far it has two tables. 1. Books, with fields Book_ID (Primary Key) and Title, and 2. Authors, with fields...
1
by: admin.offshoredataentry | last post by:
Data Entry Outsourcing provides time bound, cost effective and qualitative Data Entry also provides numeric data entry, textual data entry, image data entry, data format, data conversion and also...
1
by: Data Entry Outsourcing | last post by:
Data Entry plays vital role in every business area. Data Entry is one such aspects of any business that needs to be handled properly for expanding your business. Data Entry is one of the leading...
0
by: dataentryoffshore | last post by:
Get a Discount up to 60% on data entry, data capture, dataentry services, large volume data processing and data conversion services through offshore facilities in India. Offshore data entry also...
2
by: ketty_ng81 | last post by:
No matter how many dial up networking entries I have, the RASWrapper.RasEnumEntries(null , null , entryNames, ref cb, out entries); always returns the right number of elelments in entryNames but...
53
by: Aaron Gray | last post by:
I jokingly say this is the late entry :) Okay I have read all the event entry comments from John's Resig's AddEvent comepition blog :- http://ejohn.org/projects/flexible-javascript-events/ ...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.