Initial commit
This commit is contained in:
commit
c4244d325d
57
axis_to_scrollwheel.py
Normal file
57
axis_to_scrollwheel.py
Normal file
|
@ -0,0 +1,57 @@
|
|||
from datetime import datetime, timedelta
|
||||
import gremlin
|
||||
from gremlin.user_plugin import *
|
||||
|
||||
axis = PhysicalInputVariable(
|
||||
"Axis",
|
||||
"The axis that will trigger scrolling.",
|
||||
[gremlin.common.InputType.JoystickAxis],
|
||||
)
|
||||
|
||||
mode = ModeVariable(
|
||||
"Mode",
|
||||
"The mode in which the axis will be mapped.",
|
||||
)
|
||||
|
||||
response_coefficient = FloatVariable(
|
||||
"Scroll Speed",
|
||||
"Adjusts the rate at which the target button is pressed, relative to the axis strength.",
|
||||
1.0,
|
||||
)
|
||||
|
||||
deadzone = FloatVariable(
|
||||
"Deadzone",
|
||||
"Applies a deadzone to both sides of the axis.",
|
||||
0.0,
|
||||
)
|
||||
|
||||
# NB: Not a real boolean; invert.value returns 0 or 2
|
||||
invert = BoolVariable(
|
||||
"Invert",
|
||||
"Reverse the direction that the axis scrolls.",
|
||||
False,
|
||||
)
|
||||
|
||||
axis_decorator = axis.create_decorator(mode.value)
|
||||
|
||||
# Stateful data
|
||||
last_timestamp = datetime.now()
|
||||
|
||||
@axis_decorator.axis(axis.input_id)
|
||||
# @gremlin.input_devices.periodic(1)
|
||||
def handle_axis(event):
|
||||
global last_timestamp
|
||||
|
||||
# axis_value = joy[axis.device_guid].axis(axis.input_id).value
|
||||
axis_value = event.value
|
||||
|
||||
if (abs(axis_value) < deadzone.value):
|
||||
return
|
||||
|
||||
delta = (datetime.now() - last_timestamp) / timedelta(milliseconds=1)
|
||||
|
||||
if delta >= (1 - abs(axis_value)) * 250 * response_coefficient.value:
|
||||
direction = 1 if axis_value > 0 else -1
|
||||
if invert.value: direction = direction * -1
|
||||
gremlin.sendinput.mouse_wheel(direction)
|
||||
last_timestamp = datetime.now()
|
38
readme.md
Normal file
38
readme.md
Normal file
|
@ -0,0 +1,38 @@
|
|||
# Axis to Scrollwheel - a plugin for Joystick Gremlin
|
||||
|
||||
This is a plugin for [Joystick Gremlin](https://github.com/WhiteMagic/JoystickGremlin) (JG). Familiarity with JG is assumed.
|
||||
|
||||
This script will allow you to configure a joystick axis to send mouse scrollwheel events. The scrollwheel will move faster in proportion to how far the axis is moved.
|
||||
|
||||
## Installation
|
||||
|
||||
Download the code (TODO: add granular instructions). Click "Add Plugin" on the Plugins tab of Joystick Gremlin. Navigate to the axis_to_scrollwheel.py file and select it.
|
||||
|
||||
## Configuration
|
||||
|
||||
Clicking on the gear next to the plugin in the plugin list will present you with several configuration options. Note that you must toggle the profile off and on again for changes to take effect.
|
||||
|
||||
### Axis
|
||||
|
||||
The axis that should act as a scrollwheel.
|
||||
|
||||
### Mode
|
||||
|
||||
The Joystick Gremlin mode that needs to be active for the binding to work. If you aren't using Modes (or don't know what they are) the default value should work correctly.
|
||||
|
||||
### Scroll Speed
|
||||
|
||||
Increasing this value will cause the scroll wheel to scroll more quickly. 1.0 is a good default.
|
||||
|
||||
### Deadzone
|
||||
|
||||
This deadzone will take precedence over any deadzone already configured in Joystick Gremlin. 1.0 represents the joystick's entire range. 0.0 represents no deadzone.
|
||||
|
||||
### Invert
|
||||
|
||||
If the scrolling feels backwards, select this.
|
||||
|
||||
## Known Issues
|
||||
|
||||
* The Response Coefficient doesn't always get assigned a default value. You should set it to `1.0` to start.
|
||||
* Maxing out the axis in either direction will cause the scrolling to stop. This is a limitation of Joystick Gremlin; it stops producing joystick axis events in this case. Ideally we could use a periodic check instead of responding to axis events, but this is currently broken (see https://github.com/WhiteMagic/JoystickGremlin/issues/239).
|
Loading…
Reference in New Issue
Block a user