enigo-rs / enigo

Cross platform input simulation in Rust
MIT License
893 stars 95 forks source link

macOS: Allow entering media keys, changing the screen brightness and more #256

Closed pentamassiv closed 4 months ago

pentamassiv commented 4 months ago

The media keys and others are no ordinary keys on macos. For some reason they have to be handled differently. This code adds this functionality.

Fixes https://github.com/enigo-rs/enigo/issues/248 Allows getting rid of the workaround mentioned in https://github.com/thewh1teagle/mobslide/issues/1

pentamassiv commented 4 months ago

@paulora2405 , I went ahead and implemented the missing functionality. Do you think you could test if it works for you? I don't have the physical hardware. You can see the list of new keys if you look at the changes in the src/keycodes.rs file.

pentamassiv commented 4 months ago

@thewh1teagle, could you please test the fix and confirm that everything works as expected?

Edit: Nevermind, I just read that you also don't have a mac. I'll merge it then. If it's not working, I assume people are going to let me know

thewh1teagle commented 4 months ago

@pentamassiv I bought Mac :) I tested it but looks like it doesn't work. (I can see the log that it invoke vol up /down) Am I missing something? fix/macos-media-keys

pentamassiv commented 4 months ago

Ah, great! The code looks good. The Volume keys should behave like any other key on macOS now. Just to be sure, do other keys work? If not, maybe you did not grant the application the necessary permissions. I think when I tested it, play and pause worked with iTunes. You could run the key example and change it to other keys such as VolumeUp.

thewh1teagle commented 4 weeks ago

I tested again and both volume up / down works! desktop/src-tauri/src/cmd.rs#L9 Thanks!! if you need any testing on macOS let me know ;)