Created
November 11, 2023 03:19
-
-
Save takoeight0821/d3a50f6fa64423695f839a60cadb99f4 to your computer and use it in GitHub Desktop.
JoyConを振ってwキーを押すデモ(Python 3.11.6で動作)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
import pyautogui | |
from pyjoycon import device | |
from pyjoycon.joycon import JoyCon | |
# Set up JoyCon | |
id = device.get_L_id() | |
joycon = JoyCon(*id) | |
is_pressed = False | |
prev_z_acc = 0 | |
threshold = 500 | |
while True: | |
z_acc = joycon.get_status()["accel"]["z"] | |
print(z_acc) | |
# skip first iteration | |
if prev_z_acc == 0: | |
prev_z_acc = z_acc | |
continue | |
diff = abs(z_acc - prev_z_acc) | |
if diff > threshold and not is_pressed: | |
is_pressed = True | |
print(is_pressed) | |
pyautogui.keyDown('w') | |
elif diff <= threshold and is_pressed: | |
is_pressed = False | |
print(is_pressed) | |
pyautogui.keyUp('w') | |
else: | |
print("no change ", is_pressed) | |
prev_z_acc = z_acc | |
time.sleep(0.1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
joycon-python | |
hidapi | |
pyglm | |
pyautogui |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment