Last active
June 11, 2022 13:12
-
-
Save Akkiesoft/b0b0fba5b1ef04afb4a6df4833f075a5 to your computer and use it in GitHub Desktop.
TinyPicoTrio向けの村人取引キー+。他のキーによく使うアイテム変換を詰めた。
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
# Written in CircuitPython | |
# for Raspberry Pi Pico or Pimoroni Tiny2040 | |
import board | |
import digitalio | |
from time import sleep | |
import usb_hid | |
from adafruit_hid.keyboard import Keyboard | |
from adafruit_hid.keycode import Keycode | |
from adafruit_hid.mouse import Mouse | |
led = [ | |
digitalio.DigitalInOut(board.LED_R), | |
digitalio.DigitalInOut(board.LED_G), | |
digitalio.DigitalInOut(board.LED_B) | |
] | |
for l in led: | |
l.direction = digitalio.Direction.OUTPUT | |
# tiny2040 LED is active low | |
l.value = 1 | |
keyboard = 0 | |
while not keyboard: | |
try: | |
keyboard = Keyboard(usb_hid.devices) | |
mouse = Mouse(usb_hid.devices) | |
except: | |
pass | |
sleep(1) | |
# 最初の0/1: | |
# メニューの開き方。0はeキー、1は作業台を開くことを想定した右クリック | |
# 1つめのtuple: | |
# 右クリックして最初にアイテム枠に移動する時の移動量 | |
# 2つめのtuple: | |
# 取引アイテム受け取りの枠から、取引アイテム選択リストまでの移動量 | |
# 右から左上に移動と想定されるので基本的にマイナス値 | |
mouse_move = [ | |
# for M1 Mac | |
[ | |
# for nether blicks | |
0, | |
( 640, -210), # initial move | |
(-1140, 10) # loop | |
], [ | |
# for gold | |
1, | |
( 520, -170), # initial move | |
(-1030, 0) # loop | |
], [ | |
# for emerald | |
1, | |
( 400, -170), # initial move | |
(-600, -60) # loop | |
] | |
] | |
button = [ | |
digitalio.DigitalInOut(board.GP4), | |
digitalio.DigitalInOut(board.GP5), | |
digitalio.DigitalInOut(board.GP6) | |
] | |
for b in button: | |
b.switch_to_input(pull=digitalio.Pull.UP) | |
buttons = len(button) | |
released = 1 | |
trading = 0 | |
while True: | |
no_push = 0 | |
for i,b in enumerate(button): | |
if b.value: | |
no_push += 1 | |
continue | |
led[i].value = 1 - led[i].value | |
if not trading: | |
# 取引開始。取引中はShift押しっぱなし | |
trading = 1 | |
if mouse_move[i][0]: | |
mouse.click(Mouse.RIGHT_BUTTON) | |
else: | |
keyboard.send(Keycode.E) | |
sleep(0.5) | |
mouse.move(x = mouse_move[i][1][0], y = mouse_move[i][1][1]) | |
keyboard.press(Keycode.LEFT_SHIFT) | |
# 取引アイテム受け取り枠<->取引アイテムリストを反復しながらクリック | |
mx, my = mouse_move[i][2] | |
mouse.move(x = mx * trading, y = my * trading) | |
mouse.click(Mouse.LEFT_BUTTON) | |
trading = trading * -1 | |
sleep(0.15) | |
released = 0 | |
if no_push == buttons and not released: | |
for l in led: | |
l.value = 1 | |
if trading < 0: | |
# 取引アイテム受け取り枠に戻す | |
mouse.move(x = mx * -1, y = my * -1) | |
mouse.click(Mouse.LEFT_BUTTON) | |
keyboard.press(Keycode.ESCAPE) | |
sleep(0.15) | |
keyboard.release_all() | |
released = 1 | |
trading = 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment