記錄一下羅技鼠標G304單擊變雙擊的軟件解決過程和方案(適用于macOS, 如果是Windows,使用AutoHotKey也有類似解決辦法、方案,改日提供):
背景:通過羅技Logitech?G HUB軟件對羅技的游戲鼠標側鍵button4做了映射,映射到了command+w,用于快速關閉窗口或標簽,但此側健使用2年后出現了鼠標按鍵連擊現象,單擊變雙擊,經常連續關閉2個標簽頁。可以通過羅技售后維修,但由于已經過保,通過研究找到了軟件的解決辦法:
首先通過羅技Logitech?G HUB軟件,通過該軟件把該鼠標設定到on-board模式(軟件模式下Karabiner-Elements跟蹤不到button4按鍵)
然后通過Karabiner-Elements對側鍵進行修改,首先要在Devices欄確保對此鼠標有做監控和跟蹤Modify events:?
然后轉到Misc, 打開配置文件夾,并編輯配置文件karabiner.json:
直接通過代碼對karabiner.json添加以下規則:
{"description": "button4 twice","manipulators": [{"conditions": [{"name": "press_button4","type": "variable_if","value": 1}],"from": {"pointing_button": "button4"},"to": [{"key_code": "w","modifiers": ["left_command"]}],"type": "basic"},{"from": {"pointing_button": "button4"},"parameters": {"basic.to_delayed_action_delay_milliseconds": 100},"to": [{"set_variable": {"name": "press_button4","value": 1}}],"to_delayed_action": {"to_if_canceled": [{"set_variable": {"name": "press_button4","value": 0}}],"to_if_invoked": [{"set_variable": {"name": "press_button4","value": 0}},{"key_code": "w","modifiers": ["left_command"]} ]},"type": "basic"}]
}
代碼中to_delayed_action_delay_milliseconds?指定了雙擊判定的毫秒間隔,設置為100毫秒,100毫秒內的雙擊將視同單擊。 此值可自由設定。 若100毫秒內無雙擊,則繼續執行原單擊to_if_invoked。
至此,問題搞定。
官方參考文檔:
to_delayed_action | Karabiner-Elements
Karabiner-Elements是一個很強大的專門用于修改macOS按鍵映射的開源免費軟件:
Karabiner-Elements官網鏈接:
Karabiner-Elements