Skip to content

Instantly share code, notes, and snippets.

@takoeight0821
Created November 11, 2023 03:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save takoeight0821/d3a50f6fa64423695f839a60cadb99f4 to your computer and use it in GitHub Desktop.
Save takoeight0821/d3a50f6fa64423695f839a60cadb99f4 to your computer and use it in GitHub Desktop.
JoyConを振ってwキーを押すデモ(Python 3.11.6で動作)
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)
joycon-python
hidapi
pyglm
pyautogui
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment