This extension integrates the Makey Makey with the micro:bit through the Code-a-Key backpack. It allows you to program the micro:bit for keyboard and mouse interactions, responding to key presses and mouse clicks from the Makey Makey.
The initialize Makey Makey
block is essential and should be placed at the start of your On Start
event block.
// initialize Makey Makey block
MakeyMakey.sx1509Init()
Simulates a key press and release sequence with an adjustable delay.
// press and release Key block
MakeyMakey.typeKey(KeyPress.W)
Holds a key down until released.
// press key block
MakeyMakey.pressKey(KeyPress.W)
Releases a key that was held down.
// release key block
MakeyMakey.release(KeyRelease.W)
Triggers an event when the Makey Makey sends any key press to the computer.
// when key pressed block
MakeyMakey.whenKeyPressed(() => {
// Code to execute when a key is pressed
})
Mimics a mouse click, consisting of a mouse down and up event.
// click mouse button block
MakeyMakey.clickMouse(MouseButtons.Left)
Moves the mouse cursor in a specified direction for a set duration.
// move mouse for ms block
MakeyMakey.moveMouseForMilliseconds(MouseDirections.Up, 1000)
Triggers an event when the Makey Makey sends a left or right mouse click to the computer.
// when makey makey mouse clicked block
MakeyMakey.whenMouseClicked(() => {
// Code to execute when a mouse button is clicked
})
These blocks offer more control over key and mouse button presses, allowing for complex behaviors.
Holds down a mouse button until released.
// press mouse button block
MakeyMakey.pressMouseButton(MouseButtons.Left)
Releases a mouse button that was held down.
// release mouse button block
MakeyMakey.releaseMouseButton(MouseButtons.Left)
Starts moving the mouse in a given direction.
// begin moving mouse block
MakeyMakey.moveMouse(MouseDirections.Up)
Stops the mouse from moving in a given direction.
// stop mouse block
MakeyMakey.stopMouse(MouseDirections.Up)
Adjusts the debounce timing for press-and-release and click actions.
// set debounce block
MakeyMakey.setDebounce(100)
Sets the polling rate for the Makey Makey input event blocks. The default rate is 20ms. This is how often the micro:bit will check for changes in the state of the Makey Makey input pins
// set polling rate block
MakeyMakey.setPollingRate(50)
Executes code when the Makey Makey transitions from having any keys and/or mouse buttons pressed to zero keys and/or mouse buttons pressed.
// when all makey makey released block
MakeyMakey.onReleaseEvent(MakeyMakeyReleaseEventTypes.AllReleased, () => {
// Code to execute when all keys and/or mouse buttons are released
})
Executes code when the Makey Makey transitions from having zero keys and/or mouse buttons pressed to any keys and/or mouse buttons pressed.
// when Makey Makey pressed block
MakeyMakey.onReleaseEvent(MakeyMakeyReleaseEventTypes.AllReleased, () => {
// Code to execute when any keys and/or mouse buttons are pressed
})
Configures the debounce time for key and mouse events.
// Set Debounce Time block
MakeyMakey.setDebounce(100) // Set the debounce time in milliseconds
Checks if any Makey Makey key is currently pressed.
// Any Key Pressed block
let isAnyKeyPressed = MakeyMakey.anyKeyPressed()
Checks if any Makey Makey mouse button is currently pressed.
// Any Mouse Button Pressed block
let isAnyMouseButtonPressed = MakeyMakey.anyMouseClicked()