Bluefruit EZ-Key and KEY UP / KEY DOWN HID messages.

Breakout boards, sensors, other Adafruit kits, etc.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
allenhuffman
 
Posts: 15
Joined: Mon Dec 09, 2013 11:56 am

Bluefruit EZ-Key and KEY UP / KEY DOWN HID messages.

Post by allenhuffman »

I am about to start experimenting with the EZ-KEY, and I have a question about the byte sequences. I have worked with USB HID on Teensy and Arduino Leonardo, but their API hides things. In the HID keyboard sequence:

0xFD [modifiers] 0x00 [keycode1] [keycode2] [keycode3] [keycode4] [keycode5] [keycode6]

...the tutorial says:
Here is the Arduino function we use to send a raw keyCommand. For example if you want to send the keystroke for the letter 'a' (no shift) you'll want to call

keyCommand(0, 4);

to press the keycode 4 ('a') followed by a release

keyCommand(0, 0);

if you want to press 'a' and 'b' at the same time, send

keyCommand(0, 4, 5);

for keycodes 4 and 5 at the same time. You can send up to 6 consecutive keys at once, don't forget to send the release 'key up' command or the key will be 'stuck'!
I worked with straight USB keyboard HID, but not Bluetooth. What is releasing the KEY_A (4) and KEY_B (5) -- is that (0, 0, 0)? If so, does this mean the six key code slots in the Bluefruit EZ-Key are tied to whatever KEY_DOWN they first sent? (No more than 6 depressed at the same time?)

Suppose I wanted to hold down a key, then press and release a few keys with delays in between, then release the first key at the end. On Arduino, it might look like this:

Code: Select all

// Hold down LEFT SHIFT
Keyboard.press(KEY_LEFT_SHIFT); // press SHIFT
delay(1000);
Keyboard.press('a'); // press a
delay(1000);
Keyboard.release('a'); // release a
Keyboard.press('b');// press b
delay(1000);
Keyboard.release('b'); // release b
delay(1000);
Keyboard.release(KEY_LEFT_SHIFT); // release SHIFT
How is that done here?

Code: Select all

keyCommand(MODIFIER_SHIFT_LEFT); // press shift
delay(1000);
// ???
keyCommand(MODIFIER_SHIFT_LEFT, KEY_A); // press shift+a
delay(1000);
keyCommand(MODIFIER_NONE, KEY_A); // release shift+a
delay(1000);
// ???
keyCommand(MODIFIER_SHIFT_LEFT, KEY_B); // press shift+b
delay(1000);
keyCommand(MODIFIER_NONE, KEY_B); // release shift+b
delay(1000);
// release shift here...
...that doesn't seem right. If it was just using the six keycode slots, at each step it would have to keep resending the MODIFIER_SHIFT_LEFT over and over (does that actually go out as the key is being pressed even though it was already held down)?

I expect this is quite simple, and I am just being confused by the example.

(For my actual application, I am not sending shift and such, but might be holding down '1' and then pressing and releasing 'a' then 'x' then 'y' and then releaseing the '1' -- that type of thing.)

Thanks.

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: Bluefruit EZ-Key and KEY UP / KEY DOWN HID messages.

Post by adafruit_support_rick »

allenhuffman wrote:What is releasing the KEY_A (4) and KEY_B (5) -- is that (0, 0, 0)?
Correct.
allenhuffman wrote:Suppose I wanted to hold down a key, then press and release a few keys with delays in between, then release the first key at the end.
I believe you could do a sequence like this:

Code: Select all

keyCommand(0, 4);  //press 'a'
keyCommand(0, 4, 5);     // hold 'a', press 'b'
keyCommand(0, 4);       //hold 'a', release 'b'
keyCommand(0, 4, 6);       // hold 'a', press 'c'
keyCommand(0, 0);     // release 'a' and 'c'

Locked
Please be positive and constructive with your questions and comments.

Return to “Other Products from Adafruit”