FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Debian > Debian User

 
 
LinkBack Thread Tools
 
Old 01-21-2008, 11:43 AM
Joseph
 
Default OT: How to detect a keypress, and in which language?

As others suggested, check python. It's not to difficult and most of it is cross platform.
There are*several ways to get chars, both blocking and non-blocking.
*
I was thinking about curses, but there are other ways.
*
From python docs:


While curses is most widely used in the Unix environment, versions are available for DOS, OS/2, and possibly other systems as well. This extension module is designed to match the API of ncurses, an open-source curses library hosted on Linux and the BSD variants of
Unix.
*
The first thing that comes to my mind is doing something based on threads, assuming that beeping is a blocking function (doesn't return until the beep ends).
*
start a thread that accepts beep requests (and performs the beeping)
last_beep_end_time = now()
*
while akey is pressed:*
**
** speaker_is_idle = now() > last_beep_end_time
*
** if akey is quit_key:
****** quit
*
** if akey is key1 and the speaker is idle:
***** ask the thread to beep
***** compute*last_beep_end_time (at which the beep ends, eg now + 100ms)
**
** ...
** silently ignore keypresses while the speaker is already beeping.
*
*
Cheers,
Joseph
 
Old 01-21-2008, 01:43 PM
"Dotan Cohen"
 
Default OT: How to detect a keypress, and in which language?

On 21/01/2008, Joseph <josephdrivein@gmail.com> wrote:
> silently ignore keypresses while the speaker is already beeping.

The married men on the list will no doubt recognize that tactic.

Dotan Cohen

http://what-is-what.com
http://gibberish.co.il
א-ב-ג-ד-ה-ו-ז-ח-ט-י-ך-כ-ל-ם-מ-ן-*-ס-ע-ף-פ-ץ-צ-ק-ר-ש-ת

A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
 
Old 07-07-2011, 05:58 AM
Kent West
 
Default OT: How to detect a keypress, and in which language?

In a very old thread from January of 2008
(http://www.linux-archive.org/debian-user/41227-ot-how-detect-keypress-language.html),
I asked the following question:

> Hey folks!
>
> Apologies for the very off-topic post; I've been googling for the answer
> off-and-on for two days unsuccessfully, so I've finally decided to turn
> to the smartest group of people around.
>
>
> I want to write a basic little Morse Code key program to put into the
> newsletter of the local amateur radio (ham) club. It'd be nice if it
> were cross-platform, and preferably easy-peazy on Linux and maybe just
> as easy on OS/X and just a little more trouble on Windows (so I can
> subtly suggest that Windows is sub-standard to nix-based OSes (okay, I'm
> never subtle about pushing Debian to my fellow hams)), and it'd be ideal
> if the code requires almost no overhead, so non-programmers can easily
> grasp how it works.
>
>
> All I want to do is to detect two keys, say the left- and right-shift
> keys, or the < and > keys. For one key, a short "dit" audio tone would
> be generated, and for the other key, a longer "dah" audio tone would be
> generated. I need to bypass the keyboard buffer, so that holding down
> the dit key for two seconds doesn't generate 30 dits; it should produce
> dits while the key is held down, but once the key is let up, the dits
> should immediately stop (after finishing the one it's on).
>
>
> The code would look something like this:
>
> While ( not ESC)
> read keystroke
> if keystroke = LeftArrow then generateTone(dit)
> else if keystroke = RightArrow then generateTone(dah)
> Done
>
> I'm sure the information is out there on Google, but not being a
> programmer, I'm finding snippets that don't have enough context for me
> to be able to actually test (for example, I found a Java snippet that
> looked promising, but I couldn't even get it to compile), or the
> snippets read from the read-ahead keyboard buffer which introduces
> delays and run-ons.
>
>
> So, any suggestions as to which language will be best suitable for my
> wants?
>
> Any suggestions as to how to detect the keypress in that language?
>
> Any suggestions as to how to generate a tone in that language (this one
> I figure will be fairly easy to Google for, but I haven't tried, seeing
> as the keypress has been the show-stopper so far).
>
>
> Thanks!
>
> --
> Kent

We pretty much decided it couldn't be easily done, but here's a very
dirty, unclean method that at least shows the concept (modified from
code found at
http://www.geekpedia.com/tutorial138_Get-key-press-event-using-JavaScript.html).
Just put the following text into a plain text file, and name it
something like "morse.html", and then use your web browser's File/Open
File menu to open that file; press the right arrow for dah, left for dit.

It's slow, klunky, badly written html, not usable, but suffices to show
the concept.


CODE BELOW
----

<html>
<head>
</head>
<body>
<script type="text/javascript">
document.onkeyup = KeyCheck;

function KeyCheck(e)
{
var KeyID = (window.event) ? event.keyCode : e.keyCode;

switch(KeyID)
{

case 37: <!-- Arrow Left -->
document.Form1.KeyName.value = "dit";
PlaySound("dit");
break;

case 39: <!-- Arrow Right -->
document.Form1.KeyName.value = "dah";
PlaySound("dah");
break;

}
}
</script>

<script>
function PlaySound(soundObj) {
var sound = document.getElementById(soundObj);
sound.Play();
}
</script>

<embed src="dit.wav" autostart="false" width="0" height="0" id="dit"
enablejavascript="true">

<embed src="dah.wav" autostart="false" width="0" height="0" id="dah"
enablejavascript="true">


<form name="Form1">

<input type="text" name="KeyName" value="" />

</form>
</body>
</html>


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
Archive: 4E154B1C.7060307@acu.edu">http://lists.debian.org/4E154B1C.7060307@acu.edu
 
Old 07-07-2011, 06:04 AM
Kent West
 
Default OT: How to detect a keypress, and in which language?

On 7/7/11 12:58 AM, Kent West wrote:
> In a very old thread from January of 2008
> (http://www.linux-archive.org/debian-user/41227-ot-how-detect-keypress-language.html),
> I asked the following question:
<snip>
> I want to write a basic little Morse Code key program ...

<snip>
> case 37: <!-- Arrow Left -->
> document.Form1.KeyName.value = "dit";
> PlaySound("dit");
> break;
>
> case 39: <!-- Arrow Right -->
> document.Form1.KeyName.value = "dah";
> PlaySound("dah");
> break;
>

Oh, forgot to mention, I got the dit.wav and dah.wav from
http://www.geekpedia.com/tutorial138_Get-key-press-event-using-JavaScript.html,
Beep 6 and Beep 7 (renamed and put in the same directory as the
morse.html file).

--
Kent


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
Archive: 4E154C74.8000009@acu.edu">http://lists.debian.org/4E154C74.8000009@acu.edu
 
Old 07-07-2011, 06:05 AM
Kent West
 
Default OT: How to detect a keypress, and in which language?

On 7/7/11 1:04 AM, Kent West wrote:
> Oh, forgot to mention, I got the dit.wav and dah.wav from
> http://www.geekpedia.com/tutorial138_Get-key-press-event-using-JavaScript.html,
> Beep 6 and Beep 7 (renamed and put in the same directory as the
> morse.html file).

D'oh! Pasted the wrong URL.

http://www.soundjay.com/beep-sounds-1.html

--
Kent


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
Archive: 4E154CC4.5030901@acu.edu">http://lists.debian.org/4E154CC4.5030901@acu.edu
 
Old 07-07-2011, 06:09 AM
Kent West
 
Default OT: How to detect a keypress, and in which language?

On 7/7/11 12:58 AM, Kent West wrote:
> We pretty much decided it couldn't be easily done, but here's a very
> dirty, unclean method that at least shows the concept (modified from
> code found at
> http://www.geekpedia.com/tutorial138_Get-key-press-event-using-JavaScript.html).

And http://stackoverflow.com/questions/879152/how-do-i-make-javascript-beep

--
Kent


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
Archive: 4E154DAE.4040100@acu.edu">http://lists.debian.org/4E154DAE.4040100@acu.edu
 
Old 07-08-2011, 06:07 AM
Cousin Stanley
 
Default OT: How to detect a keypress, and in which language?

Kent West wrote:

>> I want to write a basic little Morse Code key program
>> to put into the newsletter of the local amateur radio
>> (ham) club.
>>
>> It'd be nice if it were cross-platform
>> ....

A few debian possibles ....

$ apt-cache search morse code

Python-based programs are good candidates
for cross-platform possibles ....

google-ize ....

python morse code trainer

Even if you don't particularly like any
of the programs found, checking available
source code might provide some clues
and inspiration ....


--
Stanley C. Kitching
Human Being
Phoenix, Arizona


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
Archive: iv66r4$6bf$1@dont-email.me">http://lists.debian.org/iv66r4$6bf$1@dont-email.me
 

Thread Tools




All times are GMT. The time now is 01:22 PM.

VBulletin, Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org