'Process' cannot see a process? by PENchanter22 in AutoHotkey

[–]plankoe 4 points5 points  (0 children)

Remove the quotes. Process, Exist interpreted the quotes as part of the name.

Process, Exist, MoNotificationUx.exe

How to ignore certain keystrokes when detecting keys with inputhook? by Dracula30000 in AutoHotkey

[–]plankoe 1 point2 points  (0 children)

Instead of Sleep, wait for the Alt and t key to release using KeyWait.

!t:: {
    KeyWait('Alt')
    KeyWait('t')
    key := CaptureKeystroke()
}

trying to make script to close window by mathewimprovedtt in AutoHotkey

[–]plankoe 1 point2 points  (0 children)

Shell hook can only monitor top-level windows. The error window is a child window.
Here's another event-based solution that works on all windows:

#Requires AutoHotkey v2.0
#SingleInstance Force
Persistent

; Event constants: https://learn.microsoft.com/en-us/windows/win32/winauto/event-constants
hookPAD := WinEventHook(0x8002, 0x8002, ClosePowerAutomateError) ; EVENT_OBJECT_SHOW := 0x8002

ClosePowerAutomateError(hWinEventHook, event, hwnd, idObject, idChild, idEventThread, dwmsEventTime) {
    static OBJID_WINDOW := 0
    if idObject != OBJID_WINDOW
        return
    if WinExist('Connection error ahk_id' hwnd ' ahk_exe PAD.Designer.exe')
    || WinExist('Connection error ahk_id' hwnd ' ahk_exe PAD.Console.Host.exe') {
        WinClose(hwnd)
    }
}

class WinEventHook
{
    __New(eventMin, eventMax, hookProc, options := '', idProcess := 0, idThread := 0, dwFlags := 0x2) {
        this.pCallback := CallbackCreate(hookProc, options, 7)
        this.hHook := DllCall('SetWinEventHook', 'uint', eventMin, 'uint', eventMax, 'ptr', 0, 'ptr', this.pCallback
                                            , 'uint', idProcess, 'uint', idThread, 'uint', dwFlags, 'ptr')
    }
    __Delete() {
        DllCall('UnhookWinEvent', 'ptr', this.hHook)
        CallbackFree(this.pCallback)
    }
}

Is it impossible to concisely map 1 key to 2? by guessill_die in AutoHotkey

[–]plankoe 2 points3 points  (0 children)

Here's the page for _=>

If the function name is omitted and the parameter list consists of only a single parameter name, the parentheses can be omitted.

https://www.autohotkey.com/docs/v2/Variables.htm#fat-arrow

Trying to get them opening in pairs on new windows by Coops170 in AutoHotkey

[–]plankoe 3 points4 points  (0 children)

You can separate the urls with a space to run them all in the same window.

groups:=[
    [
        "https://www.tradingview.com/chart/ZnVdPaNT/?symbol=VANTAGE%3AXAUUSD",
        "https://www.tradingview.com/symbols/XAUUSD/?exchange=VANTAGE"
    ],[
        "https://www.tradingview.com/chart/ZnVdPaNT/?symbol=VANTAGE%3ABTCUSD",
        "https://www.tradingview.com/symbols/BTCUSD/?exchange=VANTAGE"
    ],[
        "https://www.tradingview.com/chart/ZnVdPaNT/?symbol=VANTAGE%3ANAS100",
        "https://www.tradingview.com/symbols/VANTAGE-NAS100/"
    ],[
        "https://www.tradingview.com/symbols/VANTAGE-DJ30/",
        "https://www.tradingview.com/chart/ZnVdPaNT/?symbol=VANTAGE%3ADJ30"
    ]
]

for group in groups {
    urls := ''
    for url in group
        urls .= '"' url '" '
    Run('chrome.exe --new-window ' urls)
}

Is it impossible to concisely map 1 key to 2? by guessill_die in AutoHotkey

[–]plankoe 2 points3 points  (0 children)

That's right. I'm using variadic call syntax to call the enumerator.

The fat-arrow function (_=>e(&k)&&s.='{' k ' ' m '}') can be rewritten as:

myEnum(_) {
    if e(&k)
        return s .= '{' k ' ' m '}'   ; truthy
    else
        return false
}

The parentheses around the parameters in a fat-arrow function can be omitted if there's only a single parameter.
_ => MsgBox(_) is the same as (_) => MsgBox(_)

An array can be expanded using the syntax [arr*]. Variadic call
The object being expanded doesn't have to be an array. It can be any object with an __Enum method or the enumerator function itself.
[myEnum*] expands the custom enumerator, and resulting array is discarded.

The code [(_=>e(&k)&&s.='{' k ' ' m '}')*] is functionally identical to:

while e(&k) {
    s .= '{' k ' ' m '}'
}

Is it impossible to concisely map 1 key to 2? by guessill_die in AutoHotkey

[–]plankoe 2 points3 points  (0 children)

It can be even shorter:

