Untitled_47
Posts: 1
Joined: Tue Aug 14, 2018 5:40 pm

How would I create a script to simulate arrow key clicks

Tue Aug 14, 2018 5:50 pm

(I know I’m probably in the wrong section to ask this question) How would I create a script that could click the right key and left key alternating every 5 minutes?

User avatar
MrYsLab
Posts: 314
Joined: Mon Dec 15, 2014 7:14 pm
Location: Noo Joysey, USA

Re: How would I create a script to simulate arrow key clicks

Tue Aug 14, 2018 7:24 pm

Check out https://github.com/asweigart/pyautogui. This may provide the functionality you are looking for.

klricks
Posts: 6374
Joined: Sat Jan 12, 2013 3:01 am
Location: Grants Pass, OR, USA
Contact: Website

Re: How would I create a script to simulate arrow key clicks

Tue Aug 14, 2018 7:31 pm

Untitled_47 wrote:
Tue Aug 14, 2018 5:50 pm
(I know I’m probably in the wrong section to ask this question) How would I create a script that could click the right key and left key alternating every 5 minutes?
You can install the xdotool utility. With that you can simulate any keyboard or mouse move/click. Google for details.

Code: Select all

sudo apt update
sudo apt install xdotool
Easy to use in bash scripts. Not sure how hard to use in Python?
Unless specified otherwise my response is based on the latest and fully updated Raspbian Stretch w/ Desktop OS.

robbes
Posts: 144
Joined: Sun Jan 20, 2013 7:11 pm
Location: Canada - off the west coast

Re: How would I create a script to simulate arrow key clicks

Wed Aug 15, 2018 4:18 pm

Consider the keyboard package, available at PyPI. You have to be root to use it.
I think the command would just be
keyboard.press_and_release('right')
See https://pypi.org/project/keyboard/

Return to “Python”