crumblingstatue / rust-libxdo

Rust bindings to libxdo
https://docs.rs/libxdo
MIT License
9 stars 4 forks source link

How to send backspaces? #3

Closed Davejkane closed 3 years ago

Davejkane commented 6 years ago

I tried using enter_text("\b") but apparently that isn't a valid escape sequence. Any ideas? Oh, and thanks for making this by the way, it's going to be super useful for a project I have in mind.

crumblingstatue commented 6 years ago

If you want to simulate a press of the backspace key, you can use https://docs.rs/libxdo/0.6.0/libxdo/struct.XDo.html#method.send_keysequence with BackSpace as the sequence. If you have Xorg's xev utility installed, you can use it to find out the names of various keys to use in keysequences.

When you press a key, it will print out a string similar to this

KeyPress event, serial 48, synthetic NO, window 0x2400001, root 0x4ac, subw 0x0, time 20300572, (445,165), root:(447,186), state 0x0, keycode 22 (keysym 0xff08, BackSpace), same_screen YES, XLookupString gives 1 bytes: (08) " XmbLookupString gives 1 bytes: (08) " XFilterEvent returns: False

The part I marked bold is the name to look out for.

Davejkane commented 6 years ago

Great answer, and thanks for being so quick. In the meantime I did work out that enter_text("\x08") sends a back space too.