void handlePacket(byte[] hidReport, int packetLen) throws
            IOException,
            AWTException {

        // decode keys, only process up to NUM_KEYS
        int modifier = hidReport[2];
        int nrKeys = packetLen - 4;
        if (nrKeys > NUM_KEYS){

            nrKeys = NUM_KEYS;

        }

        // modifier keys
        boolean ctrl_pressed    = (modifier & 0x11) != 0;
        boolean shift_pressed   = (modifier & 0x22) != 0;
        boolean alt_pressed     = (modifier & 0x44) != 0;
        boolean command_pressed = (modifier & 0x88) != 0;

        // process events
        for (int i=0; i< nrKeys; i++){
            // find key in last state
            int new_event = hidReport[4+i];
            if (new_event == 0) continue;
            for (int j=0; j<NUM_KEYS; j++){
                if (new_event == last_keyboard_state[j]){
                    new_event = 0;
                    break;
                }
            }
            if (new_event == 0) continue;

            // get from table
            int new_key = 0;
            //     System.out.println("New Event:"+new_event);
            if (new_event <= 57){
                new_key = keytable_us_none[new_event];
            } else if (new_event >= 0x4f && new_event <= 0x52) {
                new_key = cursor_keys[ new_event - 0x4f];
            } else {
                continue;
            }

            injectKey(new_key, shift_pressed, ctrl_pressed,
                    alt_pressed, command_pressed);

        }

        // store keyboard state
        System.arraycopy(hidReport, 4, last_keyboard_state, 0, NUM_KEYS);
        last_modifier = modifier;
    }