Keyboard Quantizer for mouse

Posted on Jul 28, 2021


I use a set of a keyboard, a trackball, and a monitor for Windows and Mac computers. But, one of the issues in this setup is that the trackball behaves differently on Windows and Mac. To be more specific, the issue will be like these:

To fix this issue, I have introduced Keyboard Quantizer by sekigon. The bottom line is it works perfectly!

Keyboard Quantizer

Keyboard Quantizer is a hardware adaptor to transform keyboard or mouse input as you wish. The keyboard with QMK firmware does not need this, but regular keyboards or mouses can benefit from this adaptor.

This might be originally designed for keyboards, and there was no sample firmware for mouse when I bought months ago. But right now, some sample firmwares for mouses are available in the creator’s GitHub repository, and one of them is VIA/Remap ready.

You can buy one here if you are lucky. The creator said that the supply was not stable due to the chip scarcity.

Implemetation

The functions I wanted to implement were:

  1. introducing a layer for Mac that enables to customize the buttons
  2. assigning the following functions to the buttons
    • button #3: toggle layers
    • button #4: Command + [ (and activate gestures)
    • button #5: Command + ]
    • button #6: Ctrl + LEFT
    • button #7: Ctrl + L
    • button #8: Ctrl + RIGHT
  3. reversing the wheel direction for Mac

It took some time, but I managed to realize these functions.

You can find my implementatio here. The code for 1 and 2 is like this.

const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
    [0] = {{KC_BTN1, KC_BTN2, TG(1),   KC_BTN4, KC_BTN5, KC_NO, KC_NO,      KC_NO        }},
    [1] = {{_______, _______, _______, GEST,    LGUI(KC_RBRC),  LCTL(KC_LEFT), LCTL(KC_L), LCTL(KC_RGHT)}},
};

For the 3rd one, I implemented like this.

void mouse_report_hook(mouse_parse_result_t const* report) {

    // (partially omitted)

    mouse.x += report->x;
    mouse.y += report->y;
    mouse.h += report->h;

    if (IS_LAYER_ON(1)) {
        mouse.v -= report->v;
    } else {
        mouse.v += report->v;
    }

    pointing_device_set_report(mouse);

}

Implementing Gesture!

Implementing gestures was not in my original plan, but I tried.

The functions I implemented were like these:

The actual code is like this. Very simple.

static void gesture_start(void) {
    dprint("Gesture start\n");
    gesture_wait   = true;
    gesture_move_x = 0;
    gesture_move_y = 0;
}

bool process_record_user(uint16_t keycode, keyrecord_t* record) {
    switch (keycode) {

	   // (partially omitted)

	    case GEST:
            if (record -> event.pressed) {
                gesture_start();
            } else if (gesture_wait) {
                tap_code16(LGUI(KC_LBRC));
                gesture_wait = false;
	        }
            break;

       // (partially omitted)
}
void process_gesture(void) {

    recognize_gesture(gesture_move_x, gesture_move_y);

    switch (gesture_id) {
        case GESTURE_UP:
	    tap_code16(LCTL(KC_UP));
	    gesture_wait = false;
	    break;
	case GESTURE_DOWN:
	    tap_code16(LCTL(KC_L));
	    gesture_wait = false;
	    break;
	case GESTURE_LEFT:
	    tap_code16(LCTL(KC_LEFT));
	    gesture_wait = false;
	    break;
	case GESTURE_RIGHT:
	    tap_code16(LCTL(KC_RGHT));
	    gesture_wait = false;
	    break;
	case GESTURE_NONE:
	    break;
	default:
	    break;
    }
}

void mouse_report_hook(mouse_parse_result_t const* report) {

    // (partially omitted)

    // Save movement to recognize gesture
    //
    if (gesture_wait) {
        gesture_move_x += report->x;
        gesture_move_y += report->y;
	    process_gesture();
    }
}

Impression

As I mentioned earlier, the adaptor works pretty good. Now I can quickly implement functions on my trackball mouse.

And I just uninstalled the annoying driver. Buy-buy!

I want to mention that some mouses did not work with this adaptor. I tested three mouses and found out that one of them did not work well. Here is the list.

ManufacturerProductResult
ELECOMM-DT1DRGood
ELECOMM-DT2DRNot good. Rattling cursor.
LogicoolM350Good

I highly recommend this adaptor if you want to modify the functions of your keyboard or mouse. I am planning to buy one more…


comments powered by Disqus