The Digispark > Digispark Libraries

Digikeyboard and windows Alt+Numpad key combo



I'm trying to build a usb button that will be used as a shortcut for a Alt+Numpad  key combo on windows. I'm using a digispark and a push button. When the button is pressed, I would like to send to the computer the combo ALT+0183 using the digikeyboard librairy. The problem is that I can't figure how to hold ALT key pressed while sending the keystrokes for the numbers.
Is there anybody here that could have an idea to help me?


Using DigiKeyboard.sendKeyStroke()? It accepts two parameters, the keystroke and then the modifier. e.g. Alt+Arrow Down

--- Code: ---DigiKeyboard.sendKeyStroke(KEY_ARROW_DOWN, MOD_ALT_LEFT);
--- End code ---

The full list of all the keys that can be called that way is in the DigiKeyboard.h file...

Only thing I'm not sure if there is how you get it to hold the alt key down whilst entering the four digits... The other thing is you may need to send the correct keystrokes for the number pad keys? so 0 = 98, 1=89, 8=96 & 3=91 (from the HID Usage table - chapter 10 keyboard)

I found by myself how to do that :

First, I needed to define the following variable to send the numpad keys and not the ones which are above the QWERTY keys :

--- Code: ---#define KEYPAD_1                (  89  | 0xF000 )
#define KEYPAD_2                (  90  | 0xF000 )
#define KEYPAD_3                (  91  | 0xF000 )
#define KEYPAD_4                (  92  | 0xF000 )
#define KEYPAD_5                (  93  | 0xF000 )
#define KEYPAD_6                (  94  | 0xF000 )
#define KEYPAD_7                (  95  | 0xF000 )
#define KEYPAD_8                (  96  | 0xF000 )
#define KEYPAD_9                (  97  | 0xF000 )
#define KEYPAD_0                (  98  | 0xF000 )

--- End code ---

Then I used this code :

--- Code: ---DigiKeyboard.update();

--- End code ---

The "trick" was to use "sendKeyPress()" instead of "sendKeyStroke()" :
- sendKeyPress(keyid,mod) : press the keys "keyid" with the modifier "mod" but release none of them
- sendKeyStroke(keyid,mod) : press the keys "keyid" with the modifier "mod" and release all of them

BUT : in order to keep ALT pressed during the whole operation, it is important to use it as a modifier in each line

At the end, you can use sendKeyPress(0,0) to release all the keys.

I hope that it will help some people in the future :)


Too bad this does not work with repeating ALT numbers:

--- Code: ---DigiKeyboard.sendKeyPress(KEYPAD_4,MOD_ALT_LEFT);
DigiKeyboard.sendKeyPress(0);  // Release all keys

--- End code ---
The above will not work because the keypad numbers are also not released between "presses" …

A workaround is this:

--- Code: ---DigiKeyboard.sendKeyPress(KEYPAD_4,MOD_ALT_LEFT);
DigiKeyboard.sendKeyPress(0,MOD_ALT_LEFT); // Release all keys except "ALT"
DigiKeyboard.sendKeyPress(0);   // Release all

--- End code ---


Have good information to give slotxo


[0] Message Index

Go to full version