Skip to main content
gamedev.net
🔒 Locked

help with bash

Started by 31337noob 2 replies 1k views
Original Post
31337noob
31337noob
hi, i am making a bash script in linux and i want to know is there a way if i can tell if a key has been hit. i dont want the terminal waiting for a keypress. i would do this in c++, but i dont think kbhit() works in linux because g++ gives the error: 'kbhit' was not declared in this scope. any help would be good. thanks in advanced.
31337noob
31337noob
well, i am making an alarm clock.

crontab takes care of the time.

when it is time, it runs a bashscript

and that bashscript

opens konsole

and runs mplayer with a song

it will repeat untill a key has been pressed

and i just want to know how to get that key press without the konsole waiting for a keypress.

Bregma
Bregma
Quote:
Original post by 31337noob
well, i am making an alarm clock.
crontab takes care of the time.
when it is time, it runs a bashscript
and that bashscript opens konsole and runs mplayer with a song


Why not just have your cron job run mplayer directly, and have the user close the mplayer window instead?

As for your original question, the answer is that you'll have to put the controlling tty in raw mode and do a read on file descriprot zero. You'll want to have an exit function hooked in to your script to reset the tty mode.

Something like this (untested)
cleanup(){  stty -raw}trap cleanup 0stty rawmplayer playfile &read somechar
Stephen M. Webb
Professional Free Software Developer

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.