add mouse buttons to pointing device
This commit is contained in:
		
							
								
								
									
										16
									
								
								kmk/hid.py
									
									
									
									
									
								
							
							
						
						
									
										16
									
								
								kmk/hid.py
									
									
									
									
									
								
							@@ -4,7 +4,7 @@ from micropython import const
 | 
			
		||||
 | 
			
		||||
from storage import getmount
 | 
			
		||||
 | 
			
		||||
from kmk.keys import FIRST_KMK_INTERNAL_KEY, ConsumerKey, ModifierKey
 | 
			
		||||
from kmk.keys import FIRST_KMK_INTERNAL_KEY, ConsumerKey, ModifierKey, MouseKey
 | 
			
		||||
from kmk.utils import clamp
 | 
			
		||||
 | 
			
		||||
try:
 | 
			
		||||
@@ -96,6 +96,8 @@ class AbstractHID:
 | 
			
		||||
                self.add_modifier(key)
 | 
			
		||||
            elif isinstance(key, ConsumerKey):
 | 
			
		||||
                self.add_cc(key)
 | 
			
		||||
            elif isinstance(key, MouseKey):
 | 
			
		||||
                self.add_pd(key)
 | 
			
		||||
            else:
 | 
			
		||||
                self.add_key(key)
 | 
			
		||||
                if key.has_modifiers:
 | 
			
		||||
@@ -133,6 +135,7 @@ class AbstractHID:
 | 
			
		||||
            self.report_keys[idx] = 0x00
 | 
			
		||||
 | 
			
		||||
        self.remove_cc()
 | 
			
		||||
        self.remove_pd()
 | 
			
		||||
 | 
			
		||||
        return self
 | 
			
		||||
 | 
			
		||||
@@ -202,8 +205,17 @@ class AbstractHID:
 | 
			
		||||
    def remove_cc(self):
 | 
			
		||||
        # Remove consumer control report.
 | 
			
		||||
        if self._cc_report[1]:
 | 
			
		||||
            self._cc_report[1] = 0x00
 | 
			
		||||
            self._cc_pending = True
 | 
			
		||||
        self._cc_report[1] = 0x00
 | 
			
		||||
 | 
			
		||||
    def add_pd(self, key):
 | 
			
		||||
        self._pd_report[1] |= key.code
 | 
			
		||||
        self._pd_pending = True
 | 
			
		||||
 | 
			
		||||
    def remove_pd(self):
 | 
			
		||||
        if self._pd_report[1]:
 | 
			
		||||
            self._pd_pending = True
 | 
			
		||||
            self._pd_report[1] = 0x00
 | 
			
		||||
 | 
			
		||||
    def move_axis(self, axis):
 | 
			
		||||
        if axis.delta != 0 or self._pd_report[axis.code + 2] != 0:
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										11
									
								
								kmk/keys.py
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								kmk/keys.py
									
									
									
									
									
								
							@@ -20,6 +20,7 @@ class KeyType:
 | 
			
		||||
    SIMPLE = const(0)
 | 
			
		||||
    MODIFIER = const(1)
 | 
			
		||||
    CONSUMER = const(2)
 | 
			
		||||
    MOUSE = const(3)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
FIRST_KMK_INTERNAL_KEY = const(1000)
 | 
			
		||||
@@ -697,6 +698,10 @@ class ConsumerKey(Key):
 | 
			
		||||
    pass
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class MouseKey(Key):
 | 
			
		||||
    pass
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def make_key(
 | 
			
		||||
    code: Optional[int] = None,
 | 
			
		||||
    names: Tuple[str, ...] = tuple(),  # NOQA
 | 
			
		||||
@@ -727,6 +732,8 @@ def make_key(
 | 
			
		||||
        constructor = ModifierKey
 | 
			
		||||
    elif type == KeyType.CONSUMER:
 | 
			
		||||
        constructor = ConsumerKey
 | 
			
		||||
    elif type == KeyType.MOUSE:
 | 
			
		||||
        constructor = MouseKey
 | 
			
		||||
    else:
 | 
			
		||||
        raise ValueError('Unrecognized key type')
 | 
			
		||||
 | 
			
		||||
@@ -759,6 +766,10 @@ def make_consumer_key(*args, **kwargs) -> Key:
 | 
			
		||||
    return make_key(*args, **kwargs, type=KeyType.CONSUMER)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def make_mouse_key(*args, **kwargs) -> Key:
 | 
			
		||||
    return make_key(*args, **kwargs, type=KeyType.MOUSE)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
# Argumented keys are implicitly internal, so auto-gen of code
 | 
			
		||||
# is almost certainly the best plan here
 | 
			
		||||
def make_argumented_key(
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user