Added deadzone configuration
This commit is contained in:
parent
8af36af217
commit
f4f0cbdf35
7 changed files with 25 additions and 15 deletions
|
@ -117,6 +117,7 @@ There are currently 6 available settings:
|
||||||
- `SCROLL_STICK` will set if 2D scrolling using your controller's analog sticks should be anabled, and which of the two sticks should move your cursor. Can be set to `"left"`, `"right"` or `"none"`. Defaults to `"right"` if not set. If both `CURSOR_STICK` and `SCROLL_STICK` are set to the same value, `CURSOR_STICK` will have priority.
|
- `SCROLL_STICK` will set if 2D scrolling using your controller's analog sticks should be anabled, and which of the two sticks should move your cursor. Can be set to `"left"`, `"right"` or `"none"`. Defaults to `"right"` if not set. If both `CURSOR_STICK` and `SCROLL_STICK` are set to the same value, `CURSOR_STICK` will have priority.
|
||||||
- `CURSOR_SENSITIVITY` will change the speed of your mouse cursor when it's being moved with an analog stick. Lower value is higher sensitivity, minimum `"1"`, suggested `"6"`. If this isn't set, cursor movement will be disabled.
|
- `CURSOR_SENSITIVITY` will change the speed of your mouse cursor when it's being moved with an analog stick. Lower value is higher sensitivity, minimum `"1"`, suggested `"6"`. If this isn't set, cursor movement will be disabled.
|
||||||
- `SCROLL_SENSITIVITY` will change the scroll speed when scrolling with an analog stick. Lower value is higher sensitivity, minimum `"1"`, suggested `"6"`. If this isn't set, scrolling will be disabled.
|
- `SCROLL_SENSITIVITY` will change the scroll speed when scrolling with an analog stick. Lower value is higher sensitivity, minimum `"1"`, suggested `"6"`. If this isn't set, scrolling will be disabled.
|
||||||
|
- `DEADZONE` will change how much your analog sticks should be tilted before their inputs are detected. Particularly useful for older devices that suffer from drifting. Use a value from `"0"` to `"128"`.
|
||||||
- `SIGNED_AXIS_VALUE` is needed if you're using Xbox controllers and Switch Joy-Cons to properly calibrate the analog stick's sensitivity. Set to `"true"` if you're using those controllers. Can be left out otherwise.
|
- `SIGNED_AXIS_VALUE` is needed if you're using Xbox controllers and Switch Joy-Cons to properly calibrate the analog stick's sensitivity. Set to `"true"` if you're using those controllers. Can be left out otherwise.
|
||||||
|
|
||||||
Example settings for a keyboard or mouse, notice that only the `GRAB_DEVICE` setting is needed in this case and you can leave everything else out:
|
Example settings for a keyboard or mouse, notice that only the `GRAB_DEVICE` setting is needed in this case and you can leave everything else out:
|
||||||
|
|
|
@ -31,4 +31,5 @@ CURSOR_SENSITIVITY = "6" #lower value is higher sensitivity, minimum 1
|
||||||
SCROLL_SENSITIVITY = "6" #lower value is higher sensitivity, minimum 1
|
SCROLL_SENSITIVITY = "6" #lower value is higher sensitivity, minimum 1
|
||||||
CURSOR_STICK = "left" #left, right or none
|
CURSOR_STICK = "left" #left, right or none
|
||||||
SCROLL_STICK = "right" #left, right or none
|
SCROLL_STICK = "right" #left, right or none
|
||||||
|
DEADZONE = "5" #integer between 0 and 128, bigger number is wider deadzone, default 5
|
||||||
GRAB_DEVICE = "false" #gain exclusivity on the device
|
GRAB_DEVICE = "false" #gain exclusivity on the device
|
||||||
|
|
|
@ -30,4 +30,5 @@ CURSOR_SENSITIVITY = "6" #lower value is higher sensitivity, minimum 1
|
||||||
SCROLL_SENSITIVITY = "6" #lower value is higher sensitivity, minimum 1
|
SCROLL_SENSITIVITY = "6" #lower value is higher sensitivity, minimum 1
|
||||||
CURSOR_STICK = "left" #left, right or none
|
CURSOR_STICK = "left" #left, right or none
|
||||||
SCROLL_STICK = "right" #left, right or none
|
SCROLL_STICK = "right" #left, right or none
|
||||||
|
DEADZONE = "5" #integer between 0 and 128, bigger number is wider deadzone, default 5
|
||||||
GRAB_DEVICE = "false" #gain exclusivity on the device
|
GRAB_DEVICE = "false" #gain exclusivity on the device
|
||||||
|
|
|
@ -33,4 +33,5 @@ CURSOR_SENSITIVITY = "6" #lower value is higher sensitivity, minimum 1
|
||||||
SCROLL_SENSITIVITY = "6" #lower value is higher sensitivity, minimum 1
|
SCROLL_SENSITIVITY = "6" #lower value is higher sensitivity, minimum 1
|
||||||
CURSOR_STICK = "left" #left, right or none
|
CURSOR_STICK = "left" #left, right or none
|
||||||
SCROLL_STICK = "right" #left, right or none
|
SCROLL_STICK = "right" #left, right or none
|
||||||
|
DEADZONE = "5" #integer between 0 and 128, bigger number is wider deadzone, default 5
|
||||||
GRAB_DEVICE = "false" #gain exclusivity on the device
|
GRAB_DEVICE = "false" #gain exclusivity on the device
|
||||||
|
|
|
@ -32,5 +32,6 @@ CURSOR_SENSITIVITY = "6" #lower value is higher sensitivity, minimum 1
|
||||||
SCROLL_SENSITIVITY = "6" #lower value is higher sensitivity, minimum 1
|
SCROLL_SENSITIVITY = "6" #lower value is higher sensitivity, minimum 1
|
||||||
CURSOR_STICK = "left" #left, right or none
|
CURSOR_STICK = "left" #left, right or none
|
||||||
SCROLL_STICK = "right" #left, right or none
|
SCROLL_STICK = "right" #left, right or none
|
||||||
GRAB_DEVICE = "false" #gain exclusivity on the device
|
DEADZONE = "5" #integer between 0 and 128, bigger number is wider deadzone, default 5
|
||||||
SIGNED_AXIS_VALUE = "true" #necessary for Xbox controllers and Switch joycons, use false for other controllers
|
SIGNED_AXIS_VALUE = "true" #necessary for Xbox controllers and Switch joycons, use false for other controllers
|
||||||
|
GRAB_DEVICE = "false" #gain exclusivity on the device
|
||||||
|
|
|
@ -31,4 +31,6 @@ CURSOR_SENSITIVITY = "6" #lower value is higher sensitivity, minimum 1
|
||||||
SCROLL_SENSITIVITY = "6" #lower value is higher sensitivity, minimum 1
|
SCROLL_SENSITIVITY = "6" #lower value is higher sensitivity, minimum 1
|
||||||
CURSOR_STICK = "left" #left, right or none
|
CURSOR_STICK = "left" #left, right or none
|
||||||
SCROLL_STICK = "right" #left, right or none
|
SCROLL_STICK = "right" #left, right or none
|
||||||
|
DEADZONE = "5" #integer between 0 and 128, bigger number is wider deadzone, default 5
|
||||||
SIGNED_AXIS_VALUE = "true" #necessary for Xbox controllers and Switch joycons, use false for other controllers
|
SIGNED_AXIS_VALUE = "true" #necessary for Xbox controllers and Switch joycons, use false for other controllers
|
||||||
|
GRAB_DEVICE = "false" #gain exclusivity on the device
|
||||||
|
|
|
@ -66,6 +66,10 @@ impl EventReader {
|
||||||
if let Some(axis_value) = self.config.get(&"default".to_string()).unwrap().settings.get("SIGNED_AXIS_VALUE") {
|
if let Some(axis_value) = self.config.get(&"default".to_string()).unwrap().settings.get("SIGNED_AXIS_VALUE") {
|
||||||
has_signed_axis_value = axis_value.as_str();
|
has_signed_axis_value = axis_value.as_str();
|
||||||
}
|
}
|
||||||
|
let mut deadzone: i32 = 5;
|
||||||
|
if let Some(deadzone_str) = self.config.get(&"default".to_string()).unwrap().settings.get("DEADZONE") {
|
||||||
|
deadzone = deadzone_str.parse::<i32>().expect("Invalid value for DEADZONE, please use an integer between 0 and 128.");
|
||||||
|
}
|
||||||
while let Some(Ok(event)) = stream.next().await {
|
while let Some(Ok(event)) = stream.next().await {
|
||||||
match (event.event_type(), RelativeAxisType(event.code()), AbsoluteAxisType(event.code())) {
|
match (event.event_type(), RelativeAxisType(event.code()), AbsoluteAxisType(event.code())) {
|
||||||
(EventType::KEY, _, _) => {
|
(EventType::KEY, _, _) => {
|
||||||
|
@ -103,22 +107,22 @@ impl EventReader {
|
||||||
},
|
},
|
||||||
(EventType::ABSOLUTE, _, AbsoluteAxisType::ABS_X | AbsoluteAxisType::ABS_Y) => {
|
(EventType::ABSOLUTE, _, AbsoluteAxisType::ABS_X | AbsoluteAxisType::ABS_Y) => {
|
||||||
if cursor_analog_mode == "left" {
|
if cursor_analog_mode == "left" {
|
||||||
let axis_value = self.get_axis_value(&has_signed_axis_value, &event).await;
|
let axis_value = self.get_axis_value(&has_signed_axis_value, &event, deadzone).await;
|
||||||
let mut cursor_analog_position = self.cursor_analog_position.lock().await;
|
let mut cursor_analog_position = self.cursor_analog_position.lock().await;
|
||||||
cursor_analog_position[event.code() as usize] = axis_value;
|
cursor_analog_position[event.code() as usize] = axis_value;
|
||||||
} else if scroll_analog_mode == "left" {
|
} else if scroll_analog_mode == "left" {
|
||||||
let axis_value = self.get_axis_value(&has_signed_axis_value, &event).await;
|
let axis_value = self.get_axis_value(&has_signed_axis_value, &event, deadzone).await;
|
||||||
let mut scroll_analog_position = self.scroll_analog_position.lock().await;
|
let mut scroll_analog_position = self.scroll_analog_position.lock().await;
|
||||||
scroll_analog_position[event.code() as usize] = axis_value;
|
scroll_analog_position[event.code() as usize] = axis_value;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
(EventType::ABSOLUTE, _, AbsoluteAxisType::ABS_RX | AbsoluteAxisType::ABS_RY) => {
|
(EventType::ABSOLUTE, _, AbsoluteAxisType::ABS_RX | AbsoluteAxisType::ABS_RY) => {
|
||||||
if cursor_analog_mode == "right" {
|
if cursor_analog_mode == "right" {
|
||||||
let axis_value = self.get_axis_value(&has_signed_axis_value, &event).await;
|
let axis_value = self.get_axis_value(&has_signed_axis_value, &event, deadzone).await;
|
||||||
let mut cursor_analog_position = self.cursor_analog_position.lock().await;
|
let mut cursor_analog_position = self.cursor_analog_position.lock().await;
|
||||||
cursor_analog_position[event.code() as usize -3] = axis_value;
|
cursor_analog_position[event.code() as usize -3] = axis_value;
|
||||||
} else if scroll_analog_mode == "right" {
|
} else if scroll_analog_mode == "right" {
|
||||||
let axis_value = self.get_axis_value(&has_signed_axis_value, &event).await;
|
let axis_value = self.get_axis_value(&has_signed_axis_value, &event, deadzone).await;
|
||||||
let mut scroll_analog_position = self.scroll_analog_position.lock().await;
|
let mut scroll_analog_position = self.scroll_analog_position.lock().await;
|
||||||
scroll_analog_position[event.code() as usize -3] = axis_value;
|
scroll_analog_position[event.code() as usize -3] = axis_value;
|
||||||
}
|
}
|
||||||
|
@ -234,17 +238,16 @@ impl EventReader {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn get_axis_value(&self, has_signed_axis_value: &str, event: &InputEvent) -> i32 {
|
async fn get_axis_value(&self, has_signed_axis_value: &str, event: &InputEvent, deadzone: i32) -> i32 {
|
||||||
let axis_value: i32 = match &has_signed_axis_value {
|
let distance_from_center: i32 = match &has_signed_axis_value {
|
||||||
&"false" => {
|
&"false" => (event.value() as i32 - 128) * 200,
|
||||||
let distance_from_center: i32 = event.value() as i32 - 128;
|
_ => event.value() as i32
|
||||||
distance_from_center / 10
|
|
||||||
}
|
|
||||||
_ => {
|
|
||||||
event.value() as i32 / 2000
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
return axis_value
|
if distance_from_center.abs() <= deadzone * 200 {
|
||||||
|
0
|
||||||
|
} else {
|
||||||
|
(distance_from_center + 2000 - 1) / 2000
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn toggle_modifiers(&self, key: Key, value: i32) {
|
async fn toggle_modifiers(&self, key: Key, value: i32) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue