Jump to content
NotebookTalk

HowTo- QMK AutoFire (Toggle-able repeating keys)


Reciever

Recommended Posts

Good Morning Everyone! 

 

This thread was originally an inquiry regarding if there were keyboards that could do AutoFire keystrokes. The end result was QMK powered keyboards. An example of the code needed will be pasted below. 

 

#define SPAM_DELAY 50  // 50 milliseconds between spams
bool spam_active = false;
uint32_t spam_timer = 0;

// Place the above near the beginning of the keymap

enum custom_keycodes {
    F2TR = SAFE_RANGE, // Create a keycode to make your toggle initialize
};

bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  switch (keycode) {
    case F2TR:  // When you press custom SPAM keycode
      if (record->event.pressed) {
        spam_active = !spam_active;  // Toggle spamming
        spam_timer = timer_read32(); // Reset spam timer
      }
      break;
  }
  return true;
}


void matrix_scan_user(void){
  if (spam_active) {  
    // Check if it's been SPAM_DELAY milliseconds since the last spam
    if (timer_elapsed32(spam_timer) > SPAM_DELAY) {
      tap_code(KC_P2);           // Send an F2 keystroke
      spam_timer = timer_read32();  // Reset spam timer
    }
  }
}

 

Link to comment
Share on other sites

  • Reciever changed the title to Any Keyboards with a hardware based AutoFire capability?

Does it have to be a full keyboard? There are hardware macro pads that look like the tenkey portion of a keyboard where you can program all kinds of functions into them that stay with the device. If you're only looking to perform a few specific things, it would certainly be a more portable option than moving around a full-size keyboard.

Desktop: Ryzen 5 5600X3D | 32 GB RAM | GeForce RTX 4070 Super | 4 TB SSD | Windows 11

MacBook Pro 14: M1 Max 10-core CPU | 64 GB RAM | 32-core GPU | 2 TB SSD | macOS

Lenovo IdeaPad 3 Gaming: Ryzen 7 6800H | 16 GB RAM | GeForce RTX 3050 | 512 GB SSD | Windows 11

Lenovo IdeaPad 5 Pro: Ryzen 5 5600U | 16 GB RAM | Radeon Graphics | 512 GB SSD | Windows 11

 

Link to comment
Share on other sites

4 hours ago, saturnotaku said:

Does it have to be a full keyboard? There are hardware macro pads that look like the tenkey portion of a keyboard where you can program all kinds of functions into them that stay with the device. If you're only looking to perform a few specific things, it would certainly be a more portable option than moving around a full-size keyboard.

I am familiar with macropads and I have a 9-key version of such a device but the issue with the one I have is that it seems to not work through my other devices 95% of the time as it fails to negotiate the standard handshaking process that occurs over USB. It appears (likely) due to a dependency for redistributable or .net, havent spent the time to determine. For example, I'll provide links to my current scenario.

 

I currently have 4 Code v3/b keyboards that I use to automate a number of processes over many projects, they work well for that however they have a 32-keystroke limit not counting the delay timers. This makes systems boot-ups a time consuming task as my technicians have to sit at the stations mashing F2/F12 for (currently) Dell systems.

 

I currently use different iterations of this device, a USB synchronizer. Link Here I have 4/8 and soon to be 16/32 port versions of this to scale up my operations.

 

My keyboards work well with the synchronizers, but my macropad does not register at all. I did find a forum that seems to have some people testing out differing products, its a trial and error approach, I'll see if I cant get a link. Here

 

Basically I would like for my technicians to be able to power on the systems while the Autofiring devices continually hits the desired key.

 

Long story long, does not need to be a keyboard. As long as it has Autofire potential or can continually hit desired keys for 1-2 minutes as we cycle our production.

 

Currently owned macropad that failed to function with my USB synchronizers Link Here

 

 

 

On another note, I have been considering BADUSB as well, but need more time to look into how that functions

