0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

ハリーポッター, スクリーン対策

Last updated at Posted at 2024-09-20
import random
import subprocess
import time

import pyautogui
import pygetwindow as gw

pyautogui.FAILSAFE = False

# ハリーポッターの名言
quotes = [
    "It is our choices, Harry, that show what we truly are, far more than our abilities.",
    "We've all got both light and dark inside us. What matters is the part we choose to act on.",
    "Happiness can be found even in the darkest of times, if one only remembers to turn on the light.",
    "You're just as sane as I am.",
    "Words are, in my not-so-humble opinion, our most inexhaustible source of magic.",
    "It does not do to dwell on dreams and forget to live.",
    "After all this time? Always.",
    "Fear of a name increases fear of the thing itself.",
    "To the well-organized mind, death is but the next great adventure.",
    "The ones that love us never really leave us.",
    "The world isn't split into good people and Death Eaters.",
    "Numbing the pain for a while will make it worse when you finally feel it.",
    "Every human life is worth the same, and worth saving.",
    "It matters not what someone is born, but what they grow to be.",
    "Do not pity the dead, Harry. Pity the living.",
    "We are only as strong as we are united, as weak as we are divided.",
    "Differences of habit and language are nothing at all if our aims are identical and our hearts are open.",
    "Of course it is happening inside your head, Harry, but why on earth should that mean that it is not real?",
    "We must all face the choice between what is right and what is easy.",
    "Understanding is the first step to acceptance, and only with acceptance can there be recovery.",
    "It's the unknown we fear when we look upon death and darkness, nothing more.",
    "It takes a great deal of bravery to stand up to our enemies, but just as much to stand up to our friends.",
    "You sort of start thinking anything’s possible if you’ve got enough nerve.",
    "Time will not slow down when something unpleasant lies ahead.",
    "Until the very end.",
    "The truth. It is a beautiful and terrible thing, and should therefore be treated with great caution.",
    "I am what I am, an’ I’m not ashamed.",
    "Curiosity is not a sin.... But we should exercise caution with our curiosity.",
    "What’s comin’ will come, an’ we’ll meet it when it does.",
    "Things we lose have a way of coming back to us in the end, if not always in the way we expect."
]

# メモ帳を開く
def open_text_editor():
    return subprocess.Popen(['notepad.exe'])

# 特定のウィンドウにフォーカスを合わせる
def focus_on_window(window_title):
    try:
        window = gw.getWindowsWithTitle(window_title)[0]
        if window is not None:
            window.activate()
            return True
    except Exception as e:
        print(f"Error focusing on window: {e}")
        return False

# すべてのテキストを選択し、削除する
def clear_text():
    pyautogui.hotkey('ctrl', 'a')
    pyautogui.press('backspace')

# 人間のようにランダムにマウスを移動する
def random_mouse_move():
    screen_width, screen_height = pyautogui.size()
    random_x = random.randint(0, screen_width)
    random_y = random.randint(0, screen_height)
    duration = random.uniform(1.0, 3.0)  # 1〜3秒かけてゆっくり移動
    pyautogui.moveTo(random_x, random_y, duration=duration)

# ランダムにキーを押して名言を入力する
def simulate_keypress():
    num_lines = random.randint(1, 5)
    for _ in range(num_lines):
        quote = random.choice(quotes)
        for char in quote:
            pyautogui.press(char)
            random_interval = random.uniform(0.001, 0.5)
            time.sleep(random_interval)
        pyautogui.press("enter")
        time.sleep(1)
        # マウスをランダムに移動
        random_mouse_move()
        # メモ帳に再度フォーカスを戻す
        focus_on_window('無題 - メモ帳')
    time.sleep(3)
    clear_text()

# メモ帳を開く
notepad_process = open_text_editor()

# エディタが開くのを待つ
time.sleep(5)

while True:
    # メモ帳ウィンドウにフォーカスを合わせる
    if focus_on_window('無題 - メモ帳'):
        simulate_keypress()
    else:
        print("Unable to find or focus on the Notepad window.")

    # 10秒待機
    time.sleep(10)
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?