beep icon indicating copy to clipboard operation
beep copied to clipboard

Option for typewriter effect when typing within terminal?

Open rogerxx opened this issue 4 years ago • 4 comments

I've seen quite a few extravagant typewriting sound emulators using ALSA/Pulse for output, but seemingly bloated in my opinion with high resource usage, rather than using simple PC speaker beep. (eg. bucklespring program, but useless for vision impaired as the sounds are emitted upon press and release, more of a cosmetic feature rather than useful feature.)

Is there any method of providing the beep command the option for emulating a typewriter while typing within terminals?

If I'm not mistaken, the process is relatively simple, detect a keyscan press, play beep. I'm pretty sure the code is almost there using "beep -c -f 750 -D 20 -l 5", just needs to detect a keyscan press.

rogerxx avatar Aug 19 '21 01:08 rogerxx

Just realized, could pipe /dev/tty for input to beep, without having beep pull in additional libraries.

$ beep -c -f 750 -D 30 -l 30 < /dev/tty

However, beep is only activated on carriage return or '\n', end of line return, instead of after each key press.

rogerxx avatar Aug 19 '21 03:08 rogerxx

You could try this in Bash:

$ while read -n1 -r; do beep -f 750 -D 30 -l 30; done

or zsh:

% while read -k; do beep -f 750 -D 30 -l 30; done

Matt-Deacalion avatar Apr 09 '24 14:04 Matt-Deacalion

Just realized, could pipe /dev/tty for input to beep, without having beep pull in additional libraries.

$ beep -c -f 750 -D 30 -l 30 < /dev/tty

However, beep is only activated on carriage return or '\n', end of line return, instead of after each key press.

Perhaps beep would need to

if (isatty(STDIN_FILENO)) {
  ...put STDIN_FILENO from cooked mode to raw mode...
}

and then reverse that before the beep program terminates in any way.

ndim avatar Apr 11 '24 20:04 ndim

Probably a better way to implement key press noises would be in the keystroke processing software stack: Either inside the kernel or as a user space evdev input device driver for keyboard type devices.

A lot of care would need to be taken in that software, as that is also where you would implement a keylogger.

ndim avatar Apr 19 '24 10:04 ndim