Need help with uinput script.
Posted: Wed Oct 02, 2013 9:29 pm
Hi all,
I'm trying to get this script to work, I want it to be able to emulate a keyboard press everytime I push on a button connected to a gpio pin (17 in this case)
but now it only emulates the key once, but it does register the button being pressed.
So, I run the script, the terminal screen says "Waiting for input." and when I push the button the terminal screen says "Button 1 Pressed" and the screen connected to the rapberry pi says "n", so far so good. But if I piush the button again, the terminal says "Button 1 Pressed" but the screen on the pi says nothing, so the "n" command only works once.
here is the code:
I hope someone can help me out, I don't see why this doesn't work the way I thought it would.
Thanks.
I'm trying to get this script to work, I want it to be able to emulate a keyboard press everytime I push on a button connected to a gpio pin (17 in this case)
but now it only emulates the key once, but it does register the button being pressed.
So, I run the script, the terminal screen says "Waiting for input." and when I push the button the terminal screen says "Button 1 Pressed" and the screen connected to the rapberry pi says "n", so far so good. But if I piush the button again, the terminal says "Button 1 Pressed" but the screen on the pi says nothing, so the "n" command only works once.
here is the code:
Code: Select all
#!/usr/bin/env python
import uinput
import os
from time import sleep
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
BUTTON_1 = 17
device = uinput.Device([uinput.KEY_N])
GPIO.setup(BUTTON_1, GPIO.IN, pull_up_down=GPIO.PUD_UP)
def Input_1(channel):
device.emit(uinput.KEY_N, 1)
status ='Button 1 Pressed'
print status
return (status)
GPIO.add_event_detect(BUTTON_1, GPIO.FALLING, callback=Input_1, bouncetime=300)
while True:
print "Status is ", status , '- Waiting for input.'
sleep(10);
# GPIO.cleanup()Thanks.