︎Back to Interactive & Experience Design

Fall 2023 ︎︎︎ SUNY Purchase ︎︎︎ (DES3090) Interactive & Experience Design

knitting Circle: Major Key(boards and mice)


The CPX can function, because it connects through USB, as what is called a Human Interface Device or HID. This allows it to appear (to our computer) as a keyboard, or a mouse, or what are called “consumer controls” (the play or pause buttons for controlling media which is a good way to “fake” playing higher quality audio with the CPX). 

For reference, I am using the examples for the keyboard and consumer controls from this page︎ and the examples for the mouse from this page︎  

Sending Keyboard Messages

This first example sends individual keycodes. This is probably most relevant for non-alphanumeric keys like the arrow keys or SHIFT or CMD. Here’s an introductory example︎︎︎

You can also send multiple key presses to, for example, send a message︎︎︎

You may need to reference all the keycodes, especially if you want to work with non-alphanumeric keys. Those are listed here︎

Controlling Consumer Controls

Here’s the consumer control code. If you have a YouTube video open and the window is “in focus” (selected) the consumer controls should cause the video to play and pause if you use that option.︎︎︎

Controlling the Mouse

Here’s a simple example, using the capacitive touch sensors on the CPX to control the mouse and the scrollwheel. There are three parameters in the move() function you’ll see below. First is the x position, second is y and last is the scrollwheel. Note that the location is relative to the mouse’s original position. That is to say, you don’t say the specific position you want the mouse to move to, you say the amount you want it to move from it’s current position.︎︎︎

Tilting Out

Here’s an example of something unique to the CPX we can do, which is use the accelerometer or tilt control the mouse. The accelerometer works with the cpx.acceleration tuple. It has x, y, and z values, we access x with cpx.acceleration[0] and y with cpx.acceleration[1], similar to how we talked to the neopixels.

There’s a little bit of math here (multiplication). If you want to edit this code, know that if you don’t have a way to turn off the mouse accelerometer control, it will be annoying to edit the code ︎︎︎︎