@ -16,65 +16,59 @@
# include <Arduino.h>
# include <Arduino.h>
# include "MouseKeys.h"
# include "kaleidoscope/plugin/mousekeys/MouseWrapper.h"
# include "kaleidoscope/Runtime.h"
# include "kaleidoscope/Runtime.h"
# include "Kaleidoscope-MouseKeys.h"
# include "Kaleidoscope-FocusSerial.h"
# include "Kaleidoscope-FocusSerial.h"
# include "kaleidoscope/keyswitch_state.h"
# include "kaleidoscope/keyswitch_state.h"
namespace kaleidoscope {
namespace kaleidoscope {
namespace plugin {
namespace plugin {
uint8_t MouseKeys_ : : speed = 1 ;
uint8_t MouseKeys : : speed = 1 ;
uint16_t MouseKeys_ : : speedDelay = 1 ;
uint16_t MouseKeys : : speedDelay = 1 ;
uint8_t MouseKeys_ : : accelSpeed = 1 ;
uint16_t MouseKeys_ : : accelDelay = 64 ;
uint8_t MouseKeys_ : : wheelSpeed = 1 ;
uint16_t MouseKeys_ : : wheelDelay = 50 ;
uint16_t MouseKeys_ : : move_start_time_ ;
uint8_t MouseKeys : : accelSpeed = 1 ;
uint16_t MouseKeys_ : : accel_start_time_ ;
uint16_t MouseKeys : : accelDelay = 64 ;
uint16_t MouseKeys_ : : wheel_start_time_ ;
uint8_t MouseKeys_ : : directions_ = 0 ;
uint8_t MouseKeys : : wheelSpeed = 1 ;
uint8_t MouseKeys_ : : pending_directions_ = 0 ;
uint16_t MouseKeys : : wheelDelay = 50 ;
uint8_t MouseKeys_ : : buttons_ = 0 ;
// =============================================================================
// =============================================================================
// Configuration functions
// Configuration functions
void MouseKeys _ : : setWarpGridSize ( uint8_t grid_size ) {
void MouseKeys : : setWarpGridSize ( uint8_t grid_size ) {
MouseW rapper. warp_grid_size = grid_size ;
mousekeys: : w rapper. warp_grid_size = grid_size ;
}
}
void MouseKeys _ : : setSpeedLimit ( uint8_t speed_limit ) {
void MouseKeys : : setSpeedLimit ( uint8_t speed_limit ) {
MouseWrapper. speedL imit = speed_limit ;
mousekeys: : wrapper . speed_l imit = speed_limit ;
}
}
// =============================================================================
// =============================================================================
// Key variant tests
// Key variant tests
bool MouseKeys _ : : isMouseKey ( const Key & key ) const {
bool MouseKeys : : isMouseKey ( const Key & key ) const {
return ( key . getFlags ( ) = = ( SYNTHETIC | IS_MOUSE_KEY ) ) ;
return ( key . getFlags ( ) = = ( SYNTHETIC | IS_MOUSE_KEY ) ) ;
}
}
bool MouseKeys _ : : isMouseButtonKey ( const Key & key ) const {
bool MouseKeys : : isMouseButtonKey ( const Key & key ) const {
uint8_t variant = key . getKeyCode ( ) & ( KEY_MOUSE_BUTTON | KEY_MOUSE_WARP ) ;
uint8_t variant = key . getKeyCode ( ) & ( KEY_MOUSE_BUTTON | KEY_MOUSE_WARP ) ;
return variant = = KEY_MOUSE_BUTTON ;
return variant = = KEY_MOUSE_BUTTON ;
}
}
bool MouseKeys _ : : isMouseMoveKey ( const Key & key ) const {
bool MouseKeys : : isMouseMoveKey ( const Key & key ) const {
uint8_t mask = ( KEY_MOUSE_BUTTON | KEY_MOUSE_WARP | KEY_MOUSE_WHEEL ) ;
uint8_t mask = ( KEY_MOUSE_BUTTON | KEY_MOUSE_WARP | KEY_MOUSE_WHEEL ) ;
uint8_t variant = key . getKeyCode ( ) & mask ;
uint8_t variant = key . getKeyCode ( ) & mask ;
return variant = = 0 ;
return variant = = 0 ;
}
}
bool MouseKeys _ : : isMouseWarpKey ( const Key & key ) const {
bool MouseKeys : : isMouseWarpKey ( const Key & key ) const {
return ( key . getKeyCode ( ) & KEY_MOUSE_WARP ) ! = 0 ;
return ( key . getKeyCode ( ) & KEY_MOUSE_WARP ) ! = 0 ;
}
}
bool MouseKeys _ : : isMouseWheelKey ( const Key & key ) const {
bool MouseKeys : : isMouseWheelKey ( const Key & key ) const {
uint8_t mask = ( KEY_MOUSE_BUTTON | KEY_MOUSE_WARP | KEY_MOUSE_WHEEL ) ;
uint8_t mask = ( KEY_MOUSE_BUTTON | KEY_MOUSE_WARP | KEY_MOUSE_WHEEL ) ;
uint8_t variant = key . getKeyCode ( ) & mask ;
uint8_t variant = key . getKeyCode ( ) & mask ;
return variant = = KEY_MOUSE_WHEEL ;
return variant = = KEY_MOUSE_WHEEL ;
@ -84,12 +78,12 @@ bool MouseKeys_::isMouseWheelKey(const Key& key) const {
// Event Handlers
// Event Handlers
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
EventHandlerResult MouseKeys _ : : onNameQuery ( ) {
EventHandlerResult MouseKeys : : onNameQuery ( ) {
return : : Focus . sendName ( F ( " MouseKeys " ) ) ;
return : : Focus . sendName ( F ( " MouseKeys " ) ) ;
}
}
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
EventHandlerResult MouseKeys _ : : onSetup ( void ) {
EventHandlerResult MouseKeys : : onSetup ( void ) {
kaleidoscope : : Runtime . hid ( ) . mouse ( ) . setup ( ) ;
kaleidoscope : : Runtime . hid ( ) . mouse ( ) . setup ( ) ;
kaleidoscope : : Runtime . hid ( ) . absoluteMouse ( ) . setup ( ) ;
kaleidoscope : : Runtime . hid ( ) . absoluteMouse ( ) . setup ( ) ;
@ -97,14 +91,14 @@ EventHandlerResult MouseKeys_::onSetup(void) {
}
}
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
EventHandlerResult MouseKeys _ : : afterEachCycle ( ) {
EventHandlerResult MouseKeys : : afterEachCycle ( ) {
// Check timeout for accel update interval.
// Check timeout for accel update interval.
if ( Runtime . hasTimeExpired ( accel_start_time_ , accelDelay ) ) {
if ( Runtime . hasTimeExpired ( accel_start_time_ , accelDelay ) ) {
accel_start_time_ = Runtime . millisAtCycleStart ( ) ;
accel_start_time_ = Runtime . millisAtCycleStart ( ) ;
// `accel S tep` determines the movement speed of the mouse pointer, and gets
// `accel _s tep` determines the movement speed of the mouse pointer, and gets
// reset to zero when no mouse movement keys is pressed (see below).
// reset to zero when no mouse movement keys is pressed (see below).
if ( MouseWrapper. accelS tep < 255 - accelSpeed ) {
if ( mousekeys: : wrapper . accel_s tep < 255 - accelSpeed ) {
MouseWrapper. accelS tep + = accelSpeed ;
mousekeys: : wrapper . accel_s tep + = accelSpeed ;
}
}
}
}
@ -120,7 +114,7 @@ EventHandlerResult MouseKeys_::afterEachCycle() {
}
}
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
EventHandlerResult MouseKeys _ : : onKeyEvent ( KeyEvent & event ) {
EventHandlerResult MouseKeys : : onKeyEvent ( KeyEvent & event ) {
if ( ! isMouseKey ( event . key ) )
if ( ! isMouseKey ( event . key ) )
return EventHandlerResult : : OK ;
return EventHandlerResult : : OK ;
@ -145,7 +139,7 @@ EventHandlerResult MouseKeys_::onKeyEvent(KeyEvent &event) {
}
}
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
EventHandlerResult MouseKeys _ : : afterReportingState ( const KeyEvent & event ) {
EventHandlerResult MouseKeys : : afterReportingState ( const KeyEvent & event ) {
if ( ! isMouseKey ( event . key ) )
if ( ! isMouseKey ( event . key ) )
return EventHandlerResult : : OK ;
return EventHandlerResult : : OK ;
@ -180,7 +174,7 @@ EventHandlerResult MouseKeys_::afterReportingState(const KeyEvent &event) {
// will be up to date at the end of processing a mouse key event. We add bits
// will be up to date at the end of processing a mouse key event. We add bits
// to the `pending` directions only; these get copied later if the event isn't
// to the `pending` directions only; these get copied later if the event isn't
// aborted.
// aborted.
EventHandlerResult MouseKeys _ : : onAddToReport ( Key key ) {
EventHandlerResult MouseKeys : : onAddToReport ( Key key ) {
if ( ! isMouseKey ( key ) )
if ( ! isMouseKey ( key ) )
return EventHandlerResult : : OK ;
return EventHandlerResult : : OK ;
@ -200,15 +194,15 @@ EventHandlerResult MouseKeys_::onAddToReport(Key key) {
// HID report helper functions
// HID report helper functions
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
void MouseKeys _ : : sendMouseButtonReport ( ) const {
void MouseKeys : : sendMouseButtonReport ( ) const {
Runtime . hid ( ) . mouse ( ) . releaseAllButtons ( ) ;
Runtime . hid ( ) . mouse ( ) . releaseAllButtons ( ) ;
Runtime . hid ( ) . mouse ( ) . pressButtons ( buttons_ ) ;
Runtime . hid ( ) . mouse ( ) . pressButtons ( buttons_ ) ;
Runtime . hid ( ) . mouse ( ) . sendReport ( ) ;
Runtime . hid ( ) . mouse ( ) . sendReport ( ) ;
}
}
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
void MouseKeys _ : : sendMouseWarpReport ( const KeyEvent & event ) const {
void MouseKeys : : sendMouseWarpReport ( const KeyEvent & event ) const {
MouseW rapper. warp (
mousekeys: : w rapper. warp (
( ( event . key . getKeyCode ( ) & KEY_MOUSE_WARP_END ) ? WARP_END : 0x00 ) |
( ( event . key . getKeyCode ( ) & KEY_MOUSE_WARP_END ) ? WARP_END : 0x00 ) |
( ( event . key . getKeyCode ( ) & KEY_MOUSE_UP ) ? WARP_UP : 0x00 ) |
( ( event . key . getKeyCode ( ) & KEY_MOUSE_UP ) ? WARP_UP : 0x00 ) |
( ( event . key . getKeyCode ( ) & KEY_MOUSE_DOWN ) ? WARP_DOWN : 0x00 ) |
( ( event . key . getKeyCode ( ) & KEY_MOUSE_DOWN ) ? WARP_DOWN : 0x00 ) |
@ -217,7 +211,7 @@ void MouseKeys_::sendMouseWarpReport(const KeyEvent &event) const {
}
}
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
void MouseKeys _ : : sendMouseMoveReport ( ) {
void MouseKeys : : sendMouseMoveReport ( ) {
move_start_time_ = Runtime . millisAtCycleStart ( ) ;
move_start_time_ = Runtime . millisAtCycleStart ( ) ;
int8_t vx = 0 ;
int8_t vx = 0 ;
@ -226,7 +220,7 @@ void MouseKeys_::sendMouseMoveReport() {
if ( direction = = 0 ) {
if ( direction = = 0 ) {
// If there are no mouse movement keys held, reset speed to zero.
// If there are no mouse movement keys held, reset speed to zero.
MouseWrapper. accelS tep = 0 ;
mousekeys: : wrapper . accel_s tep = 0 ;
} else {
} else {
// For each active direction, add the mouse movement speed.
// For each active direction, add the mouse movement speed.
if ( direction & KEY_MOUSE_LEFT )
if ( direction & KEY_MOUSE_LEFT )
@ -239,14 +233,14 @@ void MouseKeys_::sendMouseMoveReport() {
vy + = speed ;
vy + = speed ;
// Prepare the mouse report.
// Prepare the mouse report.
MouseW rapper. move ( vx , vy ) ;
mousekeys: : w rapper. move ( vx , vy ) ;
// Send the report.
// Send the report.
Runtime . hid ( ) . mouse ( ) . sendReport ( ) ;
Runtime . hid ( ) . mouse ( ) . sendReport ( ) ;
}
}
}
}
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
void MouseKeys _ : : sendMouseWheelReport ( ) {
void MouseKeys : : sendMouseWheelReport ( ) {
wheel_start_time_ = Runtime . millisAtCycleStart ( ) ;
wheel_start_time_ = Runtime . millisAtCycleStart ( ) ;
int8_t vx = 0 ;
int8_t vx = 0 ;
@ -275,4 +269,4 @@ void MouseKeys_::sendMouseWheelReport() {
} // namespace plugin
} // namespace plugin
} // namespace kaleidoscope
} // namespace kaleidoscope
kaleidoscope : : plugin : : MouseKeys _ MouseKeys ;
kaleidoscope : : plugin : : MouseKeys MouseKeys ;