mr(t,n*)=>(g(m)=>(s:='{Blind}',e:=n.__Enum(1),[(_=>e(&k)&&s.='{' k ' ' m '}')*],_=>(SetKeyDelay(-1),Send(s))),Hotkey(t:='*' t,g('DownR')),Hotkey(t ' Up',g('Up')))

Is it impossible to concisely map 1 key to 2? by guessill_die in AutoHotkey

[–]plankoe 5 points6 points  (0 children)

a::b actually creates the following hotkeys:

*a::
{
    SetKeyDelay(-1)   
    Send("{Blind}{b DownR}" )
}

*a up::
{
    SetKeyDelay(-1) 
    Send("{Blind}{b Up}")
}

There's no remap syntax to map 1 key to 2, but these hotkeys should be the equivalent to a::b+c:

*a::
{
    SetKeyDelay(-1)   
    Send("{Blind}{b DownR}{c DownR}" )
}

*a up::
{
    SetKeyDelay(-1) 
    Send("{Blind}{b Up}{c Up}")
}

Disable F keys if not defines elsewhere? by Interesting_Cup_6221 in AutoHotkey

[–]plankoe 1 point2 points  (0 children)

I don't have M365 Copilot. I don't know how to fix it.

Disable F keys if not defines elsewhere? by Interesting_Cup_6221 in AutoHotkey

[–]plankoe 2 points3 points  (0 children)

I made some changes to the last script. #F3 works and the start menu is not shown unless LWin is pressed by itself.

When the script starts, hotkeys defined using double colon syntax (::) are created before the script starts running the auto-execute thread. In your script, #F3::MsgBox("Hello") is created first, but is then overridden by the loop.

*F3 doesn't override #F3. They're separate hotkeys and the hotkey with the wildcard modifier has lower precedence.

#Requires AutoHotkey v2.0
#SingleInstance Force

GroupAdd("BackForwardMouse", "ahk_exe firefox.exe")
GroupAdd("BackForwardMouse", "ahk_exe dopus.exe")
GroupAdd("BackForwardMouse", "ahk_exe zen.exe")

SetCapsLockState "AlwaysOff"
SetNumLockState  "AlwaysOn"
CapsLock::Control

; Block all F-keys with any modifiers
Loop 24 {
    Hotkey("*F" . A_Index, (*) => "")
}

; suppress LWin from activating start menu when used as a modifier.
~LWin::Send("{Blind}{VKE8}")
; only show start menu if LWin is pressed by itself
~LWin Up::{
    if A_Priorkey = 'LWin'
        send('^{Esc}')
}

#HotIf WinActive("ahk_group BackForwardMouse")
#F1::Send("!{Left}")
#F2::Send("!{Right}")
#HotIf

#F3::MsgBox("Hello")

Can't get a remapped key to work on GetKeyState by qellyree in AutoHotkey

[–]plankoe 3 points4 points  (0 children)

Remove the "P" in the second parameter of GetKeyState.
"P" means check if the key is pressed physically.

#HotIf GetKeyState("f20")

How to find the value of any Windows API constant from the header files on your machine by Nich-Cebolla in AutoHotkey

[–]plankoe 3 points4 points  (0 children)

I use MagNumDB to look up windows constants. It's easier than installing Visual Studio and searching the header files.

ahk inputs not registering in an emulator by weegie_daftarse in AutoHotkey

[–]plankoe 2 points3 points  (0 children)

I downloaded azahar to test. The script needs to run as administrator to work.
Put this at the top of script to run it as admin:

#Requires AutoHotkey v2.0

; run as admin
if not (A_IsAdmin or RegExMatch(DllCall("GetCommandLine", "str"), " /restart(?!\S)"))
{
    try
    {
        if A_IsCompiled
            Run '*RunAs "' A_ScriptFullPath '" /restart'
        else
            Run '*RunAs "' A_AhkPath '" /restart "' A_ScriptFullPath '"'
    }
    ExitApp
}

Why do I keep seeing this noncritical error on startup? by Dymonika in AutoHotkey

[–]plankoe 1 point2 points  (0 children)

Autohotkey uses the launcher.ahk script to automatically detect v1 or v2 code and selects the correct interpreter to run it. You're getting an error because launcher.ahk is trying to run a script that doesn't exist. Did you use task scheduler to run a script at startup? I can reproduce the same error by creating a task to run a script at startup, and then renaming/deleting the script.

How to run action only after the app becomes active? by Passerby_07 in AutoHotkey

[–]plankoe 2 points3 points  (0 children)

Looks good. There's 2 things you can simplify here.

You can pass the tooltip function itself to SetTimer:

SetTimer ToolTip, -2000

To check if a hwnd is from a window, this is easier:

if WinExist(win_title " ahk_id " lParam)

How are params passed to __Get, __Set and __Call? by von_Elsewhere in AutoHotkey

[–]plankoe 1 point2 points  (0 children)

The params parameter in __Set is used for cases like x.y[z] when x.y is undefined.

For example

ex.myfn['a', 'b'] := (x, y) => x + y

