I am building something like a splitkeyboard / joystick-controller for pc. The brain of the project is an arduino pro micro. I am using it in combination with firmata and python.
I decided to use python because i wanna have more than on setup / layout, for each programm it's own layout.
For example I would like to have a layout for blender, inkscape or for gaming, but one layout for each game.
I tried to do it with pyautogui, pynput it's working in general but not for games. It has something to do with directinput as far I can tell.
Do you have any advice how I can fix it so it also works in games?
By the way, I am using linux but I would like to have a cross platform solution.
Thanks for the Help!
Syntax: Select all
from pyfirmata import Arduino, util
from pynput.keyboard import Key, Controller
import time
try:
board = Arduino('/dev/ttyACM0')
print('connected')
except:
print('----------------faild to connect')
iterator = util.Iterator(board)
iterator.start()
keyboard = Controller()
x = board.get_pin('a:0:i')
y = board.get_pin('a:1:i')
s = board.get_pin('d:10:i')
#s.write(1)
time.sleep(1)
while True:
print('x =',x.read())
print('y =',y.read())
print('s =',s.read())
# time.sleep(.1)
if x.read() < 0.4:
keyboard.press('s')
keyboard.release('s')
if x.read() > 0.6:
keyboard.press('w')
keyboard.release('w')
if y.read() < 0.4:
keyboard.press('a')
keyboard.release('a')
if y.read() > 0.6:
keyboard.press('d')
keyboard.release('d')
time.sleep(0.1)