hid-keys key repetition....

General discussions about V-USB, our firmware-only implementation of a low speed USB device on Atmel's AVR microcontrollers
Post Reply
massimo

hid-keys key repetition....

Post by massimo » Tue Apr 10, 2007 9:37 pm

Hello I'm building a keyboard emulator using avr-hid and the hid keys demo...

i can't find any way to stop the computer from repeating a key...
i just want to be able to fire only one character until I release and press again. they computer seems to be repeating the code all the time...

this is my main event loop stripped to the core...

wdt_reset();
usbPoll();
key = PINC & 0x01;

if (( key == 1) && (lastKey == 0) ) {
while (!usbInterruptIsReady()) ;
buildReport(1);
usbSetInterrupt(reportBuffer, sizeof(reportBuffer));

}
lastKey = key;


as anybody got any idea?

massimo

christian
Objective Development
Objective Development
Posts: 1442
Joined: Thu Nov 09, 2006 11:46 am

Post by christian » Wed Apr 11, 2007 3:12 pm

The HID spec suggests that key repitition can be implemented by sending the keyboard status in an interrupt transfer in regular intervals.

Most operating system interpret the key status as status, measure the time how long a particular key is pressed and start repeating (with their own internal timer) after that time.

On the other hand, if an operating system wants to out-source the task of key repitition to the device, it configures an idle rate. HIDKeys does not implement properly, although it accepts the idle rate setting.

Search main.c for "USBRQ_HID_SET_IDLE" and "idleCounter" for details. The USB HID specification contains more information about the proper handling of USBRQ_HID_SET_IDLE.

xetkexet

Re: hid-keys key repetition....

Post by xetkexet » Wed Jul 17, 2013 5:33 pm

I define a new variable in main, lastSendKey.

Code: Select all

int   main(void)
{
   uchar   key, keyDidChange = 0, lastKey = 0, lastSendKey = 0;

Then I change a little bit in the usbSetInterrupt part

Code: Select all

if(keyDidChange && usbInterruptIsReady() && lastSendKey != lastKey){ //added: check so we dont send same key again :)
         keyDidChange = 0;
         /* use last key and not current key status in order to avoid lost
         changes in key status. */
         buildReport(lastKey);
         usbSetInterrupt(reportBuffer, sizeof(reportBuffer));
         lastSendKey = lastKey; // save last sended key to avoid repetions
      }
      else if (usbInterruptIsReady()) { // Usb interrupt Is ready but we haven't change key. Send no key (0)
         buildReport(0);
         usbSetInterrupt(reportBuffer, sizeof(reportBuffer));
      }


Maybee not the best way. But it works for me :)

Post Reply