How to do it...

Create a gpiokeys.py script as follows:

#!/usr/bin/python3 #gpiokeys.py import time import RPi.GPIO as GPIO import uinput #HARDWARE SETUP # GPIO # 2[==G=====<=V==]26[=======]40 # 1[===2=1>^=====]25[=======]39 B_DOWN = 22 #V B_LEFT = 18 #< B_UP = 15 #^ B_RIGHT = 13 #> B_1 = 11 #1 B_2 = 7 #2 DEBUG=True BTN = [B_UP,B_DOWN,B_LEFT,B_RIGHT,B_1,B_2] MSG = ["UP","DOWN","LEFT","RIGHT","1","2"] #Setup the DPad module pins and pull-ups def dpad_setup(): #Set up the wiring GPIO.setmode(GPIO.BOARD) # Setup BTN Ports as INPUTS for val in BTN: # set up GPIO input with pull-up control #(pull_up_down can be: # PUD_OFF, PUD_UP or PUD_DOWN, default PUD_OFF) GPIO.setup(val, GPIO.IN, pull_up_down=GPIO.PUD_UP) def main(): #Setup uinput events = ...

Get Raspberry Pi 3 Cookbook for Python Programmers - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.