Make a custom combination key from keyboard and mouse using Maker Pi Pico.


Hardware Preparation

This is the list of items used in the video.

Sample Program

This is CircuitPython sample program and have been tested with CircuitPython 6.3.0. Before that, please include the following additional libraries:

  • adafruit_hid

You may download the CircuitPython Libraries Bundle ? here.

– CircuitPython HID Keyboard and Mouse
CircuitPython libraries bundle:
Additional libraries:
– adafruit_hid
Last Modified
– 6 July 2021
import time
import analogio
import board
import digitalio
import usb_hid
from adafruit_hid.keyboard import Keyboard
from adafruit_hid.keyboard_layout_us import KeyboardLayoutUS
from adafruit_hid.keycode import Keycode
from adafruit_hid.mouse import Mouse
x_axis = analogio.AnalogIn(board.A1)
y_axis = analogio.AnalogIn(board.A0)
control_key = Keycode.SHIFT
# Sleep for a bit to avoid a race condition on some systems
mouse = Mouse(usb_hid.devices)
keyboard = Keyboard(usb_hid.devices)
keyboard_layout = KeyboardLayoutUS(keyboard) # We're in the US 🙂
pot_min = 0.8
pot_max = 2.5
step = (pot_max pot_min) / 20.0
def get_voltage(pin):
return (pin.value * 3.3) / 65536
def steps(axis):
""" Maps the potentiometer voltage range to 0-20 """
result = round((axis pot_min) / step)
if result > 8 and result < 12:
result = 10
return result
buttons_pressed = False
while True:
x = get_voltage(x_axis)
y = get_voltage(y_axis)
if x > 3.0:
time.sleep(0.2) # Debounce delay
#print(steps(x), steps(y))
if steps(x) == 10 and steps(y) == 10:
if buttons_pressed == True:
buttons_pressed = False
if buttons_pressed == False:
buttons_pressed = True
if steps(x) > 11.0:
if steps(x) < 9.0:
if steps(x) > 19.0:
if steps(x) < 1.0:
if steps(y) > 11.0:
if steps(y) < 9.0:
if steps(y) > 19.0:
if steps(y) < 1.0:

view raw

hosted with ❤ by GitHub

Thank You


Thanks for reading this tutorial. If you have any technical inquiries, please post at Cytron Technical Forum.

Please be reminded, this tutorial is prepared for you to try and learn.
You are encouraged to improve the code for a better application.

Leave a Comment

Your email address will not be published.

Share this Tutorial

Share on facebook
Share on whatsapp
Share on email
Share on print
Share on twitter
Share on pinterest
Share on facebook
Share on whatsapp
Share on email
Share on print
Share on twitter
Share on pinterest

Latest Tutorial

IoT Push Notification Using Rain Sensor with MicroBit
Low Profile Aluminum Case and Icon Case Stress Test
DIY Digital Alarm Clock Using REKA:BIT With Micro:bit | Tutorial for Beginners
Send Temperature and Humidity Data To ThingSpeak Using micro:bit
DIY Interactive Robot using REKA:BIT with micro:bit | Tutorial for Beginners
Tutorials of Cytron Technologies Scroll to Top