This has got me stumped and no solution on the WWW or here either that I can see.
I suspect this can't be done... ;o(
My requirement is to hold a _random_ key down and run a single command.
Easy EXCEPT the keyboard keeps adding that same keystroke into a type ahead buffer somewhere and does NOT wait until the command has finished.
In this real example sleep is the command but almost any command does the same.
You will notice I have tried various ideas but all give the same results...
Take this real example, hold the s key down for 1 to 2 seconds and watch the results:-
Is it possible to just get one, and one only, ketstroke with the key depressed until the next loop just like INKEY$ in BASIC where each statement is executed sequentially?
View these incorrect results:-
You will notice that sleep does its job of delaying the printout but it is printing a string of "s's" instead of one just "s" then waiting before accessing the next single character.
You could compare if the current key pressed is equal to the last key pressed, respectivly if it already has been printed.
Dunno what that stty is about, and that usage of dd as streamreader is also still new to me, but nicely made!
I have already written the morse practice oscillator but one has to tap keys "o" and "p" for the dits and dahs... Works perfectly in this mode at about 10WPM but I want to try and emulate the above using these two keys...
Boy is this difficult. I solved it ages ago in Python but I have no udea how to solve it in bash...
Hence asking for help...
Last edited by wisecracker; 06-08-2015 at 04:58 PM..
Reason: Pointed to the wrong paragraph in the URL.
I have already written the morse practice oscillator but one has to tap keys "o" and "p" for the dits and dahs...
Sounds awesome!
Anyway, since you are expecting 'chars', you could just run a case or if block catching the expected ones, and ignore (and/or trap if required/convenient) the other chars.
How about this?
It would 'act' on keypress, but delay the output.
hth
---------- Post updated at 22:19 ---------- Previous update was at 22:15 ----------
Doh, now i get it....
You'd need to catch an actual keypress, or... pipe that output to a function which then returns something when the stream ends. EDIT: Like a counter value of the time when it started/ended, and then decide according to that value, wether to dit or dah.
hth
---------- Post updated at 22:24 ---------- Previous update was at 22:19 ----------
Like, writing a tempfile:0, first start if 0 add 2 and reset the $TIME_PRESSED, after which you keep adding 1 to tempfile:$tempfile.
And when the stream stops, you set it back to 0, at which time you decide for dit/dah.
If I understand what you're trying to do, what you want is to get the time elapsed between when a key was pressed and when that key was released so you can determine whether the operator held the key for a short time (dot) or a long time (dash). That is something that the keyboard driver would know, but I don't know of any portable interface that will make that information available to a shell script. The keyboard driver probably also ignores very short duration presses and releases (key bounce) which may be a problem if you can get raw access to keyboard events somehow in a C program or shell script.
With my current keyboard driver settings (which on OS X are settable in the keyboard section of the system preferences app; but not by the stty utility) for key press repeat and time between repeated characters, I can easily manually press and release a about 7 characters/second. And, if I hold a key down for a while, it will generate about 14 characters/second. Trying to detect whether I tried to input two dashes or two (or three) dots or a dot and a dash (in either order) using a .5 second timer isn't likely to work.
If you are using an X application and can turn off key repeat using shell commands (as Chubbier_XL suggested), you still won't know whether a key press was intended to be a dot or a dash.
This User Gave Thanks to Don Cragun For This Post:
Already tried your temp file idea. It was messy and didn't work.
The keystrokes are put into a type ahead buffer as single characters but look like a string in screen.
@ Chubler_XL...
Yup, I think you have nailed the problem and no it is not an X session...
@ Don...
You are on the right lines except because the first keyhold is extended by default then holding for one dah is not a problem, similarly for dits.
However a real "bug key" can be just held in either a dit or a dah indefinitely and as many of these are produced for the duration of that hold only. read -s -n1 KEY does not stop the key strokes into the type ahead buffer after one character but keeps on reading whatever is in there each loop.
Even intialising every loop with KEY="?" does not prevent it...
BTW sleep 0.5 is just there as an example the real command is sox and the problem still exists...
I think you have given me my answer and it looks as though my thoughts were correct.
It can't be done in ordinary shell scripting.
I already have a good working model using single keystrokes and will upload when tidied up a bit.
Got to add random charcters, A -Z, 0 - 9, to generate the morse tones to listen to and practice aagainst.
---------- Post updated at 03:52 PM ---------- Previous update was at 07:53 AM ----------
Hi Don...
I have been experimenting with the KB timers and it is a fudge but might just do what I want.
Not really the way to go but an alternative nevertheless...
The morse practice oscillator will be on here in the not too distant future...
Hi, I've got a bit of a ridiculous problem and wasn't sure where to post it.
I need to use the vertical bar for piping in Bash but, as per the title, am using a UK layout on a US (physical) keyboard which doesn't have a key for it in the place I'd expect. I've tried using xbindkeys and Unicode... (7 Replies)
Hi to everyone I am new at Solaris world so I need little help.
I can not put my keyboard to Croatian layout.
I tried to edit /etc/default/init and in that file I changed LC_ALL=hr_HR. Also I tried to change my language settings over GUI (input methods and SCIIM) but with no results.
Also tried... (11 Replies)
First off, let me start by saying that I am a total rookie when it comes to Unix so I will do my best to explain the situation.
BACKGROUND:We are running AIX and using a third party Inventory Management software called Acclaim. My main interface terminal is just a "dummy" terminal hooked up to... (1 Reply)
Hi all,
I'm running a mdk 10.2 cooker on my computer.
After and update, i've lost the "alt gr" key.
How am i supposed to get it back?
I've already googled around a bit, testing solutions provided, but nothing can help..
any other suggestions?
Thanx all
Jason (3 Replies)
I have a cron job that creates my backup tape. However my commands in this job are timing out, therefore "Retrying job retry" is the loop it is hung into. I cannot telnet to the box nor get a login prompt. What is the kill command keystone stroke sequence that will break a cron job?
Thanks, (3 Replies)
A Solaris AXI 440 machine with Solaris 8 version.
I have PC users who use an emulation to login to the Solaris
server.
How can I change the keyboard mapping of the Sun keyboard
to fit to the PC keyboard ?
Any comment will be appreciated.
Thanks (1 Reply)