12/02/19 07:13:28.42
>>551を盛大にパクってWin32APIのヘルプ見つつ10分ほど
cmd.exeで動くバージョン
import sys
from random import randint
from string import ascii_letters, digits, punctuation
from ctypes import *
class CONSOLE_SCREEN_BUFFER_INFO(Structure):
_fields_ = [('w', c_short), ('h', c_short), ('x', c_short), ('y', c_short),
('a', c_int), ('l', c_short), ('t', c_short), ('r', c_short), ('b', c_short),
('maxw', c_short), ('maxh', c_short)]
b = CONSOLE_SCREEN_BUFFER_INFO()
h = windll.kernel32.GetStdHandle(-11)
c = windll.kernel32.GetConsoleScreenBufferInfo(h, byref(b))
windll.kernel32.SetConsoleTextAttribute(h, 10) # green
chars = ascii_letters + digits + punctuation
chars += ' ' * len(chars)
size = len(chars)
while True: sys.stdout.write(chars[randint(0, size - 1)])
windll.kernel32.SetConsoleTextAttribute(h, b.a) # reset