enigo-rs / enigo

Cross platform input simulation in Rust
MIT License
1.07k stars 107 forks source link

macOS: CapsLock not working #163

Closed pentamassiv closed 1 week ago

pentamassiv commented 1 year ago

Describe the bug CapsLock seems to have no effect

To Reproduce

use enigo::{Enigo, Key, KeyboardControllable};
use std::thread;
use std::time::Duration;

fn main() {
    thread::sleep(Duration::from_secs(2));
    let mut enigo = Enigo::new();

    enigo.key_click(Key::Layout('a'));
    enigo.key_click(Key::CapsLock);
    enigo.key_click(Key::Layout('a'));
}

Expected behavior The letters aA should be typed.

Environment (please complete the following information):

Additional context This seems to be a know issue. I only found out about it because I read: https://eastmanreference.com/complete-list-of-applescript-key-codes

pentamassiv commented 1 year ago

Instead of CapsLock, the shift can get activated. We need to store the shift state so we can toggle it