Implement Loop in the Background.

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
TimeToHotkey
Posts: 1
Joined: 17 Aug 2018, 05:57

Implement Loop in the Background.

17 Aug 2018, 06:18

Hello i need some help with this code.
Actually it works like this -> You press Ctrl + Left and in my Programm it press Ctrl + Right in the background . But now i need that this code press every time Ctrl + Right in a Loop.
i try to change this code:

Code: Select all

#Persistent
SetTimer, PressTheKey, 1000
Return

PressTheKey:
Send, ^{right}
Return
with this code:

Code: Select all

keyMap:={ "^left"  :"^{right}"}

Hotkey IfWinExist, % title
for pressedkey,sendkey in keyMap {
    act:=func("sendToInfinity").bind(sendkey)
    Hotkey % pressedkey, % act, On
}
return
But i always failed.
Here is the Main code:

Code: Select all

DetectHiddenWindows On
sendMode Input

title:="ahk_exe Infinity.exe"

keyMap:={ "^left"  :"^{right}"}

Hotkey IfWinExist, % title
for pressedkey,sendkey in keyMap {
    act:=func("sendToInfinity").bind(sendkey)
    Hotkey % pressedkey, % act, On
}
return

sendToInfinity(key){
    WinGet, winList, List, % title
    Loop, % winList {
        ControlFocus , , % "ahk_id " winList%A_Index%
        ControlSend, , % key, % "ahk_id " winList%A_Index%
    }
    return
}


I would be grateful if someone could help me.
User avatar
Scr1pter
Posts: 1272
Joined: 06 Aug 2017, 08:21
Location: Germany

Re: Implement Loop in the Background.

17 Aug 2018, 15:52

Hi,

Maybe it doesn't need to be that complicated.
As far as I understood:
If your target application is NOT and foreground and you press Ctrl+Left,
Ctrl+Right should be sent to your target application.

I tested it with Notepad++ and it worked flawlessly.

Code: Select all

#if not WinActive("ahk_class Notepad++")
^Left::
ControlSend, Scintilla1, ^{Right}, ahk_class Notepad++
return
Of course you will have to change the class and remove the Scintilla1.
Use this code if you don't know the class name of your target application.

Code: Select all

F1::
WinGetClass, class, A
Clipboard = #if WinActive("ahk_class %class%")
MsgBox, Class of current window is "%class%".
return
Your application must be in foreground, then you just press F1.

P.S: Before you start looping anything, check if it generally works.

Regards
Please use [code][/code] when posting code!
Keyboard: Logitech G PRO - Mouse: Logitech G502 LS - OS: Windows 10 Pro 64 Bit - AHK version: 1.1.33.09

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: aitaixy, dipahk and 207 guests