Custom shortcuts with cheap STM32 development board(s), external buttons and AHK script.
This project is a solution to all of those who want to optimize their workflow by pressing single button that is able to perform various actions.
Cheap STM32L100-Discovery board is used as a basic HID keyboard. Most of the code is automatically generated by STM32CubeMX code generator tool. 7 buttons are used here, but this can be easily expanded further by the user.
By using our free libs, this device will simulate a specific key press: F18 - F24 CTRL+SHIFT+F13 (to CTRL+SHIFT+F19)(*). Since this combination can't be pressed by the user (normal keyboards doesn't have F13 and above key), that is kind-of unique key press that can be intercepted by AHK, great automation scripting tool which can generate some action if specified.
Action could be as simple as sending a single shortcut, sequence of shortcuts, custom scripts or program specific actions. For example: in this project, key 1 press open file location in explorer, if VS Code application is in currently in focus. On the other hand, if Reaper DAW is in focus, it will stop and undo current recording.
(*) Update 13-Feb-2021: Using modifier keys could be a problem if multiple devices are toggling it or user press/release same modifier keys from different devices. Hence, latest version just use F18-F24 keys since they are not really accessible by normal keyboards.
- You already have everything you need in this project, based on STM32CubeIDE. Currently, 7 buttons are configured and sent to the host via USB as a generic HID keyboard. USB report is defined as a 'standard' 8 byte sequence, following the official usage table. Each key press is packed as a separate report on a button press event (not release or long press).
- AHK script is also available as an example how to intercept and handle this simulated keyboard events and add actions based on a current application in focus.
- Additionally events are sent on UART1 (RX - PA10, TX - PA9 @ 115200) and can be observed with any UART-USB converter and our Serial Tool.
- Button 7 is currently used as a test button and should raise a GUI pop-up window.
- NOTEAlthough most of the USB code is automatically generated by STM32CubeMX, usb report descriptor and its size aren't. See user-defined
CUSTOM_HID_ReportDesc_FS
and#define CUSTOM_HID_EPIN_SIZE
. Note thatCUSTOM_HID_EPIN_SIZE
is always rewritten on code generation (by STM32CubeIDE). Keep this in mind if you do any custom modifications.
- I used some old cheap STM32L100 Discovery board, but with just a little effort, any probably USB-capable STM32 board can be used. A short (1 m) USB cable is connected:
- GND
- DP (green, PA12, external pull-up 1K5)
- DM (white, PA11, direct connection)
- Buttons are connected directly:
- PC1 - PC3, PA0 - PA3
- shared GND
- internal pull-up
- debouncing performed by our free generic button library
- 7 buttons are used since (together with GND), standard UTP cable can be used. This is practical since this buttons panel can also be used away from the keyboard/PC, for example, on a sofa.
- Board is (at the moment) powered by main development board USB connector (debugger). Later on, everything will be connected&powered only via USB cable.