Sponsored Content
Full Discussion: How to subdue the keyboard?
Top Forums Shell Programming and Scripting How to subdue the keyboard? Post 302946352 by wisecracker on Monday 8th of June 2015 02:12:19 PM
Old 06-08-2015
How to subdue the keyboard?

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:-
Code:
#!/bin/bash
# exec 3<&0
while true
do
	KEY="?"
	stty -echo -icanon min 0 time 0
	KEY=$(dd bs=1 count=1 2> /dev/null)
	# Change -u[x] to the correct file descriptor.
	# read -s -n1 -u0 KEY
	KEY="${KEY:0:1}"
	if [ "$KEY" = "s" ]
	then
		sleep 0.5
		# wait
		printf "$KEY "
	fi
	if [ "$KEY" = "q" ]
	then
		break
	fi
done
stty sane
# exec 0<&3 3<&-
echo ""

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:-
Code:
Last login: Mon Jun  8 18:44:11 on ttys000
AMIGA:barrywalker~> cd ~/Desktop/Code/Shell
AMIGA:barrywalker~/Desktop/Code/Shell> ./kb
s s s s s s s s s s s s s 
AMIGA:barrywalker~/Desktop/Code/Shell> _

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.

I hope this is lucid enough.

TIA.

Bazza...
 

7 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

How can I map Unix keyboard for PC keyboard

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)
Discussion started by: simhab
1 Replies

2. SCO

Kill from keyboard

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)
Discussion started by: jwideman
3 Replies

3. Linux

mdk 10.2 and keyboard

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)
Discussion started by: penguin-friend
3 Replies

4. UNIX for Dummies Questions & Answers

Keyboard keeps locking up

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)
Discussion started by: sstaszak11
1 Replies

5. Solaris

Keyboard problem

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)
Discussion started by: microbot
11 Replies

6. What is on Your Mind?

Keyboard vs mouse

Which Input device do you use the most ? for me... keyboard ofcourse !! (56 Replies)
Discussion started by: vpraveen84
56 Replies

7. UNIX for Dummies Questions & Answers

Problem getting vertical bar with British keyboard layout on US (physical) keyboard

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)
Discussion started by: crunchgargoyle
7 Replies
ureadkey(3alleg4)						  Allegro manual						 ureadkey(3alleg4)

NAME
ureadkey - Returns the next unicode character from the keyboard buffer. Allegro game programming library. SYNOPSIS
#include <allegro.h> int ureadkey(int *scancode); DESCRIPTION
Returns the next character from the keyboard buffer, in Unicode format. If the buffer is empty, it waits until a key is pressed. You can see if there are queued keypresses with keypressed(). The return value contains the Unicode value of the key, and if not NULL, the pointer argument will be set to the scancode. Unlike readkey(), this function is able to return character values greater than 255. Example: int val, scancode; ... val = ureadkey(&scancode); if (val == 0x00F1) allegro_message("You pressed n with tilde "); if (val == 0x00DF) allegro_message("You pressed sharp s "); You should be able to find Unicode character maps at http://www.unicode.org/. Remember that on DOS you must specify a custom keyboard map (like those found in `keyboard.dat') usually with the help of a configuration file specifying the language mapping (keyboard variable in system section of `allegro.cfg'), or you will get the default US keyboard mapping. SEE ALSO
install_keyboard(3alleg4), readkey(3alleg4), keypressed(3alleg4), clear_keybuf(3alleg4), simulate_ukeypress(3alleg4), exkeys(3alleg4) Allegro version 4.4.2 ureadkey(3alleg4)
All times are GMT -4. The time now is 02:15 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy