Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to generate keyboard events in Python?
    primarykey
    data
    text
    <p><strong>short summary:</strong></p> <p>I am trying to create a program that will send keyboard events to the computer that for all purposes the simulated events should be treated as actual keystrokes on the keyboard.</p> <p><strong>original post:</strong></p> <p>I am looking for a way to generate keyboard events using python.</p> <p>Assume that the function receives a key that it must simulate pressing, like so:</p> <pre><code>keyboardevent('a') #lower case 'a' keyboardevent('B') #upper case 'B' keyboardevent('-&gt;') # right arrow key def keyboardevent(key): #code that simulated 'key' being pressed on keyboard </code></pre> <p>The above are obviously examples, but what I am looking for is a library, module, or whatever, which I can use to simulate keyboard events.</p> <p><em>note</em>: This is different than sending characters to notepads, or inputting text into fields or such. I want the python script to simulate an actual keyboard event, the computer will think that there is really a keyboard event.</p> <p>Extra Note:</p> <p>I don't want to send keystrokes to the active window - I want the system to believe the keyboard's keys are being pressed, subtle difference, as some active-windows do not accept certain key-combinations, or if I wanted to use keyboard shortcuts for background processes through my script, they don't need to go through the active-window</p> <p>So far I have looked at these things:</p> <p><a href="https://stackoverflow.com/questions/9318690/generate-keyboard-events-for-the-frontmost-application">Generate keyboard events for the frontmost application</a></p> <p><a href="https://stackoverflow.com/questions/6868167/how-to-generate-keyboard-keypress-events-through-python">How to generate keyboard keypress events through Python?</a></p> <p>Which were all about apple and didn't help at all.</p> <p>And this:</p> <p><a href="https://stackoverflow.com/questions/2791839/which-is-the-easiest-way-to-simulate-keyboard-and-mouse-on-python">Which is the easiest way to simulate keyboard and mouse on Python?</a> </p> <p>Which seems like it might be what I need, but I can not find the library for it or any documentation.</p> <p>I have searched more places as well, but have yet to find a solution.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload