Add Mousekey parameters and accel keys.
This commit is contained in:
parent
66b62306bc
commit
d96d15b555
@ -29,10 +29,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
#define IS_MOD(code) (KC_LCTRL <= (code) && (code) <= KC_RGUI)
|
#define IS_MOD(code) (KC_LCTRL <= (code) && (code) <= KC_RGUI)
|
||||||
|
|
||||||
#define IS_FN(code) (KC_FN0 <= (code) && (code) <= KC_FN7)
|
#define IS_FN(code) (KC_FN0 <= (code) && (code) <= KC_FN7)
|
||||||
#define IS_MOUSEKEY(code) (KC_MS_UP <= (code) && (code) <= KC_MS_WH_RIGHT)
|
#define IS_MOUSEKEY(code) (KC_MS_UP <= (code) && (code) <= KC_MS_ACCEL2)
|
||||||
#define IS_MOUSEKEY_MOVE(code) (KC_MS_UP <= (code) && (code) <= KC_MS_RIGHT)
|
#define IS_MOUSEKEY_MOVE(code) (KC_MS_UP <= (code) && (code) <= KC_MS_RIGHT)
|
||||||
#define IS_MOUSEKEY_BUTTON(code) (KC_MS_BTN1 <= (code) && (code) <= KC_MS_BTN5)
|
#define IS_MOUSEKEY_BUTTON(code) (KC_MS_BTN1 <= (code) && (code) <= KC_MS_BTN5)
|
||||||
#define IS_MOUSEKEY_WHEEL(code) (KC_MS_WH_UP <= (code) && (code) <= KC_MS_WH_RIGHT)
|
#define IS_MOUSEKEY_WHEEL(code) (KC_MS_WH_UP <= (code) && (code) <= KC_MS_WH_RIGHT)
|
||||||
|
#define IS_MOUSEKEY_ACCEL(code) (KC_MS_ACCEL0 <= (code) && (code) <= KC_MS_ACCEL2)
|
||||||
|
|
||||||
#define IS_SPECIAL(code) ((0xB0 <= (code) && (code) <= 0xDF) || (0xE8 <= (code) && (code) <= 0xFF))
|
#define IS_SPECIAL(code) ((0xB0 <= (code) && (code) <= 0xDF) || (0xE8 <= (code) && (code) <= 0xFF))
|
||||||
#define IS_CONSUMER(code) (KC_MUTE <= (code) && (code) <= KC_WFAV)
|
#define IS_CONSUMER(code) (KC_MUTE <= (code) && (code) <= KC_WFAV)
|
||||||
@ -120,6 +121,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
#define KC_WH_D KC_MS_WH_DOWN
|
#define KC_WH_D KC_MS_WH_DOWN
|
||||||
#define KC_WH_L KC_MS_WH_LEFT
|
#define KC_WH_L KC_MS_WH_LEFT
|
||||||
#define KC_WH_R KC_MS_WH_RIGHT
|
#define KC_WH_R KC_MS_WH_RIGHT
|
||||||
|
#define KC_ACL0 KC_MS_ACCEL0
|
||||||
|
#define KC_ACL1 KC_MS_ACCEL1
|
||||||
|
#define KC_ACL2 KC_MS_ACCEL2
|
||||||
/* Sytem Control */
|
/* Sytem Control */
|
||||||
#define KC_PWR KC_SYSTEM_POWER
|
#define KC_PWR KC_SYSTEM_POWER
|
||||||
#define KC_SLEP KC_SYSTEM_SLEEP
|
#define KC_SLEP KC_SYSTEM_SLEEP
|
||||||
@ -429,13 +433,16 @@ enum internal_special_keycodes {
|
|||||||
KC_MS_BTN2,
|
KC_MS_BTN2,
|
||||||
KC_MS_BTN3,
|
KC_MS_BTN3,
|
||||||
KC_MS_BTN4,
|
KC_MS_BTN4,
|
||||||
KC_MS_BTN5,
|
KC_MS_BTN5, /* 0xF8 */
|
||||||
/* Mousekey wheel */
|
/* Mousekey wheel */
|
||||||
KC_MS_WH_UP,
|
KC_MS_WH_UP,
|
||||||
KC_MS_WH_DOWN,
|
KC_MS_WH_DOWN,
|
||||||
KC_MS_WH_LEFT,
|
KC_MS_WH_LEFT,
|
||||||
KC_MS_WH_RIGHT, /* 0xFC */
|
KC_MS_WH_RIGHT, /* 0xFC */
|
||||||
/* 0xFD-FF vacant for future use */
|
/* Mousekey accel */
|
||||||
|
KC_MS_ACCEL0,
|
||||||
|
KC_MS_ACCEL1,
|
||||||
|
KC_MS_ACCEL2 /* 0xFF */
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* KEYCODE_H */
|
#endif /* KEYCODE_H */
|
||||||
|
@ -27,40 +27,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
|
|
||||||
|
|
||||||
static uint8_t mousekey_repeat = 0;
|
static uint8_t mousekey_repeat = 0;
|
||||||
|
static uint8_t mousekey_accel = 0;
|
||||||
|
|
||||||
static void mousekey_debug(void);
|
static void mousekey_debug(void);
|
||||||
|
|
||||||
|
|
||||||
/* max value on report descriptor */
|
|
||||||
#define MOUSEKEY_MOVE_MAX 127
|
|
||||||
#define MOUSEKEY_WHEEL_MAX 15
|
|
||||||
|
|
||||||
#ifndef MOUSEKEY_MOVE_DELTA
|
|
||||||
#define MOUSEKEY_MOVE_DELTA 5
|
|
||||||
#endif
|
|
||||||
#ifndef MOUSEKEY_WHEEL_DELTA
|
|
||||||
#define MOUSEKEY_WHEEL_DELTA 1
|
|
||||||
#endif
|
|
||||||
#ifndef MOUSEKEY_DELAY
|
|
||||||
#define MOUSEKEY_DELAY 300
|
|
||||||
#endif
|
|
||||||
#ifndef MOUSEKEY_INTERVAL
|
|
||||||
#define MOUSEKEY_INTERVAL 50
|
|
||||||
#endif
|
|
||||||
#ifndef MOUSEKEY_MAX_SPEED
|
|
||||||
#define MOUSEKEY_MAX_SPEED 10
|
|
||||||
#endif
|
|
||||||
#ifndef MOUSEKEY_TIME_TO_MAX
|
|
||||||
#define MOUSEKEY_TIME_TO_MAX 20
|
|
||||||
#endif
|
|
||||||
#ifndef MOUSEKEY_WHEEL_MAX_SPEED
|
|
||||||
#define MOUSEKEY_WHEEL_MAX_SPEED 8
|
|
||||||
#endif
|
|
||||||
#ifndef MOUSEKEY_WHEEL_TIME_TO_MAX
|
|
||||||
#define MOUSEKEY_WHEEL_TIME_TO_MAX 40
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Mouse keys acceleration algorithm
|
* Mouse keys acceleration algorithm
|
||||||
* http://en.wikipedia.org/wiki/Mouse_keys
|
* http://en.wikipedia.org/wiki/Mouse_keys
|
||||||
@ -68,18 +39,18 @@ static void mousekey_debug(void);
|
|||||||
* speed = delta * max_speed * (repeat / time_to_max)**((1000+curve)/1000)
|
* speed = delta * max_speed * (repeat / time_to_max)**((1000+curve)/1000)
|
||||||
*/
|
*/
|
||||||
/* milliseconds between the initial key press and first repeated motion event (0-2550) */
|
/* milliseconds between the initial key press and first repeated motion event (0-2550) */
|
||||||
static uint8_t mk_delay = MOUSEKEY_DELAY/10;
|
uint8_t mk_delay = MOUSEKEY_DELAY/10;
|
||||||
/* milliseconds between repeated motion events (0-255) */
|
/* milliseconds between repeated motion events (0-255) */
|
||||||
static uint8_t mk_interval = MOUSEKEY_INTERVAL;
|
uint8_t mk_interval = MOUSEKEY_INTERVAL;
|
||||||
/* steady speed (in action_delta units) applied each event (0-255) */
|
/* steady speed (in action_delta units) applied each event (0-255) */
|
||||||
static uint8_t mk_max_speed = MOUSEKEY_MAX_SPEED;
|
uint8_t mk_max_speed = MOUSEKEY_MAX_SPEED;
|
||||||
/* number of events (count) accelerating to steady speed (0-255) */
|
/* number of events (count) accelerating to steady speed (0-255) */
|
||||||
static uint8_t mk_time_to_max = MOUSEKEY_TIME_TO_MAX;
|
uint8_t mk_time_to_max = MOUSEKEY_TIME_TO_MAX;
|
||||||
/* ramp used to reach maximum pointer speed (NOT SUPPORTED) */
|
/* ramp used to reach maximum pointer speed (NOT SUPPORTED) */
|
||||||
//static int8_t mk_curve = 0;
|
//int8_t mk_curve = 0;
|
||||||
|
/* wheel params */
|
||||||
static uint8_t mk_wheel_max_speed = MOUSEKEY_WHEEL_MAX_SPEED;
|
uint8_t mk_wheel_max_speed = MOUSEKEY_WHEEL_MAX_SPEED;
|
||||||
static uint8_t mk_wheel_time_to_max = MOUSEKEY_WHEEL_TIME_TO_MAX;
|
uint8_t mk_wheel_time_to_max = MOUSEKEY_WHEEL_TIME_TO_MAX;
|
||||||
|
|
||||||
|
|
||||||
static uint16_t last_timer = 0;
|
static uint16_t last_timer = 0;
|
||||||
@ -88,25 +59,39 @@ static uint16_t last_timer = 0;
|
|||||||
static uint8_t move_unit(void)
|
static uint8_t move_unit(void)
|
||||||
{
|
{
|
||||||
uint16_t unit;
|
uint16_t unit;
|
||||||
if (mousekey_repeat > mk_time_to_max) {
|
if (mousekey_accel & (1<<0)) {
|
||||||
|
unit = (MOUSEKEY_MOVE_DELTA * mk_max_speed)/4;
|
||||||
|
} else if (mousekey_accel & (1<<1)) {
|
||||||
|
unit = (MOUSEKEY_MOVE_DELTA * mk_max_speed)/2;
|
||||||
|
} else if (mousekey_accel & (1<<2)) {
|
||||||
|
unit = (MOUSEKEY_MOVE_DELTA * mk_max_speed);
|
||||||
|
} else if (mousekey_repeat == 0) {
|
||||||
|
unit = MOUSEKEY_MOVE_DELTA;
|
||||||
|
} else if (mousekey_repeat >= mk_time_to_max) {
|
||||||
unit = MOUSEKEY_MOVE_DELTA * mk_max_speed;
|
unit = MOUSEKEY_MOVE_DELTA * mk_max_speed;
|
||||||
} else {
|
} else {
|
||||||
unit = (MOUSEKEY_MOVE_DELTA * mk_max_speed * mousekey_repeat) / mk_time_to_max;
|
unit = (MOUSEKEY_MOVE_DELTA * mk_max_speed * mousekey_repeat) / mk_time_to_max;
|
||||||
}
|
}
|
||||||
if (unit == 0) return 1;
|
return (unit > MOUSEKEY_MOVE_MAX ? MOUSEKEY_MOVE_MAX : (unit == 0 ? 1 : unit));
|
||||||
return (unit > MOUSEKEY_MOVE_MAX ? MOUSEKEY_MOVE_MAX : unit);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint8_t wheel_unit(void)
|
static uint8_t wheel_unit(void)
|
||||||
{
|
{
|
||||||
uint16_t unit;
|
uint16_t unit;
|
||||||
if (mousekey_repeat > mk_time_to_max) {
|
if (mousekey_accel & (1<<0)) {
|
||||||
|
unit = (MOUSEKEY_WHEEL_DELTA * mk_wheel_max_speed)/4;
|
||||||
|
} else if (mousekey_accel & (1<<1)) {
|
||||||
|
unit = (MOUSEKEY_WHEEL_DELTA * mk_wheel_max_speed)/2;
|
||||||
|
} else if (mousekey_accel & (1<<2)) {
|
||||||
|
unit = (MOUSEKEY_WHEEL_DELTA * mk_wheel_max_speed);
|
||||||
|
} else if (mousekey_repeat == 0) {
|
||||||
|
unit = MOUSEKEY_WHEEL_DELTA;
|
||||||
|
} else if (mousekey_repeat >= mk_time_to_max) {
|
||||||
unit = MOUSEKEY_WHEEL_DELTA * mk_wheel_max_speed;
|
unit = MOUSEKEY_WHEEL_DELTA * mk_wheel_max_speed;
|
||||||
} else {
|
} else {
|
||||||
unit = (MOUSEKEY_WHEEL_DELTA * mk_wheel_max_speed * mousekey_repeat) / mk_wheel_time_to_max;
|
unit = (MOUSEKEY_WHEEL_DELTA * mk_wheel_max_speed * mousekey_repeat) / mk_wheel_time_to_max;
|
||||||
}
|
}
|
||||||
if (unit == 0) return 1;
|
return (unit > MOUSEKEY_WHEEL_MAX ? MOUSEKEY_WHEEL_MAX : (unit == 0 ? 1 : unit));
|
||||||
return (unit > MOUSEKEY_WHEEL_MAX ? MOUSEKEY_WHEEL_MAX : unit);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void mousekey_task(void)
|
void mousekey_task(void)
|
||||||
@ -126,6 +111,7 @@ void mousekey_task(void)
|
|||||||
if (mouse_report.y > 0) mouse_report.y = move_unit();
|
if (mouse_report.y > 0) mouse_report.y = move_unit();
|
||||||
if (mouse_report.y < 0) mouse_report.y = move_unit() * -1;
|
if (mouse_report.y < 0) mouse_report.y = move_unit() * -1;
|
||||||
|
|
||||||
|
/* diagonal move [1/sqrt(2) = 0.7] */
|
||||||
if (mouse_report.x && mouse_report.y) {
|
if (mouse_report.x && mouse_report.y) {
|
||||||
mouse_report.x *= 0.7;
|
mouse_report.x *= 0.7;
|
||||||
mouse_report.y *= 0.7;
|
mouse_report.y *= 0.7;
|
||||||
@ -141,19 +127,22 @@ void mousekey_task(void)
|
|||||||
|
|
||||||
void mousekey_on(uint8_t code)
|
void mousekey_on(uint8_t code)
|
||||||
{
|
{
|
||||||
if (code == KC_MS_UP) mouse_report.y = MOUSEKEY_MOVE_DELTA * -1;
|
if (code == KC_MS_UP) mouse_report.y = move_unit() * -1;
|
||||||
else if (code == KC_MS_DOWN) mouse_report.y = MOUSEKEY_MOVE_DELTA;
|
else if (code == KC_MS_DOWN) mouse_report.y = move_unit();
|
||||||
else if (code == KC_MS_LEFT) mouse_report.x = MOUSEKEY_MOVE_DELTA * -1;
|
else if (code == KC_MS_LEFT) mouse_report.x = move_unit() * -1;
|
||||||
else if (code == KC_MS_RIGHT) mouse_report.x = MOUSEKEY_MOVE_DELTA;
|
else if (code == KC_MS_RIGHT) mouse_report.x = move_unit();
|
||||||
else if (code == KC_MS_WH_UP) mouse_report.v = MOUSEKEY_WHEEL_DELTA;
|
else if (code == KC_MS_WH_UP) mouse_report.v = wheel_unit();
|
||||||
else if (code == KC_MS_WH_DOWN) mouse_report.v = MOUSEKEY_WHEEL_DELTA * -1;
|
else if (code == KC_MS_WH_DOWN) mouse_report.v = wheel_unit() * -1;
|
||||||
else if (code == KC_MS_WH_LEFT) mouse_report.h = MOUSEKEY_WHEEL_DELTA * -1;
|
else if (code == KC_MS_WH_LEFT) mouse_report.h = wheel_unit() * -1;
|
||||||
else if (code == KC_MS_WH_RIGHT) mouse_report.h = MOUSEKEY_WHEEL_DELTA;
|
else if (code == KC_MS_WH_RIGHT) mouse_report.h = wheel_unit();
|
||||||
else if (code == KC_MS_BTN1) mouse_report.buttons |= MOUSE_BTN1;
|
else if (code == KC_MS_BTN1) mouse_report.buttons |= MOUSE_BTN1;
|
||||||
else if (code == KC_MS_BTN2) mouse_report.buttons |= MOUSE_BTN2;
|
else if (code == KC_MS_BTN2) mouse_report.buttons |= MOUSE_BTN2;
|
||||||
else if (code == KC_MS_BTN3) mouse_report.buttons |= MOUSE_BTN3;
|
else if (code == KC_MS_BTN3) mouse_report.buttons |= MOUSE_BTN3;
|
||||||
else if (code == KC_MS_BTN4) mouse_report.buttons |= MOUSE_BTN4;
|
else if (code == KC_MS_BTN4) mouse_report.buttons |= MOUSE_BTN4;
|
||||||
else if (code == KC_MS_BTN5) mouse_report.buttons |= MOUSE_BTN5;
|
else if (code == KC_MS_BTN5) mouse_report.buttons |= MOUSE_BTN5;
|
||||||
|
else if (code == KC_MS_ACCEL0) mousekey_accel |= (1<<0);
|
||||||
|
else if (code == KC_MS_ACCEL1) mousekey_accel |= (1<<1);
|
||||||
|
else if (code == KC_MS_ACCEL2) mousekey_accel |= (1<<2);
|
||||||
}
|
}
|
||||||
|
|
||||||
void mousekey_off(uint8_t code)
|
void mousekey_off(uint8_t code)
|
||||||
@ -171,6 +160,9 @@ void mousekey_off(uint8_t code)
|
|||||||
else if (code == KC_MS_BTN3) mouse_report.buttons &= ~MOUSE_BTN3;
|
else if (code == KC_MS_BTN3) mouse_report.buttons &= ~MOUSE_BTN3;
|
||||||
else if (code == KC_MS_BTN4) mouse_report.buttons &= ~MOUSE_BTN4;
|
else if (code == KC_MS_BTN4) mouse_report.buttons &= ~MOUSE_BTN4;
|
||||||
else if (code == KC_MS_BTN5) mouse_report.buttons &= ~MOUSE_BTN5;
|
else if (code == KC_MS_BTN5) mouse_report.buttons &= ~MOUSE_BTN5;
|
||||||
|
else if (code == KC_MS_ACCEL0) mousekey_accel &= ~(1<<0);
|
||||||
|
else if (code == KC_MS_ACCEL1) mousekey_accel &= ~(1<<1);
|
||||||
|
else if (code == KC_MS_ACCEL2) mousekey_accel &= ~(1<<2);
|
||||||
|
|
||||||
if (mouse_report.x == 0 && mouse_report.y == 0 && mouse_report.v == 0 && mouse_report.h == 0)
|
if (mouse_report.x == 0 && mouse_report.y == 0 && mouse_report.v == 0 && mouse_report.h == 0)
|
||||||
mousekey_repeat = 0;
|
mousekey_repeat = 0;
|
||||||
@ -186,17 +178,19 @@ void mousekey_send(void)
|
|||||||
void mousekey_clear(void)
|
void mousekey_clear(void)
|
||||||
{
|
{
|
||||||
mouse_report = (report_mouse_t){};
|
mouse_report = (report_mouse_t){};
|
||||||
|
mousekey_repeat = 0;
|
||||||
|
mousekey_accel = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void mousekey_debug(void)
|
static void mousekey_debug(void)
|
||||||
{
|
{
|
||||||
if (!debug_mouse) return;
|
if (!debug_mouse) return;
|
||||||
print("mousekey [btn|x y v h]rep: [");
|
print("mousekey [btn|x y v h](rep/acl): [");
|
||||||
phex(mouse_report.buttons); print("|");
|
phex(mouse_report.buttons); print("|");
|
||||||
phex(mouse_report.x); print(" ");
|
phex(mouse_report.x); print(" ");
|
||||||
phex(mouse_report.y); print(" ");
|
phex(mouse_report.y); print(" ");
|
||||||
phex(mouse_report.v); print(" ");
|
phex(mouse_report.v); print(" ");
|
||||||
phex(mouse_report.h); print("]");
|
phex(mouse_report.h); print("](");
|
||||||
phex(mousekey_repeat);
|
phex(mousekey_repeat); print("/");
|
||||||
print("\n");
|
phex(mousekey_accel); print(")\n");
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,45 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include "host.h"
|
#include "host.h"
|
||||||
|
|
||||||
|
|
||||||
|
/* max value on report descriptor */
|
||||||
|
#define MOUSEKEY_MOVE_MAX 127
|
||||||
|
#define MOUSEKEY_WHEEL_MAX 127
|
||||||
|
|
||||||
|
#ifndef MOUSEKEY_MOVE_DELTA
|
||||||
|
#define MOUSEKEY_MOVE_DELTA 5
|
||||||
|
#endif
|
||||||
|
#ifndef MOUSEKEY_WHEEL_DELTA
|
||||||
|
#define MOUSEKEY_WHEEL_DELTA 1
|
||||||
|
#endif
|
||||||
|
#ifndef MOUSEKEY_DELAY
|
||||||
|
#define MOUSEKEY_DELAY 300
|
||||||
|
#endif
|
||||||
|
#ifndef MOUSEKEY_INTERVAL
|
||||||
|
#define MOUSEKEY_INTERVAL 50
|
||||||
|
#endif
|
||||||
|
#ifndef MOUSEKEY_MAX_SPEED
|
||||||
|
#define MOUSEKEY_MAX_SPEED 10
|
||||||
|
#endif
|
||||||
|
#ifndef MOUSEKEY_TIME_TO_MAX
|
||||||
|
#define MOUSEKEY_TIME_TO_MAX 20
|
||||||
|
#endif
|
||||||
|
#ifndef MOUSEKEY_WHEEL_MAX_SPEED
|
||||||
|
#define MOUSEKEY_WHEEL_MAX_SPEED 16
|
||||||
|
#endif
|
||||||
|
#ifndef MOUSEKEY_WHEEL_TIME_TO_MAX
|
||||||
|
#define MOUSEKEY_WHEEL_TIME_TO_MAX 40
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
uint8_t mk_delay;
|
||||||
|
uint8_t mk_interval;
|
||||||
|
uint8_t mk_max_speed;
|
||||||
|
uint8_t mk_time_to_max;
|
||||||
|
uint8_t mk_wheel_max_speed;
|
||||||
|
uint8_t mk_wheel_time_to_max;
|
||||||
|
|
||||||
|
|
||||||
void mousekey_task(void);
|
void mousekey_task(void);
|
||||||
void mousekey_on(uint8_t code);
|
void mousekey_on(uint8_t code);
|
||||||
void mousekey_off(uint8_t code);
|
void mousekey_off(uint8_t code);
|
||||||
|
Reference in New Issue
Block a user