How i can do event "Click button on screen (in another application, like minecraft)"
I want make a python thing what clicking buttons on minecraft like:
'A', 'B', 'C', 'CTRL', 'SHIFT', '1', '2', '3', '\', 'ENTER' etc.
It will click only 1 time
To find people with hacks, i don't love people who cheating >:d\

- 23
- 4
-
Does this answer your question? [How to simulate a mouse click while holding the SHIFT key in Windows?](https://stackoverflow.com/questions/56469486/how-to-simulate-a-mouse-click-while-holding-the-shift-key-in-windows) – mcsoini May 29 '21 at 06:58
1 Answers
Keyboard module (python) to control keyboard
first we need install a module name- keyboard in python
pip3 install keyboard
First, let's import the module:
import keyboard
Next, you can also simulate key presses using the send() function:
it will press space:
keyboard.send("space")
This will press and release the space button. In fact, there is an equivalent function press_and_release() that does the same thing.
You can also pass multi-keys:
keyboard.send("windows+d")
The + operator means we press both buttons in the same time, you can also use multi-step hotkeys:
send ALT+F4 in the same time, and then send space,
keyboard.send("alt+F4, space")
But what if you want to press a specific key but you don't want to release it ? Well, press() and release() functions comes into play:
press CTRL button
keyboard.press("ctrl")
release the CTRL button
keyboard.release("ctrl")
So this will press CTRL button and then release it, you can do anything in between, such as sleeping for few seconds, etc.
But now what if you want to write a long text and not just specific buttons ? send() would be inefficient. Luckily for us, write() function does exactly that, it sends artificial keyboard events to the OS simulating the typing of a given text, let's try it out:
keyboard.write("Python Programming is always fun!", delay=0.1)
Setting delay to 0.1 indicates 0.1 seconds to wait between keypresses, this will look fancy like in hacking movies!
THANKS!

- 144
- 10