Activate keys only in inactive window. Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
airm
Posts: 5
Joined: 29 Jul 2019, 04:00

Activate keys only in inactive window.

29 Jul 2019, 04:14

Hello forum,

I have a little problem. I have a mud client - mudlet (mudlet.exe) and defined numpad keys for move and other actions.
My goal is to make script which allow me to use these numpad keys only in mudlet.exe even if working in other window. For expample if im using browser, code editor, others and i press numpad 4, key is activate only in inactive mudlet.exe.
Last time i tried achive such result i had problem with infinity loop.
User avatar
rommmcek
Posts: 1475
Joined: 15 Aug 2014, 15:18

Re: Activate keys only in inactive window.

29 Jul 2019, 16:12

Try something like this:

Code: Select all

#IfWinActive, ahk_exe mudlet.exe
Numpad2::Down
Numpad8::Up
Numpad4::Left
Numpad6::Right
Numpad5::            ; just a peseudo code
    Send, ^{Home}
    Send, ^+{PgDn}
Return
#IfWinActive
airm
Posts: 5
Joined: 29 Jul 2019, 04:00

Re: Activate keys only in inactive window.

30 Jul 2019, 06:59

It doesnt work when I am in other window focused.
User avatar
rommmcek
Posts: 1475
Joined: 15 Aug 2014, 15:18

Re: Activate keys only in inactive window.

30 Jul 2019, 07:32

To make work Hotkeys in multiple windows see here.
To make work Hotkeys in all windows don't use #IfWinActive commands at all!
bye!
User avatar
rommmcek
Posts: 1475
Joined: 15 Aug 2014, 15:18

Re: Activate keys only in inactive window.

30 Jul 2019, 14:28

OMG! I didn't read attentively! If you want Hotkeys to work in an inactive window then use something like this:

Code: Select all

#IfWinExist, ahk_exe mudlet.exe
Numpad2::ControlSend, mudletCtrl, {Down}, ahk_exe mudlet.exe
Numpad8::ControlSend, mudletCtrl, {Up}, ahk_exe mudlet.exe
Numpad4::ControlSend, mudletCtrl, {Left}, ahk_exe mudlet.exe
Numpad6::ControlSend, mudletCtrl, {Right}, ahk_exe mudlet.exe
Numpad5::            ; just a peseudo code
    ControlSend, mudletCtrl, ^{Home}, ahk_exe mudlet.exe
    ControlSend, mudletCtrl, ^+{PgDn}, ahk_exe mudlet.exe
Return
#IfWinExist
Note: In place of "mudletCtrl" you have to determin and put the real ClassNN of your mudlet app.
airm
Posts: 5
Joined: 29 Jul 2019, 04:00

Re: Activate keys only in inactive window.

04 Aug 2019, 14:52

Dont know why but examples above dont work for me.

I have other solution but isnt as fast as it could (but works):

Code: Select all

Numpad4::
    WinGetActiveTitle, currActiveTitle
    WinGetClass, currActiveClass
    WinActivate, Arkadia - Mudlet 3.21.0 ahk_class Qt5QWindowIcon
    Send w{Enter}
    WinActivate, %currActiveTitle%
    return
User avatar
rommmcek
Posts: 1475
Joined: 15 Aug 2014, 15:18

Re: Activate keys only in inactive window.

04 Aug 2019, 15:16

That's a good news. Here is my little modification:

Code: Select all

Numpad4::
    WinGetActiveTitle, currActiveTitle
    ;WinGetClass, currActiveClass ; you don't use that in the code below
    WinActivate, Arkadia - Mudlet 3.21.0 ahk_class Qt5QWindowIcon
    WinWaitActive, Arkadia - Mudlet 3.21.0 ahk_class Qt5QWindowIcon ; needed if CPU under load
    Send w{Enter}
    WinActivate, %currActiveTitle%
return
if that works then maybe this could too, if you didn't try it already:

Code: Select all

Numpad4::ControlSend,, w{Enter}, Arkadia - Mudlet 3.21.0 ahk_class Qt5QWindowIconreturn
airm
Posts: 5
Joined: 29 Jul 2019, 04:00

Re: Activate keys only in inactive window.

04 Aug 2019, 17:34

Thx, first one works fine but like in my example too, when i press fast f.e. numpad 4 and then numpad 2 (s{Enter}), it doesnt back to previous active window. For sure after pressing numpad4 it is getting Mudlet as active window. Only when i do it fast (0.2s or smth). Is there any fast solution for such behaviour?

Second example doesnt work.
User avatar
Masonjar13
Posts: 1555
Joined: 20 Jul 2014, 10:16
Location: Не Россия
Contact:

Re: Activate keys only in inactive window.  Topic is solved

04 Aug 2019, 19:12

The reason it doesn't work when pressed quickly is because it's getting the active window again, which would be the mudlet window. If you use critical, it should buffer (or ignore) the second activation, rather than interrupt the currently running instance. If it doesn't, then consider using the hotkey command to disable the hotkey after called, then re-enable just before the return.
OS: Windows 10 Pro | Editor: Notepad++
My Personal Function Library | Old Build - New Build
airm
Posts: 5
Joined: 29 Jul 2019, 04:00

Re: Activate keys only in inactive window.

07 Aug 2019, 06:00

Masonjar13 wrote: The reason it doesn't work when pressed quickly is because it's getting the active window again, which would be the mudlet window. If you use critical, it should buffer (or ignore) the second activation, rather than interrupt the currently running instance. If it doesn't, then consider using the hotkey command to disable the hotkey after called, then re-enable just before the return.
thx, Critical works fine.

Code: Select all

#SingleInstance, force

setTask(task){
    Critical
    WinGetActiveTitle, currActiveTitle
    WinActivate, Arkadia - Mudlet 3.21.0 ahk_class Qt5QWindowIcon
    WinWaitActive, Arkadia - Mudlet 3.21.0 ahk_class Qt5QWindowIcon ; needed if CPU under load
    Send %task%
    WinActivate, %currActiveTitle%
}

Numpad4::setTask("w{Enter}")
Numpad2::setTask("s{Enter}")

^x::ExitApp

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Descolada, downstairs, filipemb, Google [Bot], OrangeCat, roysubs and 156 guests