Link to comment
Share on other sites

After a little more digging, it looks like AutoFire explicitly isnt sold as a feature for keyboards. 

 

That being said it looks like this can be done via QMK, so I may try a full size 10-key DIY kit just to get some experience with the soldering iron and learn how I can utilize QMK for my work needs.

Link to comment
Share on other sites

maybe one of the system 76 launch keyboards?  I believe it's foss and you can set up macros.  I don't have one yet.  I might order next month depending on my cash flow.  but would any programmable keyboard macro or via/qmk be able to "turbo".  I bet the steam controller can do a turbo function with any key.  that controller can do a lot and also has a usb receiver. 

Link to comment
Share on other sites

It looks like those keyboards also have QMK so in theory it should be able to work but I am building a numpad first in the hopes that I can have a low-cost "principle use case" before I start looking at 300 USD boards. 

 

I have been wanting an 1800 layout for some time so I may (if this works out) finally pick one up.

Link to comment
Share on other sites

Posting a link I got from the developer/manufacturer of the tidbit. Should give me some illumination for how to configure the device to my needs.

 

Hey hey! Glad you have you here :D
All of these things are possible. I'll run through them one by one -- it won't be the most detailed but should give you enough to get rolling. All will require modifying the firmware, which is quite easy to jump into. The QMK discord server in particular is a great resource with lots of folks who can help if you hit any snags.

 

 

OLED: You can definitely show what layer is active. Take a look at the OLED driver documentation: https://github.com/qmk/qmk_firmware/blob/master/docs/feature_oled_driver.md The SNAP OLED keymap also shows exactly how to do this if you need a concrete reference:  Here

 

 

Encoder: The QMK docs are a good place to start: Here

The TIDBIT actually handles encoder events with a virtual key in the matrix, but that's going to be changing. I'd recommend overriding the encoder behavior with `encoder_update_user()` in your keymap.c that returns false -- that will ensure it's not handled by the matrix scan as well. You'll need to know what HID keycodes your KVM uses, but as long as they're documented you can send any valid 16-bit keycode.

 

Autofire: This one requires a bit more finesse, but can be done in almost the same way as the timer macro example in the QMK docs: Here Basically, set a boolean variable true when the key in question is pressed inside `process_record_user()`, then `tap_code(KC_F12)` inside `matrix_scan_user()` as long as that variable is set.

 

I'm not sure exactly what you're looking to integrate with, but the TRRS is bi-directional UART serial + power/ground, so you can essentially integrate with anything! It is limited to one point-to-point connection, though. Here's the serial code, for reference: https://github.com/qmk/qmk_firmware/blob/master/keyboards/nullbitsco/common/remote_kb.c

 


Hopefully that gets you started! I think the TIDBIT will be a great improvement to your workflow. It's just about infinitely customizable :D

 

 

Should give me some good reading material for tomorrow :D 

Link to comment
Share on other sites

  • 3 weeks later...

I can confirm that QMK is capable of AutoFire and have it functioning now. An added bonus would be if its possible to give this thing an independent power supply and have it send keyboard commands without a system being powered on, that will come after I get more functions programmed in. 

 

The below would be code that you inject into your keymap file.

 

#define SPAM_DELAY 50  // 50 milliseconds between spams
bool spam_active = false;
uint32_t spam_timer = 0;

// Place the above near the beginning of the keymap

enum custom_keycodes {
    F2TR = SAFE_RANGE, // Create a keycode to make your toggle initialize
};

bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  switch (keycode) {
    case F2TR:  // When you press custom SPAM keycode
      if (record->event.pressed) {
        spam_active = !spam_active;  // Toggle spamming
        spam_timer = timer_read32(); // Reset spam timer
      }
      break;
  }
  return true;
}


