HIDKeys: issue key on both press and release

General discussions about V-USB, our firmware-only implementation of a low speed USB device on Atmel's AVR microcontrollers
Post Reply
Ross_ValuSoft
Posts: 15
Joined: Sun Oct 28, 2012 1:41 pm

HIDKeys: issue key on both press and release

Post by Ross_ValuSoft » Thu Apr 03, 2014 6:56 am

Hi everyone.

Has anyone succeeded in being able to issue a key on both a switch press and its release? I have tried a few ways but been unsuccessful. A clue to get me in the correct direction would be appreciated.

Thanks,

Ross

Ross_ValuSoft
Posts: 15
Joined: Sun Oct 28, 2012 1:41 pm

Re: HIDKeys: issue key on both press and release

Post by Ross_ValuSoft » Tue Apr 08, 2014 10:09 pm

No one?

blargg
Rank 3
Rank 3
Posts: 102
Joined: Thu Nov 14, 2013 10:01 pm

Re: HIDKeys: issue key on both press and release

Post by blargg » Thu Apr 10, 2014 2:27 am

Hi, I just downloaded HIDkeys, got it working on a USBasp stick (with fewer keys), and came up with this modification to generate distinct key events when you release the button. So you get 1-17 when pressed, 18-34 when released (in the keyReport array). So when I pressed a certain button, it types an A, and then when I release that button, it types an R.

Code: Select all

// main.c:68
#define NUM_KEYS    17*2

// main.c:266
        if(lastKey != key && !keyDidChange){
            if (lastKey && lastKey <= NUM_KEYS/2)
                lastKey += NUM_KEYS/2;
            else
                lastKey = key;
            keyDidChange = 1;
        }

// main.c:200
static const uchar  keyReport[NUM_KEYS + 1][2] PROGMEM = {
/* none */  {0, 0},                     /* no key pressed */
/*  1 */    {MOD_SHIFT_LEFT, KEY_A},
/*  2 */    {MOD_SHIFT_LEFT, KEY_B},
/*  3 */    {MOD_SHIFT_LEFT, KEY_C},
/*  4 */    {MOD_SHIFT_LEFT, KEY_D},
/*  5 */    {MOD_SHIFT_LEFT, KEY_E},
/*  6 */    {MOD_SHIFT_LEFT, KEY_F},
/*  7 */    {MOD_SHIFT_LEFT, KEY_G},
/*  8 */    {MOD_SHIFT_LEFT, KEY_H},
/*  9 */    {MOD_SHIFT_LEFT, KEY_I},
/* 10 */    {MOD_SHIFT_LEFT, KEY_J},
/* 11 */    {MOD_SHIFT_LEFT, KEY_K},
/* 12 */    {MOD_SHIFT_LEFT, KEY_L},
/* 13 */    {MOD_SHIFT_LEFT, KEY_M},
/* 14 */    {MOD_SHIFT_LEFT, KEY_N},
/* 15 */    {MOD_SHIFT_LEFT, KEY_O},
/* 16 */    {MOD_SHIFT_LEFT, KEY_P},
/* 17 */    {MOD_SHIFT_LEFT, KEY_Q},
/* 18 */    {MOD_SHIFT_LEFT, KEY_R}, // 1-34 release gives these
/* 19 */    {MOD_SHIFT_LEFT, KEY_S},
/* 20 */    {MOD_SHIFT_LEFT, KEY_T},
/* 21 */    {MOD_SHIFT_LEFT, KEY_U},
/* 22 */    {MOD_SHIFT_LEFT, KEY_V},
/* 23 */    {MOD_SHIFT_LEFT, KEY_W},
/* 24 */    {MOD_SHIFT_LEFT, KEY_X},
/* 25 */    {MOD_SHIFT_LEFT, KEY_Y},
/* 26 */    {MOD_SHIFT_LEFT, KEY_Z},
/* 27 */    {MOD_SHIFT_LEFT, KEY_1},
/* 28 */    {MOD_SHIFT_LEFT, KEY_2},
/* 29 */    {MOD_SHIFT_LEFT, KEY_3},
/* 30 */    {MOD_SHIFT_LEFT, KEY_4},
/* 31 */    {MOD_SHIFT_LEFT, KEY_5},
/* 32 */    {MOD_SHIFT_LEFT, KEY_6},
/* 33 */    {MOD_SHIFT_LEFT, KEY_7},
/* 34 */    {MOD_SHIFT_LEFT, KEY_8},
};

Ross_ValuSoft
Posts: 15
Joined: Sun Oct 28, 2012 1:41 pm

Re: HIDKeys: issue key on both press and release

Post by Ross_ValuSoft » Thu Apr 10, 2014 3:15 am

Many, many thanks.

I will test it after my granddaughters (5 and 3) go home tomorrow. At the moment that are using 120% of our time and energies. :lol:

Cheers,

Ross

Ross_ValuSoft
Posts: 15
Joined: Sun Oct 28, 2012 1:41 pm

Re: HIDKeys: issue key on both press and release

Post by Ross_ValuSoft » Fri Apr 11, 2014 2:41 pm

Hi Blarrg.

Granddaughters have gone back to their parents and I have just tested your code... successfully. Thanks.

Now I need to understand it and extend it so that multiple keys can be pressed and released without interfering with each other. Another day... another quest.

Cheers,

Ross (who has been answering to "Pops" for the last 48 hours :lol: )

katt
Posts: 1
Joined: Wed Nov 12, 2014 10:46 am

Re: HIDKeys: issue key on both press and release

Post by katt » Wed Nov 12, 2014 10:50 am

This equals 88 bits. In the hypothical worst case all data is FF, which is practictally impossible. In that case 14 bits are "stuffed", resulting in a total maximum critical packet lengths of 102 bits or 84 without CRC.

_______________________
Unlike scam 820-421 exam and itil wikipedia training program, our best Stanford University and IBM online training courses provide you quick success in first try of LPI

Post Reply