Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PLAN] Key logger for data collection #30

Closed
xjjak opened this issue Jan 28, 2024 · 4 comments · Fixed by #37
Closed

[PLAN] Key logger for data collection #30

xjjak opened this issue Jan 28, 2024 · 4 comments · Fixed by #37
Assignees
Labels
in planning Accepted idea or not yet fleshed out plan software
Milestone

Comments

@xjjak
Copy link
Owner

xjjak commented Jan 28, 2024

We need a keylogger for our keyboards.
This would enable easier collection of larger datasets, which would also be less unbalanced and more realistic.

Possible approaches:

We tried using the keycodes sent by the keyboard, making it completely device-side. This was not very successful.
It should be attempted to utilize the QMK firmware, possibly with custom code snippets to make collection easier or even on the keyboards themselves. This could be done by sending key numbers through a separate channel, similar to something described in this article under Firmware.

@xjjak xjjak added software in planning Accepted idea or not yet fleshed out plan labels Jan 28, 2024
@xjjak xjjak self-assigned this Jan 28, 2024
@xjjak xjjak changed the title [IDEA] Key logger for data collection [PLAN] Key logger for data collection Jan 28, 2024
@xjjak xjjak added this to the JuFo Regio milestone Feb 9, 2024
@xjjak
Copy link
Owner Author

xjjak commented Feb 14, 2024

To add key logging output to my keyboard with the following additions/modifications on to of the tutorial:

  • Follow basic qmk instructions for building and flashing

  • locate the folder with keymap.json/keymap.c

  • If there is only keymap.json: run qmk json2c keymap.json > keymap.c

  • remove/rename the .json

  • change the bootloader in rules.mk to atmel-dfu

  • Append the following to keymap.c:

    bool process_record_user(uint16_t keycode, keyrecord_t *record) {
        #ifdef CONSOLE_ENABLE
            const bool is_combo = IS_COMBOEVENT(record->event); // DIFFERS FROM TUTORIAL
            uprintf("0x%04X,%u,%u,%u,%b,0x%02X,0x%02X,%u\n",
                 keycode,
                 is_combo ? 254 : record->event.key.row,
                 is_combo ? 254 : record->event.key.col,
                 get_highest_layer(layer_state),
                 record->event.pressed,
                 get_mods(),
                 get_oneshot_mods(),
                 record->tap.count
                 );
        #endif
        // switch (keycode) {
        // //...
        // }
        return true;
    }

    The line is_combo check had to be changed as COMBO_EVENT wasn't found. There is a wrapper function available called IS_COMBOEVENT which returns a bool.

  • Now try compilation with qmk compile (assuming standard kb and km are set)
    I encountered the following error:

    Compiling: platforms/avr/drivers/i2c_master.c                                                      In function 'i2c_start_impl',
        inlined from 'i2c_start' at platforms/avr/drivers/i2c_master.c:104:18:
    platforms/avr/drivers/i2c_master.c:61:10: error: array subscript 0 is outside array bounds of 'volatile uint8_t[0]' {aka 'volatile unsigned char[]'} [-Werror=array-bounds=]
       61 |     TWCR = 0;
          |          ^
    

    Reddit led me here with a workaround to be found here

    The workaround disables this type of error, by appending -e AVR_CFLAGS="-Wno-array-bounds" to qmk compile or qmk flash

@xjjak
Copy link
Owner Author

xjjak commented Feb 14, 2024

The plan now is to write a simple script the output of hid_listen can be piped into, which prepends the current Unix timestamp. A format changing "filter" can be applied to the whole file afterward if necessary for compatibility with the current training method.

@xjjak xjjak mentioned this issue Feb 15, 2024
@xjjak
Copy link
Owner Author

xjjak commented Feb 15, 2024

For the HID console, the QMK udev rules from qmk_fimware/utils/udev/50-qmk.rules must be copied to lib/udev/rules.d or that directory in its corresponding location.

@xjjak
Copy link
Owner Author

xjjak commented Mar 18, 2024

To mitigate the effect that a press event was only sent after a hold-event was detected when a key was kept pressed, the modified function was changed to pre_process_user_record(). Thanks, @palisn, for figuring that out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in planning Accepted idea or not yet fleshed out plan software
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants