Ejemplo n.º 1
0
 def code():
     import sys
     import ahkpy as ahk
     ahk.hotkey("F24", sys.exit)
     ctx = ahk.HotkeyContext(lambda: True)
     ctx.hotkey("F13", ahk.message_box, "Boop")
     print("ok00")
Ejemplo n.º 2
0
 def hotkeys():
     import ahkpy as ahk
     import sys
     ahk.hotkey("F24", sys.exit)
     ahk.hotkey("F13",
                object)  # object() cannot be converted to an AHK value
     print("ok00")
Ejemplo n.º 3
0
 def code():
     import ahkpy as ahk
     import sys
     ahk.hotkey("F24", sys.exit)
     ahk.hotkey("F13", ahk.message_box, "General", max_threads=2)
     ctx = ahk.windows.active_window_context(title="Python.ahk", text="General")
     ctx.hotkey("F13", ahk.message_box, "Context-specific")
     print("ok00")
Ejemplo n.º 4
0
 def code():
     import ahkpy as ahk
     import sys
     ahk.hotkey("F24", sys.exit)
     ctx = ahk.windows.window_context(title="Python.ahk - - ", match="contains")
     ctx.hotkey("F13", ahk.message_box, "Context-specific")
     ahk.Window(-1).exists  # This sets DetectHiddenWindows, On
     print("ok00")
Ejemplo n.º 5
0
 def code():
     import ahkpy as ahk
     import sys
     ahk.hotkey("F24", sys.exit)
     ahk.hotkey("F13", ahk.message_box, "Beep")
     ctx = ahk.HotkeyContext(
         lambda: ahk.windows.get_active(title="Python.ahk", text="Beep"))
     ctx.hotkey("F13", ahk.message_box, "Boop")
     print("ok00")
Ejemplo n.º 6
0
        def windows():
            import ahkpy as ahk
            import sys

            ahk.hotkey("F24", sys.exit)

            ahk.set_countdown(0.1, ahk.message_box, "win1", "ahkpy win1")
            ahk.set_countdown(0.3, ahk.message_box, "win2", "ahkpy win2")
            ahk.sleep(1)
            sys.exit()
Ejemplo n.º 7
0
    def code():
        import ahkpy as ahk
        import signal
        import sys
        ahk.hotkey("F24", sys.exit)

        def handler(*args):
            1 / 0

        signal.signal(signal.SIGINT, handler)
        print("ok00")
    def clipboards():
        import ahkpy as ahk
        import sys

        ahk.hotkey("F24", sys.exit)

        @ahk.on_clipboard_change()
        def objector():
            return object()

        print("ok00")
Ejemplo n.º 9
0
    def code():
        import ahkpy as ahk
        import sys

        ahk.hotkey("F24", lambda: None)  # Make the script persistent

        @ahk.set_countdown(0.1)
        def dong():
            print("Dong!")
            sys.exit()

        print("Ding!")
Ejemplo n.º 10
0
    def code():
        import ahkpy as ahk
        import os
        import sys

        ahk.hotkey("F24", sys.exit)

        @ahk.on_message(0x5555)
        def slow_handler():
            ahk.sleep(1)
            return 42

        print(os.getpid())
Ejemplo n.º 11
0
    def code():
        import ahkpy as ahk
        import sys

        ahk.hotkey("F13", print, "ok01")

        @ahk.hotkey("F14")
        def sus():
            ahk.suspend()
            print("ok02")

        ahk.set_countdown(0.5, sys.exit)
        print("ok00")
Ejemplo n.º 12
0
    def hotkeys():
        import ahkpy as ahk
        import sys

        ahk.hotkey("F24", sys.exit)

        @ahk.hotkey("F15")
        def block():
            with ahk.block_input():
                ahk.sleep(0.1)
            print("ok01")

        print("ok00")
Ejemplo n.º 13
0
    def code():
        import ahkpy as ahk
        import sys

        ahk.hotkey("F24", lambda: None)  # Make the script persistent

        @ahk.set_timer(0.1)
        def ding():
            print("Ding!")
            ding.stop()

        @ahk.set_countdown(0.5)
        def exit():
            sys.exit()
