1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# Adapted from https://gist.github.com/geekley/5e6daf62d2e86b566c4886f20b604d21
# which is unlicense lincensed
extends Node
func _ready() -> void:
Input.joy_connection_changed.connect(joy_check)
static var banned_words: PackedStringArray = [
"touchpad", "trackpad", "clickpad", "mouse", "pen", "finger", "led",
"Synaptics",
]
static func joy_check(device: int, connected: bool) -> void:
if not connected:
return
var device_name: String = Input.get_joy_name(device)
if not is_banned(device_name):
return
var guid: String = Input.get_joy_guid(device)
var mapping: String = guid + ',' + device_name.replace(',', '')
Input.add_joy_mapping(mapping, true)
for axis: JoyAxis in range(JOY_AXIS_SDL_MAX) as Array[JoyAxis]:
var event: InputEventJoypadMotion = InputEventJoypadMotion.new()
event.device = device
event.axis = axis
Input.parse_input_event(event)
for button_index: JoyButton in range(JOY_BUTTON_SDL_MAX) as Array[JoyButton]:
var event: InputEventJoypadButton = InputEventJoypadButton.new()
event.device = device
event.button_index = button_index
Input.parse_input_event(event)
prints('Ignoring joypad device:', mapping)
static func is_banned(device_name: String) -> bool:
for word: String in banned_words:
var i: int = device_name.findn(word)
if i < 0:
continue
if i > 0 and not is_ascii_non_letter(device_name[i - 1]):
continue
var j: int = i + word.length()
if j < device_name.length() and not is_ascii_non_letter(device_name[j]):
continue
return true
return false
static func is_ascii_non_letter(c: String) -> bool:
return c.unicode_at(0) < 128 and not (c >= 'a' and c <= 'z' or c >= 'A' and c <= 'Z')
|