aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJavier <dev.git@javispedro.com>2026-03-01 18:00:45 +0100
committerJavier <dev.git@javispedro.com>2026-03-01 18:00:45 +0100
commit0c2b1b6a5d80f2dd5f03e73efa52d6a921f1f98c (patch)
treebdbb136ca398ed75d3601725331086bbd92eeb9c
parent58fe8e22096863f86b2916dd388401f7afc1d26c (diff)
downloadvbados-master.tar.gz
vbados-master.zip
add initial support for emulating left/right arrow keys from horizontal wheelHEADmaster
-rw-r--r--mousetsr.c12
-rw-r--r--mousetsr.h9
-rw-r--r--mousmain.c56
3 files changed, 61 insertions, 16 deletions
diff --git a/mousetsr.c b/mousetsr.c
index 2913efd..85230cc 100644
--- a/mousetsr.c
+++ b/mousetsr.c
@@ -661,15 +661,15 @@ static void handle_mouse_event(uint16_t buttons, bool absolute, int x, int y, ch
#if USE_WHEEL
if (data.num_wheels && z) {
- if (wheeln == 0 && !data.usewheelapi && (data.wheel_up_key || data.wheel_down_key)) {
- // Emulate keystrokes on (vertical) wheel movement
- if (z < 0 && data.wheel_up_key) {
+ if (!data.usewheelapi && (data.wheel_key[wheeln][WHEEL_DIR_UP] || data.wheel_key[wheeln][WHEEL_DIR_DOWN])) {
+ // Emulate keystrokes on wheel movement
+ if (z < 0 && data.wheel_key[wheeln][WHEEL_DIR_UP]) {
for (; z < 0; z++) {
- int16_store_keystroke(data.wheel_up_key, 0);
+ int16_store_keystroke(data.wheel_key[wheeln][WHEEL_DIR_UP], 0);
}
- } else if (z > 0 && data.wheel_down_key) {
+ } else if (z > 0 && data.wheel_key[wheeln][WHEEL_DIR_DOWN]) {
for (; z > 0; z--) {
- int16_store_keystroke(data.wheel_down_key, 0);
+ int16_store_keystroke(data.wheel_key[wheeln][WHEEL_DIR_DOWN], 0);
}
}
} else {
diff --git a/mousetsr.h b/mousetsr.h
index 05b2f24..f33dc11 100644
--- a/mousetsr.h
+++ b/mousetsr.h
@@ -90,6 +90,11 @@ struct point {
int16_t x, y;
};
+enum {
+ WHEEL_DIR_UP,
+ WHEEL_DIR_DOWN
+};
+
typedef struct tsrdata {
// TSR installation data
/** Previous int33 ISR, storing it for uninstall. */
@@ -101,8 +106,8 @@ typedef struct tsrdata {
#if USE_WHEEL
/** Whether to enable & use wheel mouse. */
bool usewheel;
- /** Key (scancode) to generate on wheel scroll up/down, or 0 for none. */
- uint8_t wheel_up_key, wheel_down_key;
+ /** Scancode to generate on wheel N scroll up [N][0] or down [N][1]. 0 for none. */
+ uint8_t wheel_key[MAX_WHEELS][2];
#endif
// Video settings
diff --git a/mousmain.c b/mousmain.c
index 80ea1fb..07ba05a 100644
--- a/mousmain.c
+++ b/mousmain.c
@@ -71,6 +71,12 @@ static int set_wheel(LPTSRDATA data, bool enable)
return 0;
}
+static void set_wheel_keys(LPTSRDATA data, int wheel, uint8_t scancode_up, uint8_t scancode_down)
+{
+ data->wheel_key[wheel][WHEEL_DIR_UP] = scancode_up;
+ data->wheel_key[wheel][WHEEL_DIR_DOWN] = scancode_down;
+}
+
static int set_wheel_key(LPTSRDATA data, const char *keyname)
{
if (!data->usewheel) {
@@ -79,12 +85,10 @@ static int set_wheel_key(LPTSRDATA data, const char *keyname)
}
if (keyname) {
if (stricmp(keyname, "updn") == 0) {
- data->wheel_up_key = 0x48;
- data->wheel_down_key = 0x50;
+ set_wheel_keys(data, 0, 0x48, 0x50);
printf(_(1, 4, "Generate Up Arrow / Down Arrow key presses on wheel movement\n"));
} else if (stricmp(keyname, "pageupdn") == 0) {
- data->wheel_up_key = 0x49;
- data->wheel_down_key = 0x51;
+ set_wheel_keys(data, 0, 0x49, 0x51);
printf(_(1, 5, "Generate PageUp / PageDown key presses on wheel movement\n"));
} else {
fprintf(stderr, _(3, 2, "Unknown key '%s'\n"), keyname);
@@ -92,8 +96,28 @@ static int set_wheel_key(LPTSRDATA data, const char *keyname)
}
} else {
printf(_(1, 6, "Disabling wheel keystroke generation\n"));
- data->wheel_up_key = 0;
- data->wheel_down_key = 0;
+ set_wheel_keys(data, 0, 0, 0);
+ }
+ return EXIT_SUCCESS;
+}
+
+static int set_hwheel_key(LPTSRDATA data, const char *keyname)
+{
+ if (!data->usewheel) {
+ fprintf(stderr, _(3, 1, "Wheel not detected or support not enabled\n"));
+ return EXIT_FAILURE;
+ }
+ if (keyname) {
+ if (stricmp(keyname, "lr") == 0) {
+ set_wheel_keys(data, 1, 0x4B, 0x4D);
+ printf(_(1, 4, "Generate Up Arrow / Down Arrow key presses on wheel movement\n"));
+ } else {
+ fprintf(stderr, _(3, 2, "Unknown key '%s'\n"), keyname);
+ return EXIT_FAILURE;
+ }
+ } else {
+ printf(_(1, 6, "Disabling wheel keystroke generation\n"));
+ set_wheel_keys(data, 1, 0, 0);
}
return EXIT_SUCCESS;
}
@@ -267,8 +291,6 @@ static int configure_driver(LPTSRDATA data)
#if USE_WHEEL
// Let's utilize the wheel by default
data->usewheel = true;
- data->wheel_up_key = 0;
- data->wheel_down_key = 0;
detect_wheel(data); // Prints message if wheel found
#endif
@@ -536,6 +558,24 @@ int main(int argc, const char *argv[])
} else {
return set_wheel_key(data, 0);
}
+ } else if (stricmp(argv[argi], "hwheelkey") == 0) {
+ bool enable = true;
+ const char *key = 0;
+
+ if (!data) return driver_not_found();
+
+ argi++;
+ if (argi < argc) {
+ if (is_false(argv[argi])) enable = false;
+ else key = argv[argi];
+ }
+
+ if (enable) {
+ if (!key) return arg_required("hwheelkey");
+ return set_hwheel_key(data, key);
+ } else {
+ return set_hwheel_key(data, 0);
+ }
#endif
#if USE_INTEGRATION
} else if (stricmp(argv[argi], "integ") == 0) {