Force user input in verbatim mode?

随声附和 提交于 2019-12-03 21:47:54

This should work

#!/bin/bash

while true;do
    stty_state=$(stty -g) 
    #Save stty to reset to default
    stty raw isig -echo 
    #Set to raw and isig so nothing is interpretted and turn echo off so nothing is printed to screen.
    keypress=$(dd count=1 2>/dev/null)
    #Capture one character at a time
    #Redirect "errors" (from dd) output to dump
    keycode=$(printf "%s" "$keypress" | xxd -p)
    # Convert to hex
    stty "$stty_state"
    #Revert stty back
    printf "%s" "$keycode"
    #Print your key in hex
done

You can put a condition on the loop to exit the loop/program, otherwise you will need to use CTRLC` to exit.

This should print every key press except for CTRLC and CTRLz.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!