Ejemplo n.º 14
0
    def code():
        import ahkpy as ahk
        import sys
        ahk.hotkey("F24", sys.exit)

        @ahk.hotkey("F13")
        def _():
            # This executes after SystemExit was raised, but have not been
            # handled yet.
            pass

        ahk.send("{F13}")
        for _ in range(1_000_000):
            pass
Ejemplo n.º 15
0
    def hotkeys():
        import ahkpy as ahk
        import sys

        ahk.hotkey("F24", sys.exit)

        @ahk.hotkey("F15")
        def block():
            with ahk.block_input_while_sending():
                print("ok01")
                ahk.mouse_move(100, 100, relative_to="cursor", mode="event")
                ahk.mouse_move(-100, -100, relative_to="cursor", mode="event")
            print("ok02")

        print("ok00")
Ejemplo n.º 16
0
    def code():
        import runpy
        import sys
        import ahkpy as ahk

        ahk.hotkey("F24", sys.exit)
        ahk.hotkey("F13", ahk.message_box, "hello")

        print("ok00")

        sys.argv.append("8010")
        ahk.coop(
            runpy.run_module,
            mod_name="http.server",
            run_name="__main__",
            alter_sys=True,
        )
Ejemplo n.º 17
0
 def hotkeys():
     import ahkpy as ahk
     import sys
     ahk.hotkey("F24", sys.exit)
     ahk.hotkey("F14", lambda: ahk.message_box("F14 pressed"))
     ahk.hotkey("F15", lambda: ahk.message_box("F15 pressed"))
     print("ok00")
Ejemplo n.º 18
0
def test_exceptions():
    with pytest.raises(ValueError, match="key_name must not be blank"):
        ahk.hotkey(None)

    with pytest.raises(ValueError, match="key_name must not be blank"):
        ahk.hotkey("")

    with pytest.raises(TypeError, match="must be callable"):
        ahk.hotkey("^t", func="not callable")
Ejemplo n.º 19
0
 def code():
     import ahkpy as ahk
     import sys
     ahk.hotkey("F24", sys.exit)
     ahk.hotkey("F13", ahk.message_box, "General", max_threads=3)
     ahk.hotkey("F14", ahk.message_box, "Extra")
     ctx = ahk.windows.filter(title="Python.ahk").exclude(text="General").active_window_context()
     # If there are any active AutoHotkey windows beside General.
     ctx.hotkey("F13", ahk.message_box, "Context-specific")
     print("ok00")
Ejemplo n.º 20
0
def test_update_options(request):
    calls = []
    hk = ahk.hotkey("F13", calls.append, "F13")
    request.addfinalizer(hk.disable)
    ahk.send_event("{F13}", level=10)
    ahk.sleep(0)
    assert calls == ["F13"]

    calls.clear()
    hk.update(input_level=20)
    ahk.send_event("{F13}", level=10)
    ahk.sleep(0)
    assert calls == []

    ahk.send_event("{F13}", level=21)
    ahk.sleep(0)
    assert calls == ["F13"]
Ejemplo n.º 21
0
def test_reenable_on_init(request):
    hk = ahk.hotkey("F13", lambda: None)
    request.addfinalizer(hk.disable)
    hk.disable()

    called = False

    @ahk.hotkey("F13")
    def hk2():
        nonlocal called
        called = True

    request.addfinalizer(hk2.disable)

    assert not called
    ahk.send("{F13}", level=1)
    ahk.sleep(0)
    assert called
Ejemplo n.º 22
0
"""A variation of the Compose key."""

import ahkpy as ahk


def compose_send(keys, shift_keys=None):
    shift_pressed = ahk.is_key_pressed("Shift")
    ahk.wait_key_released(COMPOSE)
    if shift_keys and shift_pressed:
        ahk.send(shift_keys)
    else:
        ahk.send(keys)


COMPOSE = "CapsLock"

ahk.hotkey(f"{COMPOSE} & -", compose_send, "–", "—")  # dashes
ahk.hotkey(f"{COMPOSE} & Tab", compose_send, "{U+0009}")  # tab
ahk.hotkey(f"{COMPOSE} & 2", compose_send, "²")

# Combining characters
ahk.hotkey(f"{COMPOSE} & '", compose_send, "\u0301", "\u0308")  # á ä
ahk.hotkey(f"{COMPOSE} & 6", compose_send, "\u0302")  # â
ahk.hotkey(f"{COMPOSE} & `", compose_send, "\u0300", "\u0303")  # à ã
ahk.hotkey(f"{COMPOSE} & o", compose_send, "\u030A")  # å
Ejemplo n.º 23
0
 def code():
     import ahkpy as ahk
     import sys
     ahk.hotkey("F24", sys.exit)
     ahk.message_box("Hello from AutoHotkey.py", title="AutoHotkey")
Ejemplo n.º 24
0
        def window():
            import ahkpy as ahk
            import sys

            ahk.hotkey("F24", sys.exit)
            ahk.message_box("win1", title="ahkpy win1")
Ejemplo n.º 25
0
 def timers():
     import ahkpy as ahk
     import sys
     ahk.hotkey("F24", sys.exit)
     ahk.set_countdown(0.01, object)
     print("ok00")
Ejemplo n.º 26
0
import ahkpy as ahk

ahk.hotkey("AppsKey & a",
           lambda: ahk.windows.get_active().toggle_always_on_top())
ahk.hotkey("AppsKey & h", lambda: ahk.windows.get_active().minimize())
ahk.hotkey("AppsKey & Left", ahk.send, "#{Left}")
ahk.hotkey("AppsKey & Right", ahk.send, "#{Right}")
ahk.hotkey("AppsKey & Up", lambda: ahk.windows.get_active().toggle_maximized())
ahk.hotkey("AppsKey & Down",
           lambda: ahk.windows.get_active().toggle_minimized())
Ejemplo n.º 27
0
 def code():
     import ahkpy as ahk
     import sys
     ahk.hotkey("F24", sys.exit)
     print("ok00")
     "{proc}"
Ejemplo n.º 28
0
 def hotkeys():
     import ahkpy as ahk
     import sys
     ahk.hotkey("F24", sys.exit)
     ahk.hotkey("LButton", print, "ok01")
     ahk.hotkey("RButton", print, "ok02")
     ahk.hotkey("+LButton", print, "ok03")
     ahk.hotkey("WheelDown", print, "ok04")
     ahk.hotkey("WheelLeft", print, "ok05")
     print("ok00")
Ejemplo n.º 29
0
import ahkpy as ahk


def set_keyboard_layout(language_code):
    # This depends on having only two layouts in the Windows language list.
    # Inspired by GetCurrentLocale and ActiveWindow functions
    # https://github.com/BladeMight/Mahou/blob/9423423163/Mahou/Classes/Locales.cs#L20.
    # TODO: Handle Command Prompt windows.

    active_win = ahk.windows.get_active()
    focused_control = active_win.get_focused_control() or active_win
    if not focused_control:
        return

    thread_id = windll.user32.GetWindowThreadProcessId(focused_control.id, 0)
    if not thread_id:
        return

    current_layout = windll.user32.GetKeyboardLayout(thread_id)
    current_layout &= 0xffff
    if current_layout != language_code:
        ahk.send("#{Space}")


LANGID_ENGLISH_US = 0x0409
LANGID_RUSSIAN = 0x0419
# See more codes in the "Language Codes" article in AHK docs.

ahk.hotkey("CapsLock", set_keyboard_layout, LANGID_ENGLISH_US)
ahk.hotkey("+CapsLock", set_keyboard_layout, LANGID_RUSSIAN)
Ejemplo n.º 30
0
def test_hotkey_field(request):
    hk = ahk.hotkey("F13", lambda: None)
    request.addfinalizer(hk.disable)
    assert hk.key_name == "F13"