boppreh / keyboard

Hook and simulate global keyboard events on Windows and Linux.
MIT License
3.8k stars 433 forks source link

how to generate "space bar" command with python script #506

Open chicco64 opened 2 years ago

chicco64 commented 2 years ago

I would need with your software to emulate the "spacebar" key towards an already open window running google-chrome (debian11). This is to be able to activate an audio player that requires the physical keyboard command "spacebar" and that I would like to emulate through the bash command. can you kindly help me? Thank you very much

boppreh commented 2 years ago

This library is window-agnostic, so there's no option to emulate events "towards" other programs. One option would be to alt+tab or somehow change the current window, send the spacebar event, and come back. This is fairly invasive and will lead to screen flashing, however.

If you are pressing spacebar to play/pause a video in Chrome, you can try sending a 'play/pause media' event, which is equivalent to most keyboards' media key. Chrome is able to understand those commands and pause the current video. This would be preferred if it works for your use case.