void matrix_scan_user(void){
  if (spam_active) {  
    // Check if it's been SPAM_DELAY milliseconds since the last spam
    if (timer_elapsed32(spam_timer) > SPAM_DELAY) {
      tap_code(KC_P2);           // Send an F2 keystroke
      spam_timer = timer_read32();  // Reset spam timer
    }
  }
}

 

My understanding of this stuff is very limited, essentially you create boolean (if statement) set to false then matrix scan user scans the keyboard waiting for the case to be initialized with the keystroke. Once it detects the keystroke it will then repeat the designated key, in this case KC_P2 or "2" until it detects that same keypress. In this case I used tap_code but you can also have it repeat strings via SEND_STRING.

I cant take credit for the code above, a user on reddit was kind enough to share it in a previous post. Sharing here for posterity :) 

I was also able to get multiple boolean keys to work as well so for my use case, I needed F2 and F12 to enter the BIOS or one time boot of Dell systems.

 

  • Thanks 1
Link to comment
Share on other sites

  • 3 weeks later...

This is great. I found you through your reddit posts.


Do you by chance have your working version on github or somewhere else? I'm trying to build an autofire Enter button with QMK but I'm new to it, and I'm DIYing it with a pro micro. What you included in the comments does help, just wondered if you had a finished version - I'm still getting my footing with QMK and would love to be able to look through the whole keyboard folder. Thanks!

  • Like 1
Link to comment
Share on other sites

On 2/2/2023 at 7:48 PM, KatieTheTall said:

This is great. I found you through your reddit posts.


Do you by chance have your working version on github or somewhere else? I'm trying to build an autofire Enter button with QMK but I'm new to it, and I'm DIYing it with a pro micro. What you included in the comments does help, just wondered if you had a finished version - I'm still getting my footing with QMK and would love to be able to look through the whole keyboard folder. Thanks!

Just saw your post on Reddit, sorry I didnt see it earlier! 

 

I wasnt able to get multiple booleans working if that is what you are seeking. Though if all you need is to repeat the Enter key, that is simple enough with the template above. 

 

void matrix_scan_user(void){
  if (spam_active) {  
    // Check if it's been SPAM_DELAY milliseconds since the last spam
    if (timer_elapsed32(spam_timer) > SPAM_DELAY) {
      tap_code(KC_P2);           // Send an F2 keystroke
      spam_timer = timer_read32();  // Reset spam timer
    }
  }
}

 

In the segment above, you just need to replace the "KC_P2" with the keycode for the Enter key. Keycodes can be found on the QMK Docs here but its "KC_ENT" or "KC_ENTER".

 

bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  switch (keycode) {
    case F2TR:  // When you press custom SPAM keycode
      if (record->event.pressed) {
        spam_active = !spam_active;  // Toggle spamming
        spam_timer = timer_read32(); // Reset spam timer
      }
      break;
  }
  return true;
}

 

In the above I gave it a custom keycode which you can see next to the case "F2TR". People advise against that sort of thing but its more of a mental placeholder for me. F2TR being shorthand for F2 Toggle Repeat.

 

Then you place that key where you want the toggle to be in the keymap. Just for example, below is one layer in my keymap. 

 

const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
    [_SRCE] = LAYOUT(
                            TO(1), TO(1), KC_PENT,
    KC_VOLU, KC_VOLD, F2TR, KC_F12,   KC_P8,   KC_PENT,
    KC_MPRV, KC_MNXT, KC_P4, KC_P5,   KC_P6,   KC_PENT,
    KC_LEFT, KC_RGHT, KC_P1, KC_P2,   KC_P3,   KC_PENT, 
    KC_TRNS, KC_TRNS, KC_P0, KC_P0,   KC_PDOT, KC_PENT  
    ),

 

F2TR is the keypress most people associate with "7" on the numpad

 

Welcome to the Forum! 

  • Thumb Up 1
Link to comment
Share on other sites

  • 3 weeks later...
  • Reciever changed the title to HowTo- QMK AutoFire (Toggle-able repeating keys)

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. Terms of Use