Author Topic: Digikeyboard and windows Alt+Numpad key combo  (Read 5136 times)

gmarion

  • Newbie
  • *
  • Posts: 4
Digikeyboard and windows Alt+Numpad key combo
« on: January 17, 2018, 02:45:19 pm »
Hi!

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?

Regards

PeterF

  • Hero Member
  • *****
  • Posts: 877
Re: Digikeyboard and windows Alt+Numpad key combo
« Reply #1 on: January 17, 2018, 11:25:53 pm »
Using DigiKeyboard.sendKeyStroke()? It accepts two parameters, the keystroke and then the modifier. e.g. Alt+Arrow Down

Code: [Select]
DigiKeyboard.sendKeyStroke(KEY_ARROW_DOWN, MOD_ALT_LEFT);
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 USB.org HID Usage table - chapter 10 keyboard)


gmarion

  • Newbie
  • *
  • Posts: 4
Re: Digikeyboard and windows Alt+Numpad key combo
« Reply #2 on: January 20, 2018, 06:54:56 am »
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: [Select]
#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 )


Then I used this code :

Code: [Select]
DigiKeyboard.update();
DigiKeyboard.sendKeyPress(KEYPAD_0,MOD_ALT_LEFT);
DigiKeyboard.sendKeyPress(KEYPAD_1,MOD_ALT_LEFT);
DigiKeyboard.sendKeyPress(KEYPAD_8,MOD_ALT_LEFT);
DigiKeyboard.sendKeyPress(KEYPAD_3,MOD_ALT_LEFT);
DigiKeyboard.sendKeyPress(0,0);   
DigiKeyboard.delay(100);

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 :)

G

Photubias

  • Newbie
  • *
  • Posts: 1
Re: Digikeyboard and windows Alt+Numpad key combo
« Reply #3 on: November 17, 2018, 11:04:11 am »
Too bad this does not work with repeating ALT numbers:

Code: [Select]
DigiKeyboard.sendKeyPress(KEYPAD_4,MOD_ALT_LEFT);
DigiKeyboard.sendKeyPress(KEYPAD_4,MOD_ALT_LEFT);
DigiKeyboard.sendKeyPress(0);  // Release all keys
The above will not work because the keypad numbers are also not released between "presses" …

A workaround is this:
Code: [Select]
DigiKeyboard.sendKeyPress(KEYPAD_4,MOD_ALT_LEFT);
DigiKeyboard.sendKeyPress(0,MOD_ALT_LEFT); // Release all keys except "ALT"
DigiKeyboard.sendKeyPress(KEYPAD_4,MOD_ALT_LEFT);
DigiKeyboard.sendKeyPress(0);   // Release all

Regards,
Photubias