Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Send Key To Multiple Inactive Game Windows



  • Please log in to reply
7 replies to this topic
Steelice
  • Members
  • 6 posts
  • Last active: Jul 23 2015 05:00 AM
  • Joined: 07 Jan 2015

I want to run multiple games of Trove and have them jump every once and a while to avoid going AFK. So far i have -

 

#ifWinActive Trove
{
Loop
{
Send {Space}
Sleep 10000
}
}
return

 

which works but it also spamms spacebar when the Trove window isn't even active. Anyone know why? Also can you give me a script that will send space to the inactive game windows?

 

If this helps: 

>>>>>>>>>>( Window Title & Class )<<<<<<<<<<<

Trove
ahk_class SDL_app
 
 
p.s- I know you have to use Controlsend but i have no idea what that even means or how to code at all....


Masonjar13
  • Members
  • 1517 posts
  • Last active:
  • Joined: 16 Sep 2012
✓  Best Answer

ControlSend [, Control, Keys, WinTitle, WinText, ExcludeTitle, ExcludeText]

In this case, there is no control, we're just sending to the window, so we'll leave it blank. The key is space. For the WinTitle, we'll use the class, since it's typically more consistent. Put it together: ControlSend,, {Space}, ahk_class SDL_app

If we have multiple windows to send to, we need to have another form of identification for them. We can use WinGet for this.

WinGet, winList, List, ahk_class SDL_app ; grab all window handles (hwnds) that match the class. Hwnds, or window ID's, are unique in that no two can have the same ID at the same time.
Loop % winList ; now contains the number of windows matched
    ControlSend,, {Space},% "ahk_id " winList%a_index% ; starting a parameter with % forces expression syntax. This loop structure effectively sends a space to all windows that previously matched the class name.

 

And putting it all together, along with a timer (pre-directives (specified by a preceding #) only affect hotkeys and hotstrings). Checking if it's active isn't needed here; if WinGet finds no windows, it will loop for 0 iterations.

#Persistent
SetTimer, noafk, 10000 ; run label "noafk" at 10000 ms intervals
return
 
noafk:
WinGet, winList, List, ahk_class SDL_app
Loop % winList
    ControlSend,, {Space},% "ahk_id " winList%a_index%
return

 

It's often games don't accept ControlSend, so don't worry if this doesn't readily work.


OS: Windows 7 Ultimate / Windows 8.1 Pro | Editor: Notepad++


Steelice
  • Members
  • 6 posts
  • Last active: Jul 23 2015 05:00 AM
  • Joined: 07 Jan 2015

Wow you are amazing! It works perfectly! Quick reply too, perfect code, you are the best! :D



Steelice
  • Members
  • 6 posts
  • Last active: Jul 23 2015 05:00 AM
  • Joined: 07 Jan 2015

Is there a code to make all the windows hold down a key for a couple seconds every 15 seconds?

Like 15 seconds goes by

Hold e for 5 seconds

15 seconds later,

hold e for 5 seconds



Masonjar13
  • Members
  • 1517 posts
  • Last active:
  • Joined: 16 Sep 2012

http://ahkscript.org...ding_Down_a_Key
You can essentially copy and paste the example given, then replace the key names.


OS: Windows 7 Ultimate / Windows 8.1 Pro | Editor: Notepad++


Steelice
  • Members
  • 6 posts
  • Last active: Jul 23 2015 05:00 AM
  • Joined: 07 Jan 2015

I'm trying this - 

 

#Persistent
SetTimer, noafk, 1000 ; run label "noafk" at 1000 ms intervals
return
 
noafk:
WinGet, winList, List, ahk_class SDL_app
Loop % winList
    ControlSend,, {Space},% "ahk_id " winList%a_index%
    ControlSend,, {b},% "ahk_id " winList%a_index%
    
return
 
specifically "ControlSend,, {b},% "ahk_id " winList%a_index%"
And the b isn't getting sent (Either is any other letter or number i type.) What am i doing wrong, i want to send it to an inactive window as well. ),: 


idontcheatihotkey
  • Members
  • 20 posts
  • Last active: Jan 22 2017 03:38 AM
  • Joined: 16 Jan 2015

if you want to hold down b it would probably be something like this.

ControlSend, , b {down} %winList%a_index%     ;Sending b down

sleep 15000    ;amount of time you want it down

ControlSend, , b {up} %winList%a_index%     ;Releasing it

 

I don't know if I did this "%winList%a_index%" correctly because I haven't used WinGet much. 

I am just rather new to ahk over all.



FunnyO
  • Members
  • 61 posts
  • Last active: Aug 03 2015 05:06 PM
  • Joined: 04 Apr 2015

you dont need to WinGet at all. It works without it.