Skip to content

python inputs #4256

Description

@Smehunia

I just wanted to make a remote control out of my gamepad, but for some reason it doesn't work correctly in some video players, and keyboard testing websites show that the 4862 keys are being pressed instead of the regular arrow keys. I also can't find documentation for all the keys in the input library.

from inputs import devices
from inputs import get_gamepad
import keyboard

left = 0
right = 0
up = 0
down = 0
x = 0

while 1:
    events = get_gamepad()
    for event in events:
        print(event.ev_type, event.code, event.state)

if event.ev_type == 'Absolute' and event.state == -1 and event.code == 'ABS_HAT0X' and left == 0:
    keyboard.press('left arrow')
    left = 1

if event.ev_type == 'Absolute' and event.state == 0 and event.code == 'ABS_HAT0X' and left == 1:
    keyboard.release('left arrow')
    left = 0

# right
if event.ev_type == 'Absolute' and event.state == 1 and event.code == 'ABS_HAT0X' and right == 0:
    keyboard.press('right')
    right = 1

if event.ev_type == 'Absolute' and event.state == 0 and event.code == 'ABS_HAT0X' and right == 1:
    keyboard.release('right')
    right = 0

# up
if event.ev_type == 'Absolute' and event.state == -1 and event.code == 'ABS_HAT0Y' and up == 0:
    keyboard.press('up')
    up = 1

if event.ev_type == 'Absolute' and event.state == 0 and event.code == 'ABS_HAT0Y' and up == 1:
    keyboard.release('up')
    up = 0

# down
if event.ev_type == 'Absolute' and event.state == 1 and event.code == 'ABS_HAT0Y' and down == 0:
    keyboard.press('down')
    down = 1

if event.ev_type == 'Absolute' and event.state == 0 and event.code == 'ABS_HAT0Y' and down == 1:
    keyboard.release('down')
    down = 0

# x
if event.ev_type == 'Key' and event.state == 1 and event.code == 'BTN_SOUTH':
    keyboard.press('space')
if event.ev_type == 'Key' and event.state == 0 and event.code == 'BTN_SOUTH':
    keyboard.release('space')

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions