Keyboard input in rust

Some time ago I started to program something in python. It wasn't to difficult, but I needed a accurate timer. So I tried to switch to rust, because it is maybe faster because of the low level of the language. But for this idea to work, I need to simulate the pressing of my keyboard. Unfortunately I didn't found anything till now, so maybe someone here can help me.

I realy just need to fake user inputs about the keyboard.

Thanks in advance :hugs:

I would look for crates related to pseudo-terminals, or "pty":

I think Rust is a great language, but just because you need an accurate timer doesn't mean you need a faster/more low-level language. Python's timers should be as accurate as Rust's (this is coming from the OS/hardware).


Of course, but that is not the only reason. I just want more power over how things work. And it is also a great challenge

Thanks, I will check it out :slightly_smiling_face:

Unfortunately, as “simple sounding” as this is, the truth is that it depends on a lot of details.

  • are you a command-line app, or a GUI app?
  • are you on a POSIX platform, like Linux or macOS, or are you on Windows?
  • do you need to be able to do advanced interactions, like a key being held down, or is it sufficient to be able to do regular typing?

The PTY libraries will only work well if you’re doing command line apps on POSIX platforms, and the PTY really only works with regular typing (detailed stuff like holding down a key just isn’t possible, because POSIX terminals send events for characters entered, not events for buttons pressed.

If you want GUI support, or you want to bypass the PTY layer and get at low-level keyboard events, you’re going to need something OS-specific, and we’re going to need to know what OS you want to support.


This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.