[partially solved] I need a python script to hold a key down
[partially solved] I need a python script to hold a key down
Hi,
So I am trying to game in MX Linux, so far so good, BUT, there is no AutoHotKey in Linux, and I used to use it to hold down the move key in games to save wear and tear on my fingers.
The AutoHotKey script I had pushed and held the move key down when I pressed the activating key, and when I pressed the activating key a second time, it released the move key.
I downloaded AutoKey, which uses python, and is made to trigger python scripts with a key stroke, but I am too new at python to figure out what the script should be.
Any help would be appreciated.
So I am trying to game in MX Linux, so far so good, BUT, there is no AutoHotKey in Linux, and I used to use it to hold down the move key in games to save wear and tear on my fingers.
The AutoHotKey script I had pushed and held the move key down when I pressed the activating key, and when I pressed the activating key a second time, it released the move key.
I downloaded AutoKey, which uses python, and is made to trigger python scripts with a key stroke, but I am too new at python to figure out what the script should be.
Any help would be appreciated.
Last edited by Eric on Thu Jan 31, 2019 11:15 pm, edited 1 time in total.
Re: I need a python script to hold a key down
Can you link to AutoKey you downloaded or post here the relevant part of the script? You can post it in between [code] [/code] tags
Re: I need a python script to hold a key down
I don't use linux for gaming but I am in the same boat using autohotkey to hold down the "w" key. I look forward to the answers given as I hope someday to be able to switch completely to linux.
Re: I need a python script to hold a key down
Autokey was a program I installed via Synaptic Package Manager.Adrian wrote: ↑Wed Jan 30, 2019 10:30 am Can you link to AutoKey you downloaded or post here the relevant part of the script? You can post it in betweentagsCode: Select all
It was listed on some websites as a Linux alternative to AutoHotKey.
It uses Python instead of AutoHotKeys own scripting language.
I don't know Python at all, so there is no script to post.
Autokey's interface is pretty straight forward, there is a place to indicate what key will trigger the script, and a place to type in the script.
I need to know what syntax to type in, to get the "push and hold, toggle" behavior that I got in Autohotkey.
Re: I need a python script to hold a key down
Yes, this is a good start.Old Giza wrote: ↑Wed Jan 30, 2019 1:37 pm Does any of this help?
Stack Overflow
AutoPy, specifically: keyboard control
I am still struggling with exact syntax though.
Re: I need a python script to hold a key down
Ok
I installed AutoPy with apt-get
BUT
The program AutoKey will not recognize the module.
When i use the command
import autopy
I get the following error message:
Script name: 'New Script'
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/autokey/service.py", line 454, in execute
exec script.code in scope
File "<string>", line 2, in <module>
ImportError: No module named autopy
I tried looking in the service.py file.
Its hundreds and hundreds of lines of code, no way am I messing with it, unless I know exactly what i am doing.
Any ideas?
I installed AutoPy with apt-get
BUT
The program AutoKey will not recognize the module.
When i use the command
import autopy
I get the following error message:
Script name: 'New Script'
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/autokey/service.py", line 454, in execute
exec script.code in scope
File "<string>", line 2, in <module>
ImportError: No module named autopy
I tried looking in the service.py file.
Its hundreds and hundreds of lines of code, no way am I messing with it, unless I know exactly what i am doing.
Any ideas?
Re: I need a python script to hold a key down
Ok, I have a partial work around, it involves one key to start running, another to stop.
I am writing all this, because at least one other person is interested in autorun in none autorun games.
First, I had a huge trouble getting Autopy to work.
Turns out it was because I installed it with apt-get
To work, it must be installed with pip, which you must first install with apt-get
Then after MUCH messing around, I gave up on Autopy, as the command autopy.key.toggle had syntax I could just not get to work.
So, I tried using pyautogui, also installed via pip
This had very straight forward syntax
and
But, getting the toggling logic to work right was tricky, and I had to use a text file to hold one word, either False or True, which the script alternated writing one of those words to the file.
Finally got the toggling to work, but ran into a hardware problem.
When the keyDown was active, AutoKey would not register the keystroke to activate the script a second time, having one key down precluded it "seeing" the activating keystroke.
Perhaps your keyboard is different, so here is the code in case it will work for you
Before using this code, make a text file in your home dir, called autorun.txt and put the word False in it.
Anyway, would not work for me, as the keystroke to trigger the script would not register when the keyDown was active.
So, I made a cheap workaround. One key to activate autorun (doing a keyDown call), then just hitting the movement key by hand, which seemed to cancel the keyDown.
If you have the activation key right next to the movement key, its not that bad.
I have keypad1 to activate, and keypad2 as the movement key.
Here is a picture of what it looks like in AutoKey
I hit keypad1 to start running, keypad2 to stop.
Not so bad.
I am writing all this, because at least one other person is interested in autorun in none autorun games.
First, I had a huge trouble getting Autopy to work.
Turns out it was because I installed it with apt-get
To work, it must be installed with pip, which you must first install with apt-get
Then after MUCH messing around, I gave up on Autopy, as the command autopy.key.toggle had syntax I could just not get to work.
So, I tried using pyautogui, also installed via pip
Code: Select all
pip install pyautogui
Code: Select all
pyautogui.keyDown('num2')
Code: Select all
pyautogui.keyUp('num2')
Finally got the toggling to work, but ran into a hardware problem.
When the keyDown was active, AutoKey would not register the keystroke to activate the script a second time, having one key down precluded it "seeing" the activating keystroke.
Perhaps your keyboard is different, so here is the code in case it will work for you
Code: Select all
import pyautogui
ar = open("autorun.txt", "r+")
down = ar.read().strip()
ar.close()
ar = open("autorun.txt","w")
if (down == "True"):
ar.write("False")
pyautogui.keyDown('insert')
else:
ar.write("True")
pyautogui.keyUp('insert')
ar.close()
Anyway, would not work for me, as the keystroke to trigger the script would not register when the keyDown was active.
So, I made a cheap workaround. One key to activate autorun (doing a keyDown call), then just hitting the movement key by hand, which seemed to cancel the keyDown.
If you have the activation key right next to the movement key, its not that bad.
I have keypad1 to activate, and keypad2 as the movement key.
Code: Select all
import pyautogui
pyautogui.keyUp('num2')
pyautogui.keyDown('num2')
I hit keypad1 to start running, keypad2 to stop.
Not so bad.
You do not have the required permissions to view the files attached to this post.
Re: [partially solved] I need a python script to hold a key down
I also was thinking of a bit of gaming in linux. Have a heap of steam games all FPS don't even know if steam games for windows will work with linux steam. Doe's linux steam have like wine build in or something. So you have to keep pressing the (w) key up and down to more forward. a s d same.
I have installed some linux drivers in the past for my Razer keyboards and mice. I don't know they would with gaming. If you own Logitech stuff...
Back to the real topic: Not sure if any this will help ?
https://nitratine.net/blog/post/how-to- ... in-python/ = How to Make Hotkeys in Python
https://appdb.winehq.org/objectManager. ... &iId=17738 = Linux port of AutoHotkey via wine. Uses AutoHotkey.dll, xdotool .
I have installed some linux drivers in the past for my Razer keyboards and mice. I don't know they would with gaming. If you own Logitech stuff...
Back to the real topic: Not sure if any this will help ?
https://nitratine.net/blog/post/how-to- ... in-python/ = How to Make Hotkeys in Python
https://appdb.winehq.org/objectManager. ... &iId=17738 = Linux port of AutoHotkey via wine. Uses AutoHotkey.dll, xdotool .
Main : MX 19.1-AHS (i3) 5.4.13-1~mx19+1, Asus B450-i AMD 5 3600 , 32gb Hyper-X 3200 , GTX970 .
Lenovo T430 : Debian10 antiX17 (i3) , 4.20.12 , i5 , 12gb .
Lenovo X220 : Test Machine (ATM)
Lenovo T430 : Debian10 antiX17 (i3) , 4.20.12 , i5 , 12gb .
Lenovo X220 : Test Machine (ATM)
Re: [partially solved] I need a python script to hold a key down
https://faq.i3wm.org/question/6901/mous ... ard.1.html
xbindkeys ...
'xdotool keydown --clearmodifiers w '
Alt + w
'xdotool keyup --clearmodifiers w '
Alt + w + Release
or
$ xdotool keydown w;sleep 3;xdotool keyup w
https://askubuntu.com/questions/122161/ ... d-xkeybind
i have not tested the xbindkey methods. Or maybe buy a cheap chinese joystick?
xbindkeys ...
'xdotool keydown --clearmodifiers w '
Alt + w
'xdotool keyup --clearmodifiers w '
Alt + w + Release
or
$ xdotool keydown w;sleep 3;xdotool keyup w
https://askubuntu.com/questions/122161/ ... d-xkeybind
i have not tested the xbindkey methods. Or maybe buy a cheap chinese joystick?