Is it possible to make it appear to a system that a key was pressed, for example I need to make A key be pressed thousands of times, and it is much to time consuming to do it manually, I would like to write something to do it for me, and the only thing I know well enough is Python.
A better way to put it, I need to emulate a key press, I.E. not capture a key press.
More Info (as requested): I am running windows XP and need to send the keys to another application.
Install the pywin32 extensions. Then you can do the following:
Search for documentation of the WScript.Shell object (I believe installed by default in all Windows XP installations). You can start here, perhaps.
EDIT: Sending F11
Check This module keyboard with many features.Install it, perhaps with this command:
Then Use this Code:
If you Want to write 'A' multiple times, Then simply use a loop.
Note:
The key 'A' will be pressed for the whole windows.Means the script is running and you went to browser, the script will start writing there.
If you're platform is Windows, I wouldn't actually recommend Python. Instead, look into Autohotkey. Trust me, I love Python, but in this circumstance a macro program is the ideal tool for the job. Autohotkey's scripting is only decent (in my opinion), but the ease of simulating input will save you countless hours. Autohotkey scripts can be "compiled" as well so you don't need the interpreter to run the script.
Also, if this is for something on the Web, I recommend iMacros. It's a firefox plugin and therefore has a much better integration with websites. For example, you can say "write 1000 'a's in this form" instead of "simulate a mouseclick at (319,400) and then press 'a' 1000 times".
For Linux, I unfortunately have not been able to find a good way to easily create keyboard/mouse macros.
You could also use PyAutoGui to send a virtual key presses.
Here's the documentation: https://pyautogui.readthedocs.org/en/latest/
You can also send keys like the shift key or enter key with:
Pyautogui can also send straight text like so:
As for pressing the "A" key 1000 times, it would look something like this:
alt-tab or other tasks that require more than one key to be pressed at the same time:
AutoHotKey is perfect for this kind of tasks (keyboard automation / remapping)
Script to send "A" 100 times:
That's all
EDIT: to send the keys to an specific application:
It's probably possible - but where do you want the key presses to go? To another application? That would probably be a case of understanding your platform's windowing toolkit and sending the right messages to the right window.
Clarify your requirements, and I'm sure we can help out.