digistump / DigistumpArduino

Files to add Digistump support (Digispark, Pro, DigiX) to Arduino 1.6.X (1.6.5+)
949 stars 379 forks source link

added functionality to send keypresses, i.e. a press without release #18

Closed eta-orionis closed 8 years ago

eta-orionis commented 8 years ago

added functionality to send keypresses, i.e. a press without release.

sendKeyStroke sends the release automatically, which creates a problem when you want to use the repeating key functionality of your OS. This change is backwards compatible and introduces the sendKeyPress function for cases when you want explicit control over press and release events.

digistump commented 8 years ago

Thanks!

nsisodiya commented 7 years ago

@eelmasllari - can you fix this ? https://github.com/digistump/DigistumpArduino/issues/48 Unable to generate this sequence. Can we hold two keys and release them separately ? We can do in normal keyboard but not with this library.

eta-orionis commented 7 years ago

I have moved on to other projects since, but have you tried sendKeyPress(0, MOD_ALT_LEFT) to keep the ALT pressed and release the tab? That's the only thing I can think of.

nsisodiya commented 7 years ago

@eelmasllari - yes, I have tried, but that is not working..

I basically need a Window Switch behaviour, we do window switch like Alt + Tab, while we hold Alt key for long time but we keep on pressing Tab key again and again for moving to next window in desktop OS.

Also, sendKeyPress(0, MOD_ALT_LEFT) do press (no -release) the ALT key but I have to press Tab key too (press-release). so, I have cododed l

DigiKeyboard.sendKeyPress(0, MOD_ALT_LEFT);//Pressing Alt -no release
DigiKeyboard.delay(1000);
DigiKeyboard.sendKeyStroke(KEY_Tab);

Culprit is sendKeyStroke which release both keys, ALT and TAB both. I want to emulate the window switch behaviour. Let me know if you able to understand me. may me you can give me idea so that I can improve your pull request if needed..

nsisodiya commented 7 years ago

@eelmasllari @digistump

I used xev to look what happen when I release multiple keys.. this is what i got

I pressed ALT KEY for long and in between I pressed KEY_A twice. So you can notice that multiple KeyRelease event came from Laptop keyboard. while KeyRelease for ALT came at the last. right not, DigiKeyboard library do not support individual key release.

KeyPress event, serial 36, synthetic NO, window 0x4400001,
    root 0xc4, subw 0x0, time 42418533, (-121,265), root:(536,445),
    state 0x0, keycode 64 (keysym 0xffe9, Alt_L), same_screen YES,
    XLookupString gives 0 bytes: 
    XmbLookupString gives 0 bytes: 
    XFilterEvent returns: False

KeyPress event, serial 36, synthetic NO, window 0x4400001,
    root 0xc4, subw 0x0, time 42419575, (-121,265), root:(536,445),
    state 0x8, keycode 38 (keysym 0x61, a), same_screen YES,
    XLookupString gives 1 bytes: (61) "a"
    XmbLookupString gives 1 bytes: (61) "a"
    XFilterEvent returns: False

KeyRelease event, serial 36, synthetic NO, window 0x4400001,
    root 0xc4, subw 0x0, time 42419694, (-121,265), root:(536,445),
    state 0x8, keycode 38 (keysym 0x61, a), same_screen YES,
    XLookupString gives 1 bytes: (61) "a"
    XFilterEvent returns: False

KeyPress event, serial 36, synthetic NO, window 0x4400001,
    root 0xc4, subw 0x0, time 42420421, (-121,265), root:(536,445),
    state 0x8, keycode 38 (keysym 0x61, a), same_screen YES,
    XLookupString gives 1 bytes: (61) "a"
    XmbLookupString gives 1 bytes: (61) "a"
    XFilterEvent returns: False

KeyRelease event, serial 36, synthetic NO, window 0x4400001,
    root 0xc4, subw 0x0, time 42420516, (-121,265), root:(536,445),
    state 0x8, keycode 38 (keysym 0x61, a), same_screen YES,
    XLookupString gives 1 bytes: (61) "a"
    XFilterEvent returns: False

KeyRelease event, serial 36, synthetic NO, window 0x4400001,
    root 0xc4, subw 0x0, time 42420986, (-121,265), root:(536,445),
    state 0x8, keycode 64 (keysym 0xffe9, Alt_L), same_screen YES,
    XLookupString gives 0 bytes: 
    XFilterEvent returns: False
eta-orionis commented 7 years ago

I can't test this, but have you tried something along these lines?

DigiKeyboard.sendKeyPress(0, MOD_ALT_LEFT);//Pressing Alt -no release

DigiKeyboard.delay(200); //Wait a bit before pressing Tab
DigiKeyboard.sendKeyPress(KEY_Tab, MOD_ALT_LEFT);//Pressing Tab -no release
DigiKeyboard.delay(200); //Keep Tab 200ms pressed
DigiKeyboard.sendKeyPress(0, MOD_ALT_LEFT);//Release Tab, keep alt pressed

DigiKeyboard.delay(200); //Wait 200 ms between "Tab"-s
DigiKeyboard.sendKeyPress(KEY_Tab, MOD_ALT_LEFT);//Pressing Tab -no release
DigiKeyboard.delay(200); //Keep Tab 200ms pressed
DigiKeyboard.sendKeyPress(0, MOD_ALT_LEFT);//Release Tab, keep alt pressed

//Can press tab as many times as you want by repeating the four lines above

DigiKeyboard.delay(200); //Keep Alt pressed a bit more
DigiKeyboard.sendKeyPress(0, 0);//Release Alt
nsisodiya commented 7 years ago

@eelmasllari Let me try !!