【Follow me第二季第4期】非任务:制作一个黑神话碎玉池银行提款机
众所周知,黑神话第四章盘丝洞的碎玉池银行是那些灵韵、灵光点不足的玩家最爱去的地方。然而,刷取灵韵的过程往往枯燥且乏味,笔者就曾亲身经历,刷了一整晚才勉强将等级提升至200级。鉴于此,笔者突发奇想,是否能利用`Arduino® Nano RP2040 Connect`的`USB-HID`功能,将其模拟成一个键盘,从而自动执行刷灵韵的操作,以加速这一过程。(注:当然,更专业且高效的方法通常是通过专门的软件来实现自动化刷取,但本文旨在提供一种有趣的尝试和娱乐思路。)
## 首先先上演示视频
36fcf66e44de691aaee5e55e1b507a7a<br/>
## 准备
#### 软件准备:
1. 黑神话悟空
2. `Arduino® Nano RP2040 Connect`需要刷入`CircuitPython`,且导入`adafruit_hid`库
#### 属性准备:
1. 攻击力需大于90
2. 装备双头鼠,且点满变身攻击和双头鼠
3. q键必须切换到缩地
4. 最好带上仙禄和幽灯鬼
#### 安装CircuitPython
前往(https://circuitpython.org/board/arduino_nano_rp2040_connect/)下载固件,在短接`REC`和`GND`的情况下双击两下按钮,拖入下载好的`.uf2`文件即可。
#### 安装adafruit_hid库
前往(https://github.com/adafruit/Adafruit_CircuitPython_HID/releases/tag/6.1.3)下载(https://github.com/adafruit/Adafruit_CircuitPython_HID/releases/download/6.1.3/adafruit-circuitpython-hid-py-6.1.3.zip)解压后将lib目录下面的adafruit_hid移动到板载目录下即可
## 代码实现
```python
import json
import time
import board
import digitalio
import usb_hid
from adafruit_hid.keyboard import Keyboard
from adafruit_hid.keycode import Keycode
from adafruit_hid.keyboard_layout_us import KeyboardLayoutUS
keyboard_map = {
"a": 0x04, "A": 0x04,
"b": 0x05, "B": 0x05,
"c": 0x06, "C": 0x06,
"d": 0x07, "D": 0x07,
"e": 0x08, "E": 0x08,
"f": 0x09, "F": 0x09,
"g": 0x0A, "G": 0x0A,
"h": 0x0B, "H": 0x0B,
"i": 0x0C, "I": 0x0C,
"j": 0x0D, "J": 0x0D,
"k": 0x0E, "K": 0x0E,
"l": 0x0F, "L": 0x0F,
"m": 0x10, "M": 0x10,
"n": 0x11, "N": 0x11,
"o": 0x12, "O": 0x12,
"p": 0x13, "P": 0x13,
"q": 0x14, "Q": 0x14,
"r": 0x15, "R": 0x15,
"s": 0x16, "S": 0x16,
"t": 0x17, "T": 0x17,
"u": 0x18, "U": 0x18,
"v": 0x19, "V": 0x19,
"w": 0x1A, "W": 0x1A,
"x": 0x1B, "X": 0x1B,
"y": 0x1C, "Y": 0x1C,
"z": 0x1D, "Z": 0x1D,
"1": 0x1E, "!": 0x1E,
"2": 0x1F, "@": 0x1F,
"3": 0x20, "#": 0x20,
"4": 0x21, "$": 0x21,
"5": 0x22, "%": 0x22,
"6": 0x23, "^": 0x23,
"7": 0x24, "&": 0x24,
"8": 0x25, "*": 0x25,
"9": 0x26, "(": 0x26,
"0": 0x27, ")": 0x27,
"enter": 0x28,
"esc": 0x29,
"ctrl": 0xE0,
"alt": 0xE2
}
# 初始化键盘和布局
kbd = Keyboard(usb_hid.devices)
layout = KeyboardLayoutUS(kbd)
# 定义一个按键(例如,板载的一个按钮)
usrkey = digitalio.DigitalInOut(board.D2)# 假设GP24是板载按钮的引脚
usrkey.direction = digitalio.Direction.INPUT
usrkey.pull = digitalio.Pull.UP
def launch_notepad():
# 打开记事本(Windows系统)
kbd.send(Keycode.WINDOWS, Keycode.R)
time.sleep(0.3)
layout.write('notepad\n')
time.sleep(0.5)
def type_text(text):
# 输入文本
layout.write(text)
while True:
# 检查按钮是否被按下
if not usrkey.value:
while True:
with open("sycbank.txt", "r", encoding="utf-8") as f:
keys = f.readlines()
start_time = 0
last_time = 0
for key in keys:
try:
key = key.replace("\n", "")
key_json = json.loads(key)
except:
print(f"error: {key}")
continue
print(key_json, f"{key_json['time']:.2f}")
event_type = key_json["event_type"]
name = key_json["name"]
key_time = key_json["time"]
if last_time == 0:
last_time = key_time
if event_type == "start":
start_time = key_json["time"]
if event_type == "stop":
pass
else:
time.sleep(key_time - last_time)
print(key_time - last_time)
if event_type == "down":
kbd.press(keyboard_map)
elif event_type == "up":
kbd.release(keyboard_map)
last_time = key_time
time.sleep(2)
# 添加一个小的延时以避免过度占用CPU资源
time.sleep(0.1)
```
## 启用方法
1. 首先前往盘丝洞碎玉池
2. 在土地庙前按`E`后,点击鼠标右键返回后不要移动鼠标和控制键盘
3. 短接`D2`和`GND`即可
## 附件
板卡文件,可直接复制替换
<p>与实际相结合,最大化增加板子的利用率 </p>
<p>是不是搞个修改器会更快一些<img height="51" src="https://bbs.eeworld.com.cn/static/editor/plugins/hkemoji/sticker/facebook/biggrin.gif" width="48" /></p>
wangerxian 发表于 2024-12-2 13:12
是不是搞个修改器会更快一些
更专业且高效的方法通常是通过专门的软件来实现自动化刷取,但本文旨在提供一种有趣的尝试和娱乐思路 ICS 发表于 2024-12-2 16:09
更专业且高效的方法通常是通过专门的软件来实现自动化刷取,但本文旨在提供一种有趣的尝试和娱乐思路
<p>确实也是,这属于物理外挂。</p>
<p>逆天了!</p>
页:
[1]