I am writing a command line application in Swift that will run on Linux. I want to know what keys the user is touching in real time so I can show a value associated with each key.
Is there aa non blocking way of capturing user keystroke events in real time one key at a time?
I know of the readLine() function but that captures whole words and is blocking.
Anybody knows of a working solution?
If you know which input device (for example a USB keyboard) you want to read the real time keystrokes from, then you could use something like: https://github.com/Dev1an/InputEvents
It does not use standard command line input streams but reads the events directly from /dev/input/...
devices instead.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.