receiver: add MouseClick diversion rule

This commit is contained in:
Vinícius 2020-11-13 20:48:09 -03:00 committed by Peter F. Patel-Schneider
parent be590c154a
commit 381371c899
2 changed files with 29 additions and 0 deletions

View File

@ -91,6 +91,7 @@ A `KeyPress` action takes a sequence of X11 key symbols and simulates a chorded
Any key symbols that correspond to modifier keys that are in the current keyboard modifiers are ignored.
A `MouseScroll` action takes a sequence of two numbers and simulates a horizontal and vertical mouse scroll of these amounts.
If the previous condition in the parent rule returns a number the scroll amounts are multiplied by this number.
A `MouseClick` action takes a mouse button name (`left`, `middle` or `right`) and a positive number, and simulates that number of clicks of the specified button.
An `Execute` actions takes a program and arguments and executes it asynchronously.
Solaar has several built-in rules, which are run after user-created rules and so can be overridden by user-created rules.

View File

@ -444,6 +444,33 @@ class MouseScroll(Action):
return None
class MouseClick(Action):
def __init__(self, args):
if len(args) == 1 and isinstance(args[0], list):
args = args[0]
if not isinstance(args, list):
args = [args]
self.button = str(args[0]) if len(args) >= 0 else 'unknown'
if not hasattr(_mouse.Button, self.button):
_log.warn('rule MouseClick action: button %s not known', self.button)
self.button = 'unknown'
count = args[1] if len(args) >= 1 else 1
try:
self.count = int(count)
except ValueError | TypeError:
_log.warn('rule MouseClick action: count %s should be an integer', count)
self.count = 1
def __str__(self):
return 'MouseClick: %s (%d)' % (self.button, self.count)
def evaluate(self, feature, notification, device, status, last_result):
if _log.isEnabledFor(_INFO):
_log.info('MouseClick action: %d %s' % (self.count, self.button))
mouse.click(getattr(_mouse.Button, self.button), self.count)
return None
class Execute(Action):
def __init__(self, args):
if isinstance(args, str):
@ -478,6 +505,7 @@ COMPONENTS = {
'Test': Test,
'KeyPress': KeyPress,
'MouseScroll': MouseScroll,
'MouseClick': MouseClick,
'Execute': Execute,
}