[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

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>


Reply to: