2

So this is going to be a bit confusing but using a basic loop i can detect keyboard and mouse inputs using the following:

globals()['keyboardEvent'] = evdev.InputDevice('/dev/input/event0') 
globals()['mouseEvent'] = evdev.InputDevice('/dev/input/event1') 
async def print_events(device):
    global x, y #must be inside of loop or else nonlocal error is thrown
    left_click = 0
    right_click = 0
    currentClick = " "
    x = 0 #defines the start of x
    y = 0 #defines the start of y
    z = 5 #defines up and down axis
    async for event in device.async_read_loop():
        if (event.code == 8): #scrollbar
            print("you are scrolling")
            z += event.value
        if event.type == ecodes.EV_REL: #if the event is a mouse moving
            if event.code == ecodes.REL_X: #chechking for x direction
                print("REL_X", event.value)
                x += event.value #advance the cursor position
            if event.code == ecodes.REL_Y: #checking for y direction
                print("REL_Y", event.value)
                y += event.value * -1
            print(x, y)
        if event.type == ecodes.EV_KEY: #if the event is a button click
            c = categorize(event)
            if c.keystate == c.key_down: 
                print(c.keycode)

for device in globals()['keyboardEvent'] , globals()['mouseEvent']:
        asyncio.ensure_future(print_events(device))
loop = asyncio.get_event_loop()
loop.run_forever()

now if i do not move the mouse nothing in this loop runs. My question is how can i program a statement to account for this so i can use time.time() to say if no event in 60 seconds print hello. This is probably really easy but no answer online and i cant think of a logical way to do this.

0

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.