Reputation: 108
I am trying to develop a rather simple program on rust, I want to be able to detect keydown presses from the keyboard, this will be used to control a drone using "WASD" just like a game.
The thing is, I have tried to check if there is any way to do it by using just the std library, but every answer I see is something like "use termion" or "use this".
Is there a way to do it just with the std library from rust? without using external crates.
Ty!
So far I have tried to develop a terminal-like program that sends commands, I want to improve it by reading the keys rather than having to send the commands to the drone one by one. Reading these commands directly from what I press would be rather useful. (Also, this is done using UDP, in case that matters)
Upvotes: 0
Views: 1071
Reputation: 23434
The way to do this depends on the target OS and terminal.
On Unix systems, this is done by switching stdin/stdout to raw mode and using ANSI control sequences (but note that there are several sets of control sequences and the right one to use depends on your terminal application, e.g. the Linux console uses different sequences from xterm and Gnome Terminal uses yet another set).
On Windows, this requires calling system functions from the Windows Console API.
The existing crates abstract all those differences into a single unified cross-platform API.
Upvotes: 3