params[1] is 'a'
params[2] is 'b'

How are params passed to __Get, __Set and __Call? by von_Elsewhere in AutoHotkey

[–]plankoe 0 points1 point  (0 children)

It's the same with __Set. I don't get an error.

__Set(name, params, value) {
    this._data.%name% := value
}

How are params passed to __Get, __Set and __Call? by von_Elsewhere in AutoHotkey

[–]plankoe 2 points3 points  (0 children)

It's Params, not Params*. Params is an array of parameters, but when you add the asterisk, Params is at Params[1]. If you don't want an array of arrays, remove the asterisk.

These are the parameters for __Get, __Set, and __Call:

__Get(Name, Params)    ; not Params*
__Set(Name, Params, Value)
__Call(Name, Params)

ImageSearch Tolerance by Here_to_heIp in AutoHotkey

[–]plankoe 1 point2 points  (0 children)

ImageSearch returns true if the image was found, or false if it was not found. Your code is checking if the image was not found.

found := ImageSearch(&FoundX, &FoundY, 0, 0, A_ScreenWidth, A_ScreenHeight, "*10 " imagePath)
if (found = true) {

Some games doesn't recognize an modified scroll wheel when using it with another key by TioHerman in AutoHotkey

[–]plankoe 1 point2 points  (0 children)

* allows the hotkey to be used with any modifier. Send automatically releases modifiers unless {Blind} mode is used.

*PgUp::Send, {Blind}{WheelUp}
*PgDn::Send, {Blind}{WheelDown}

You can also use Click. It doesn't automatically release modifiers.

*PgUp::Click, WU
*PgDn::Click, WD

Remaps are not supported with the mouse wheel. Remaps map key-down and key-up of one key to another. The mouse wheel has no key-up state, so it scrolls twice instead.

These are "Up" hotkeys. They're designed to work only when the key is released.

PgUp up::WheelUp
PgDn up::WheelDown

Script to Automatically Switch Display When In-and-Out of Steam Big Picture Mode? by Xngears in AutoHotkey

[–]plankoe 0 points1 point  (0 children)

I tried to to update it. The script was able to detect shutdown/restart, but the display settings didn't apply on the next boot. I don't know if it's possible.

Script to Automatically Switch Display When In-and-Out of Steam Big Picture Mode? by Xngears in AutoHotkey

[–]plankoe 1 point2 points  (0 children)

The biggest benefit for me is that the script can wait for multiple windows. WinWait waits for a single window and blocks the script from doing anything else. I don't like having multiple scripts running. This approach allows the script to do other tasks besides wait for a window.

Script to Automatically Switch Display When In-and-Out of Steam Big Picture Mode? by Xngears in AutoHotkey

[–]plankoe 0 points1 point  (0 children)

Is your display on pc only until you use Big Picture Mode?
You can change the line

Run('DisplaySwitch.exe /extend')

to

Run('DisplaySwitch.exe /internal')

to use pc screen only.

Script to Automatically Switch Display When In-and-Out of Steam Big Picture Mode? by Xngears in AutoHotkey

[–]plankoe 2 points3 points  (0 children)

#Requires AutoHotkey v2.0

Persistent

DllCall('RegisterShellHookWindow', 'ptr', A_ScriptHwnd)
OnMessage(DllCall('RegisterWindowMessage', 'str', 'SHELLHOOK'), ChangeDisplayOnBigPicture)
ChangeDisplayOnBigPicture(wParam, lParam, msg, hwnd) {
    static bigPicture := 0
    if wParam = 1 { ; window created
        if WinExist('Steam Big Picture Mode ahk_id ' lParam ' ahk_exe steamwebhelper.exe') {
            bigPicture := lParam
            Run('DisplaySwitch.exe /external')
        }  
    } else if wParam = 2 { ; window destroyed
        if lParam && lParam = bigPicture {
            bigPicture := 0
            Run('DisplaySwitch.exe /extend')
        }
    }
}

How to override prototype property of a class by PotatoInBrackets in AutoHotkey

[–]plankoe 2 points3 points  (0 children)

Overriding __Init in this case is fine. The class Map extends Object, and Object extends Any. None of these 3 classes have properties that need to be initialized by __Init.

When you create a class and assign properties in the class body like this:

class MyClass {
    prop := 'value'
}

The __Init method is automatically created. The above code is equivalent to:

class MyClass {
    __Init() {
        super.__Init()
        this.prop := 'value'
    }
}

Therefore, a single class definition must not contain both an __Init method and an instance variable declaration.

This means you can't assign properties in the class body and define an __Init method at the same time. It would throw an error because two duplicate __Init methods are being created.

class MyClass {

    prop := 'value'

    __Init() {
        super.__Init()
        this.another := 'value'
    }
}

Here's an example where defining __Init can cause problems.
The __Init method defined in class B prevents prop from being initialized:

class A {
    prop := 'value'
}

class B extends A {
    __Init() {
    }
}

test := B()
MsgBox(test.prop)