Forum: Poser Python Scripting


Subject: Useful Code Snippets

structure opened this issue on Jun 27, 2019 ยท 94 posts


structure posted Fri, 03 June 2022 at 12:57 PM Forum Coordinator

getting single characters from keystrokes and building a string from them * WINDOWS

from msvcrt import getche
from _toggle_keys import KEY_SYSTEM as toggle
from importlib import util

FOUND = util.find_spec("rich") is not None
if FOUND:
    from rich import print

hex_string = '0123456789ABCDEF'
chars = "#"
if not toggle.get_key_status(None, 20) == 1:
    toggle.toggle_key(None, 20, 1)  # turn off/on caps lock 0 = off, 1 = on

# getche displays characters as they are typed, getch does not display them
print("Incorrect hex characters will be substituted with a zero (0).")
print(f"Enter Your Hex Value (from {hex_string}) {chars}", end=" : ")
for x in range(1, 7):
    char = str(getche().decode('utf-8')).upper()
    chars += "0" if not char in hex_string else char

if not toggle.get_key_status(None, 20) == 0:
    toggle.toggle_key(None, 20, 0)  # turn off/on caps lock 0 = off, 1 = on

ps = f"[{chars}]" if FOUND else ""

print(f"\n\nYour Selected Color : {ps}{chars}\n")

Locked Out