level 1
from flask import *
app = Flask("ScratchExtension")
res = ""
shift = "0"
BS = "0"
ctrl = "0"
import keyboard
def abc(x):
a = keyboard.KeyboardEvent('down', 28, 'shift')
b = keyboard.KeyboardEvent('down', 28, 'backspace')
c = keyboard.KeyboardEvent('down', 28, 'ctrl')
#如果想知道按键的值可以用hook绑定所有事件后,输出x.scan_code即可
global shift, BS, ctrl
if x.event_type == 'down' and x.name == a.name:
shift = "1"
if x.event_type == 'up' and x.name == a.name:
shift = "0"
if x.event_type == 'down' and x.name == b.name:
BS = "1"
if x.event_type == 'up' and x.name == b.name:
BS = "0"
if x.event_type == 'down' and x.name == c.name:
ctrl = "1"
if x.event_type == 'up' and x.name == c.name:
ctrl = "0"
keyboard.hook(abc)
@app.route("/poll")
def poll_var():
import keyboard
global shift, BS, ctrl
return f"key_shift {str(shift)}\n" \
f"key_backspace {str(BS)}\n" \
f"key_ctrl {str(ctrl)}\n"
@app.errorhandler(404)
def Error404(a):
uri = request.path
print(uri)
req = uri.split("/")[1:]
app.run(
host = "0.0.0.0",
port = 13579,
debug = True
)
Python代码
scratch要导入s2e
s2e
{
"extensionName": "Keys Detect",
"extensionPort": 13579,
"blockSpecs":[
["r", "Shift Key", "key_shift"],
["r", "Backspace Key", "key_backspace"],
["r", "Ctrl Key", "key_ctrl"]
]
}
2019年09月13日 01点09分
4
挖坟,封禁一天
2019年09月13日 02点09分