Prevent Star Citizen from disconnecting while idle Topic is solved

Ask gaming related questions (AHK v1.1 and older)
User avatar
xvz
Posts: 33
Joined: 20 Feb 2023, 15:15

Prevent Star Citizen from disconnecting while idle

Post by xvz » 20 Feb 2023, 15:57

At present, Star Citizen disconnects when it is idle for something like 10 or 15 minutes. I have used a mouse macro to effectively avoid disconnection, although that is separate from AHK and has its limitations, it also requires keeping the Star Citizen window active and as the focused window.

I would like to use AHK to ensure that Star Citizen remains connected even while other windows are active and receiving focus.

Here is an example walkthrough of the manual steps that happen:

1. Start the RSI Launcher application
2. In that window, select Launch Game then Acknowledge
3. Then the main menu of Star Citizen launches
4. Select Persistent Universe then Enter Star Citizen Universe
5. Wait for the loading screen, then the character wakes up

It would be great to have a script to take care of 1.-4., although right now the main interest is in avoiding being idle from causing disconnects after the character wakes up in the verse. The main focus here is after step 5. in the above process.

As I understand it, anything can be done from within the verse with the character to ensure that it does not go idle. It could simply open the mobiglas (a wristwatch type device), wait a couple minutes, close it, wait a couple minutes, open it again, and loop it. Both open and close for that mobiglas device are done with the F1 key. The character could also jump in place (space bar) or walk around (wasd keys), basically anything will probably be okay.

How would I make my character remain active while the Star Citizen window is in the background and I am actively using other windows?

I looked up some possibilities and found mentions of options like something called "DetectHiddenWindows, On", "WinGet", "WinWait", using "Loop" options, however they were from several years ago. I also found this, from a fear years ago in this forum, but it uses a web browser instead:

Code: Select all

DetectHiddenWindows, On
SetTitleMatchMode, 2

WinGetClass, WinClass, Mozilla Firefox

loop {
SetTimer, GetFocus, 200								; Makes the browser gain focus every 200 ms
}
return

GetFocus:
ControlFocus,, Mozilla Firefox
Return


F3::
	loop 5
	{
		Controlsend,, {Down down}, ahk_class %WinClass%
		Sleep 200
		Controlsend,, {Down up}, ahk_class %WinClass%
	}

I wonder if I could make a variation of that, maybe like this:

Code: Select all

DetectHiddenWindows, On
SetTitleMatchMode, 2

WinGetClass, WinClass, Star Citizen

loop {
SetTimer, GetFocus, 300000 ; Makes Star Citizen gain focus every 5 minutes
}
return

GetFocus:
ControlFocus,, Star Citizen
Return

F1::
	loop 1
	{
		Controlsend,, {F1 down}, ahk_class %WinClass%
		Sleep 100
		Controlsend,, {F1 up}, ahk_class %WinClass%
	}

Maybe the AHK script for Star Citizen would need to be started after the character wakes up in the verse, or maybe it can be started before even starting the RSI Launcher, I don't know.

It looks like the example above might put Star Citizen in the foreground, but the intention is for it to remain in the background, without interrupting tasks in other windows.

The tinkering around with the above example is probably messing it all up.

Are there any example scripts and specific sections of documentation that would help achieve this?

User avatar
DuckingQuack
Posts: 219
Joined: 20 Jan 2023, 18:20

Re: Prevent Star Citizen from disconnecting while idle

Post by DuckingQuack » 20 Feb 2023, 20:58

Hey! I'd love to assist with your mega-script. I don't play star citizen, but I do enjoy making scripts for games and helping people... so this will be lots of fun.
It will be easier to iron out all the details if we have a faster method of sending messages. I use Discord, DuckingQuack#6926, please hit me up so we can chat about the script.

Until then, here's a script that might teach you some basics and take care of the main request of this thread. Please note that this script lacks a pause, only a start button and an exit button.
Instructions for use: (1)Get game to state ready for idling. (2)Press F11. (3)Go do whatever, tab out, work on stuff... anything.
If this doesn't operate as expected, then we can troubleshoot it!

Code: Select all

#Requires AutoHotkey v2.0  ; Made by DuckingQuack. HMU on Discord: DuckingQuack#6926
#SingleInstance Force      ; This script is not guaranteed to operate in all games. https://www.autohotkey.com/board/topic/111737-how-to-make-ahk-work-in-most-games-the-basics/
F12::ExitApp   ; This button exits the script.
F11:: {        ; This button declares that your CURRENTLY active window will recieve the input.
   Global WinID := WinGetID("A") ; This line makes a variable that is equal to the active window's HWND.
   SetTimer(Fn1, 60000)  ; This is the delay before Fn1 activations in milliseconds.
}
Fn1() {  ; This creates a UDF (User Defined Function) named Fn1.
   ControlSend "{Blind}{F1}",, "ahk_id" WinID ; This is the line where you set the keystroke.
}
***
Steps to take if script doesn't work at all: https://www.autohotkey.com/board/topic/111737-how-to-make-ahk-work-in-most-games-the-basics/
***
Best of Luck,
The Duck

User avatar
xvz
Posts: 33
Joined: 20 Feb 2023, 15:15

Re: Prevent Star Citizen from disconnecting while idle

Post by xvz » 21 Feb 2023, 14:08

That is great thanks!

I'm using v1 AHK and have a couple basic scripts in use, hopefully they will still work with v2.

I wondered if alt tab could be set as the key combo that activates this script, but it may be better to designate something else for it to work across applications. I might want to specify only Star Citizen and keep this specific to that. Before trying to do that, though, I'll stick with the way it is with what you shared.

The F11 and F12 keys are used in Star Citizen, I think most keys are, the key bindings for it take up most of the keyboard. Maybe I could use a combination of the control key and something else to activate and deactivate the script while in the window.

It's impressive that you were able to get the script down to fewer lines than the example that I found. Thank you for adding the comments and explaining what each line does in it, also the link to the basics thread, that is very helpful.

After I replace v1 with v2 AHK and confirm my other AHK scripts still work, I'll give this one a go. After confirming it works, I may adjust the duration from 1 minute to 5 minutes. I think the idle timer on Star Citizen is around 10 or 15 minutes, but if it wouldn't "tax the system" or anything like that to have the script run every minute that would be okay too.

Thanks again! I'm going to reply back in here with an update after I have a chance to test things out.

User avatar
DuckingQuack
Posts: 219
Joined: 20 Jan 2023, 18:20

Re: Prevent Star Citizen from disconnecting while idle

Post by DuckingQuack » 21 Feb 2023, 17:55

xvz wrote:
21 Feb 2023, 14:08
After I replace v1 with v2 AHK and confirm my other AHK scripts still work
You can have BOTH v1 and v2 installed and AHK will "sense" what version the script is and run it correctly.

I HIGHLY suggest fully uninstalling your v1 and installing v2 WITH the v1 included option checked so that all your files are together... iirc... that's what I did.

Also, it will be super simple to modify the script the way you want... I can do everything but pick the button you want and type in the window title since I don't know it. ;)

Edit: Added modified script

Code: Select all

#Requires AutoHotkey v2.0  ; Made by DuckingQuack. HMU on Discord: DuckingQuack#6926
#SingleInstance Force      ;This script is not guaranteed to operate in all games.
F12::ExitApp   ; This button exits the script.
F11:: {        ; This button toggles the script.
   Static on := False   ; This line prepares the toggle and remembers the value.
   SetTimer(Fn1, 60000 * on := !on)  ; This is the delay before Fn1 activations in milliseconds and where the toggle action happens.
}
Fn1() {  ; This creates a UDF (User Defined Function) named Fn1.
   ControlSend "{Blind}{F1}",, "Program window title with quotes around it" ; This is the line where you set the keystroke.
}
Edit: added links to help you customize the script's key remaps and title match mode if you need it.
https://www.autohotkey.com/docs/v2/Hotkeys.htm#combo
https://www.autohotkey.com/docs/v2/lib/SetTitleMatchMode.htm
Best of Luck,
The Duck

off
Posts: 176
Joined: 18 Nov 2022, 21:54

Re: Prevent Star Citizen from disconnecting while idle

Post by off » 23 Feb 2023, 22:18

Hello @xvz
I might didnt understand much (or at all), but maybe this script will work?

This script activate then minimized the window immediatly

Code: Select all

F12:: ; use F12 to toggle script on and off (remove if you want this script auto run)
toggle:=!toggle
If (toggle)
{
SetTimer, AntiKickF1, 60000 	; 1 minute set to 600000 for 10 minutes
		                        	; change AntiKickF1 to AntiKickMove to choose your desired Anti Kick
}
Else
{
SetTimer, AntiKickF1, Off
SetTimer, AntiKickMove, Off
}
return

AntiKickF1:
WinActivate, Star Citizen ; change this if not same as the window title
Send, {F1 2} ; send F1 twice as it open and close immediatly.
WinMinimize, Star Citizen
return

AntiKickMove:
WinActivate, Star Citizen ; change this if not same as the window title
Send, {a}{d} ; make the character move left and right
WinMinimize, Star Citizen
return

Esc::ExitApp ; terminate script with Esc
My Creations
IMG2HotString - Send image file easily with your hotstring!
CtrlSend - A small solution for sending keys to window in background that doesn't accept ControlSend's key
ControlProcess

User avatar
xvz
Posts: 33
Joined: 20 Feb 2023, 15:15

Re: Prevent Star Citizen from disconnecting while idle

Post by xvz » 25 Feb 2023, 00:21

@off, thank you for that example. I may give that a try later after I try the other ones in this thread.

@DuckingQuack, thank you for the additional info. I haven't had a chance yet to take the next steps, although am hoping to in the upcoming days.

The current idle timer in Star Citizen is nowhere near long enough. It will be great to have a way around that. Hopefully I'll get a chance soon to dive into the new AHK setup. I'll update in here after I get a chance.

User avatar
xvz
Posts: 33
Joined: 20 Feb 2023, 15:15

Re: Prevent Star Citizen from disconnecting while idle

Post by xvz » 25 Feb 2023, 15:02

Hi there! Here's an update.

I was able to install AHKv2 and it kept AHKv1 so they are both recognized now.

The AV program settings had to be updated to allow the new AHK executables, there are multiple so I added all of them to be allowed, and also added the new script to the exceptions list, it now matches with the existing AHK setup so AV shouldn't interfere.

The 1st version of the script, to activate from any window, didn't work, then I tried the 2nd version, same thing. I adjusted the time to 5 seconds just to see results more quickly, to adjust again later after it's working. I can also try changing the F12 and F11 keys to something else later, something like an alt key with another key combo, although I'd just like to make sure it works first.

For the 2nd version of the script, I ran the AHK program that detects the name and it showed me this:
Star Citizen
ahk_class CryENGINE
ahk_exe StarCitizen.exe
Here's what I'm trying that's not working yet:

Code: Select all

#Requires AutoHotkey v2.0  ; Made by DuckingQuack. HMU on Discord: DuckingQuack#6926
#SingleInstance Force      ;This script is not guaranteed to operate in all games.
F12::ExitApp   ; This button exits the script.
F11:: {        ; This button toggles the script.
   Static on := False   ; This line prepares the toggle and remembers the value.
   SetTimer(Fn1, 5000 * on := !on)  ; This is the delay before Fn1 activations in milliseconds and where the toggle action happens.
}
Fn1() {  ; This creates a UDF (User Defined Function) named Fn1.
   ControlSend "{Blind}{F1}",, "Star Citizen" ; This is the line where you set the keystroke.
}

User avatar
DuckingQuack
Posts: 219
Joined: 20 Jan 2023, 18:20

Re: Prevent Star Citizen from disconnecting while idle

Post by DuckingQuack » 25 Feb 2023, 19:11

xvz wrote:
25 Feb 2023, 15:02
Here's what I'm trying that's not working yet:
Since I know the code is good, and I'm pretty confident you grabbed the correct window title (although it wouldn't hurt to double check it), then our next step is make the game compatible with the script.
DuckingQuack wrote:
20 Feb 2023, 20:58
***
Steps to take if script doesn't work at all: https://www.autohotkey.com/board/topic/111737-how-to-make-ahk-work-in-most-games-the-basics/
***
Remember this?

Definitely start with changing the game to windowed mode.
Now, you said you had a script that would send mouse movements and such but required the game to be the active window. We could potentially be trying to solve a problem that can't be solved. It is possible this game does not accept controlsend which means this will never work.
Best of Luck,
The Duck

User avatar
xvz
Posts: 33
Joined: 20 Feb 2023, 15:15

Re: Prevent Star Citizen from disconnecting while idle

Post by xvz » 26 Feb 2023, 19:04

I just checked it again and for some reason the new script stopped running, while the other ones continued to run, and I have them set up the same way, with the only exception being that the one that stopped is AHK v2 and the other ones are on AHK v1. I set up the AV to allow AHK and AHK scripts, although I may temporarily try pausing the AV very briefly just to see how that affects it. However, the other day when I tested the script, it kept running without any issues, either way it is weird that it stopped just now on a recent test. I did install AHK v2 on top of v1, so maybe I need to uninstall all of it and install only AHK v2. The weird thing about that is that when I installed v2, it already knew where to look to find v1 and just put it all in the same path.

In one of my simple scripts that I use, the Star Citizen name works, although it is without quotes that may be due to the way it's used:

Code: Select all

#IfWinActive Star Citizen
That specific action is not what I want for this new script, since it needs to run in the background, but I'm not familiar enough with all of it to know that for sure.

That Basics post does have helpful info, here's what I've done so far from that:
  • Set script to run as admin
  • Set Star Citizen to Windows mode, although technically it is Borderless Windows mode
I didn't adjust the script to press F1 down for 10-15ms before releasing the key.

I've never seen the ControlSend or Blind parts of a script before:

Code: Select all

ControlSend "{Blind}{F1}",, "Star Citizen"
I looked them up:
https://www.autohotkey.com/docs/v2/lib/ControlSend.htm
It looks like ControlSend simulates keystrokes.
https://www.autohotkey.com/docs/v2/lib/Send.htm#blind
Blind is a little confusing, it seems like it gives the command more control and helps with remapping keys.

Here's one of the simple scripts I'm using that I use with AHK v1, this one will "auto walk" without having to hold down w:

Code: Select all

#IfWinActive Star Citizen
#SingleInstance Ignore
!w::
Loop,
{
Send, {w down}
sleep 100
	{
       keywait, w
	   break
	   }
}
Return
That works fine, although I wouldn't need the F1 key to be continuously held down. I would only need the key to be pressed, then released, then wait at an interval before happening again.

I haven't tried the intermediate or advanced steps in that Basics post. Star Citizen has a built-in feature on launch that may prevent AHK scripts from running as exe files or from system accounts. Running Star Citizen inside a VM is unfortunately not an option, I'm trying to use all the hardware that I have, not divvy any of it up into a VM.

Next up will be testing with AV briefly disabled, then reenable it, and if still no luck, then I'm going to wipe out AHK completely from the computer and install AHK v2 again, only this time see if it gives me the option to also install v1 or maybe my basic scripts will work with v2 (they look just like the walking w loop script above).

User avatar
xvz
Posts: 33
Joined: 20 Feb 2023, 15:15

Re: Prevent Star Citizen from disconnecting while idle

Post by xvz » 26 Feb 2023, 20:00

I was unable to edit my previous message so I will just post an update in a new message.

It does not appear to be an AV issue, the scripts kept running with and without it.

After completely removing AHK v1 and v2, it prompted me to remove both, so I did that.

While installing AHK v2 again, it did not prompt me to install v1.

The new installation ran into an issue with not wanting to install in a different location:

Image

I don't know if UI Access will be needed, regardless of that I changed it to use the default path.

After running the scripts again, old ones and new one, and old ones continued to work, new one still didn't work.

Next up, I tested the script that @off shared, although I removed the last line and adjusted the time to 5 seconds. The escape key is used in Star Citizen, I'd rather not confuse the key between the two applications. The reduced time was just to see how it would work without having to wait several minutes. That script did seem to work but not as intended. The F1 key was pressed by the script, but the entire Star Citizen window kept minimizing and restoring and minimizing again, it was disrupting the flow of trying to do tasks while alt tabbed out of it.

I am wondering if it is possible to make AHK function with programs in the background without having to make them the active window.

Either way, I think that the script that you provided @DuckingQuack is almost what is needed for this, although it may be the way that it is being told to simulate pressing the key may not be working.

User avatar
xvz
Posts: 33
Joined: 20 Feb 2023, 15:15

Re: Prevent Star Citizen from disconnecting while idle

Post by xvz » 26 Feb 2023, 20:05

Forgot one thing, I completely removed both AHK installs, then installed only AHK v2, then when attempting to run scripts that were used with AHK v1, it prompted me to install v1, so I did that, and now it is using both versions again, as intended this time. However, if it is possible to adjust my old scripts to use v2, that would be okay. I was only using the "auto walk" (it's in a previous message in this thread) and a copy of it that was with the f key instead of w key, the copy of it just holds down the f key for interaction mode in Star Citizen.

User avatar
DuckingQuack
Posts: 219
Joined: 20 Jan 2023, 18:20

Re: Prevent Star Citizen from disconnecting while idle

Post by DuckingQuack » 26 Feb 2023, 21:36

It is true that controlsend does not work with every game, but it is the only method I'm familiar with that allows one to send keystrokes to a minimized window. Since all the other scripts you have showcased have used send with the game in an active state, it is easy to conclude that this is one of those games that does not work with controlsend.
Best of Luck,
The Duck

off
Posts: 176
Joined: 18 Nov 2022, 21:54

Re: Prevent Star Citizen from disconnecting while idle

Post by off » 26 Feb 2023, 22:06

@xvz
Hello, sorry to hear that, i expected that, because the script maximize and minimize the window, that will disturb you.
Maybe, if you set the delay to 5 or 10 minutes, it will not disturb you as much as 5 seconds is. And maybe Block mouse and/or keyboard input while the script activating the window until it minimized again will help (idrk).

Sadly, AFAIK the game you play will not accept ControlSend, which will send keys straight into the window. So i use this method, ill search another way to activate window and send keys without disturbing.

If you find before me, please tell me too. I may need the trick later.
My Creations
IMG2HotString - Send image file easily with your hotstring!
CtrlSend - A small solution for sending keys to window in background that doesn't accept ControlSend's key
ControlProcess

User avatar
xvz
Posts: 33
Joined: 20 Feb 2023, 15:15

Re: Prevent Star Citizen from disconnecting while idle

Post by xvz » 27 Feb 2023, 14:03

If there's not a way to use ControlSend or otherwise simulate pressing keys with Star Citizen remaining in the minimized state, then it may be a matter of dealing with the window periodically restoring then minimizing again while in the middle of other tasks.

I looked for information on how to briefly block mouse and keyboard input in the case of the Star Citizen window briefly restoring then minimizing again.

This is from somebody else:

Code: Select all

; use f11 to block input for 10 secs
f11::
  blockinput,on
  sleep 10000
  blockinput,off
return

; holding appskey and pressing x abort
appskey & x::
  blockinput,off
return
Someone else:

Code: Select all

^!l::BlockInput, On
They said control-alt-delete toggles it off.

Being able to simulate keystrokes while Star Citizen is minimized, without briefly restoring it, is something I'd like to try to figure out. I don't want to give up on ControlSend or other possibilities just yet, but would like to have a better understanding of how that works and if there are other options.

Maybe ControlSend could be used without the Blind and with the commas shuffled around, like this:

Code: Select all

ControlSend,, "{F1 Down}", "Star Citizen"
Sleep, 100
ControlSend,, "{F1 Up}", "Star Citizen"
Return
Shuffling commas may be a bad idea, I just saw that in an example while looking for additional options.

The Down and Up may not be necessary, the Send lines in the other script example in this thread worked.

There's also probably some mixing up of AHK v1 and v2 syntax going on, it may be helpful to just stick with one version.

ControlSend does come up more often in search results. That would be really too bad if it doesn't work with Star Citizen.

I would like to use the key combination of the alt key and the backtick/tilde key to toggle it on, then just backtick/tilde to toggle it off.

I believe that would look something like this to toggle it on, followed by the lines that tell it what to do:

Code: Select all

!`::
That would be the backtick ` instead of tilde ~ (shift `), it seems the actual tilde is a modifier, the docs are a bit confusing on that.

And to toggle it off, I'd want to use just the backtick ` key, although I am unclear as to the purpose of ExitApp, it appears that it completely exits out of the script, making it impossible to toggle it on again. I wonder if that's why the ControlSend variation of the script wasn't working for me before, if I pressed the designated ExitApp key for its Star Citizen function before pressing the key to toggle the script on.

On a related note, I wonder if I could combine multiple scripts into one. I have a basic hold-w auto-walk script and a basic hold-f maintain-interaction-mode script. It would be great if I could just combine all of the scripts into one.

I know I covered multiple subtopics here, to summarize:
  • Briefly blocking keyboard and mouse if the script is going to quickly restore the Star Citizen window, simulate pressing keys, then quickly minimize again
  • Possible alternative ways to use ControlSend
  • Using alt ` to toggle on and ` to toggle off
  • Wondering if multiple scripts can be merged into one script
Thank you both @DuckingQuack and @off for your help with this!

User avatar
DuckingQuack
Posts: 219
Joined: 20 Jan 2023, 18:20

Re: Prevent Star Citizen from disconnecting while idle

Post by DuckingQuack » 27 Feb 2023, 18:04

Given the parameters ControlSend Keys , Control, WinTitle, WinText, ExcludeTitle, ExcludeText, if you move the commas, you are changing the parameter the information represents. IE: Referencing your example, your key inputs become the "win title" and what was your win title becomes your "win text".

Blind is not necessary, it only allows you to use modifier keys without the script momentarily turning them off when sending the keystrokes.

ExitApp does exactly that... it ends the script. It is not used as a toggle. In the second script I sent, there is one button (F11) that performs the act of toggling of script's function on and off and then the other button (F12), will end the program completely. ExitApp is equivalent to the X button at the top right of the window.

Toggling with two buttons is not toggling ;P that's just an on button and off button, which, yes, is very doable. Although, why not just make a toggle?

Multiple scripts can be merged so long as they do not overlap with each other's actions' hotkeys and variables, specifically global variables. However, building with one piece at a time and adding one additional feature and testing will yield a more stable script.
Best of Luck,
The Duck

off
Posts: 176
Joined: 18 Nov 2022, 21:54

Re: Prevent Star Citizen from disconnecting while idle

Post by off » 27 Feb 2023, 21:05

Hello again @xvz!

I've add the BlockInput as you suggest, and (maybe) improve the maximizing and minimizing so doesnt disturb what you doing.
But i cant think how to save your action (mouse/keyboard input) while the BlockInput is enable, like, when you writing something in notepad, it will cut off the input and you need to type again, maybe someone else have better way to do this.

And i've managed to found how to use Shift + ` as hotkey,

Code: Select all

Shift & ~`::MsgBox, Hello, World! ; using "Shift" instead of "!" as modifier,
                                      ; because sending Shift + ` will return "~" and the script
                                      ; will run if the hotkey is ~::MsgBox, Hello, World!
image.png
image.png (20.59 KiB) Viewed 3564 times
Anyway, here is the modified script:

Code: Select all

game=Star Citizen ; change this if not same as the window title

Shift & ~`:: ; use Shift + ` to toggle script on and off (remove if you want this script auto run)
toggle:=!toggle
If (toggle)
{
SetTimer, AntiKick, 60000 	; 1 minute, set to 600000 for 10 minutes
}
Else
{
SetTimer, AntiKick, Off
WinActivate, %game%
WinSet, Enable,, %game%
WinMove, %game%,, 0, 0 ; moving the game back to x0 y0 pos from x1000 and y1000
WinSet, Bottom,, %game%
WinMinimize, %game%
}
return

AntiKick:
BlockInput, On
WinActivate, %game%
WinMove, %game%,, 1000, 1000 ; this move the window to x1000 and y1000, make no flickering window from maximize and minimizing the game
WinSet, Disable,, %game% ; disabling input from mouse to the game
WinSet, Bottom,, %game% ; activating the game in the most bottom from window stack
Send, {F1 2} ; send F1 twice as it open and close immediatly.
WinMinimize, %game%
WinSet, Enable,, %game% ; enabling back mouse input
BlockInput, Off
return

^\::ExitApp ; terminate script with Ctrl + \
My Creations
IMG2HotString - Send image file easily with your hotstring!
CtrlSend - A small solution for sending keys to window in background that doesn't accept ControlSend's key
ControlProcess

User avatar
xvz
Posts: 33
Joined: 20 Feb 2023, 15:15

Re: Prevent Star Citizen from disconnecting while idle

Post by xvz » 27 Feb 2023, 21:36

Excellent points! Thank you for clarifying the parameters, Blind, ExitApp, and yes, definitely a good idea to just make a toggle. I've already been using 2 key settings for the other scripts to start and stop their actions, although I may go ahead and make a toggle out of the "no idle" script. I'm going to try dumping multiple scripts into one, I'll need to better understand the options for this, like SingleInstance, and possibly adjust the old scripts to AHK v2 syntax if setting to require that version. I won't try adding the block keyboard and mouse thing until later if it's needed.

Star Citizen idles out at 15 minutes and 30 seconds. At the 15-minute mark, it gives a 30-second notification. I'm going to see if it will work with the full 15 minutes in the no-idle part of the script. Since it appears to require quickly restoring the window, then doing something to avoid idle, then quickly minimizing again, I'm going with that duration to maximize the time between restore/minimize interruptions.

Here's a draft:

Code: Select all

#Requires AutoHotkey v2.0

; Star Citizen script to simplify some tasks (this is just a messy draft, a work in progress)
; Includes: auto-walk, auto-hold interaction, no idle

; Auto-Walk, use alt w to start, w to stop

#IfWinActive Star Citizen
#SingleInstance Ignore
!w::
Loop,
{
Send, {w down}
sleep 100
  {
  keywait, w
    break
  }
}
Return

; Auto-Hold Interact, use alt f to start, f to stop:

#IfWinActive Star Citizen
#SingleInstance Ignore
!f::
Loop,
{
Send, {f down}
sleep 100
  {
  keywait, f
    break
  }
}
Return

; No Idle, for use while in other windows, use alt ` to start and stop:

#SingleInstance Force
!`:: {
   Static on := False
   SetTimer(Fn1, 900000 * on := !on)
}
Fn1() {
  WinActivate, Star Citizen
    Send, {F1 2}
  WinMinimize, Star Citizen
}

That's definitely a messy hack of multiple previous example scripts from this thread, it may need to use if else and return. I haven't tested it yet, just experimenting with options, looking for at least a temporary solution with the active-minimize actions until hopefully one day discovering if there is a way to use ContolSend or something to keep Star Citizen minimized the entire time.

User avatar
xvz
Posts: 33
Joined: 20 Feb 2023, 15:15

Re: Prevent Star Citizen from disconnecting while idle

Post by xvz » 27 Feb 2023, 22:02

My bad, I initially only replied @DuckingQuack's most recent reply, and forgot to reply to @off's until now. For some reason every message I send in this forum requires approval to post, so my other reply and this one may be out of order. I'll give your update a try, thank you! I may be okay to not need the BlockInput.

I'm also wondering if I could use ControlSend like this:

Code: Select all

{
  ControlSend,,{F1 down},Star Citizen
  sleep 1000
  ControlSend,,{F1 up},Star Citizen
}


User avatar
DuckingQuack
Posts: 219
Joined: 20 Jan 2023, 18:20

Re: Prevent Star Citizen from disconnecting while idle

Post by DuckingQuack » 28 Feb 2023, 06:49

Good news! Upon reaching your tenth post, not every post will require admin approval! Some will if the bots think it might be spam, but it will be fewer and fewer the more you post.

Now, you have improper use of single instance in the mashup, and poor usage of if win active. I added notes in the edit of your script, but I did not change any of the functions, only changed the usage of the aforementioned statements to more properly reflect the way I *think* you would need them.

Be sure to test it.

Code: Select all

#Requires AutoHotkey v2.0

; Star Citizen script to simplify some tasks (this is just a messy draft, a work in progress)
; Includes: auto-walk, auto-hold interaction, no idle

; Auto-Walk, use alt w to start, w to stop

#IfWinActive Star Citizen ; This statement is used to make sections of the script only work if the specified window is active and when you get to a section that does not need this, it is turned off using the same command but without a window title.
#SingleInstance Force ; This statement should only be used once per script whether it is force OR ignore, only use it once because it tells the script if you can run two of them at the same time or not. So having both options present in the same script makes no sense.
!w::
Loop,
{
Send, {w down}
sleep 100
  {
  keywait, w
    break
  }
}
Return

; Auto-Hold Interact, use alt f to start, f to stop:

!f::
Loop,
{
Send, {f down}
sleep 100
  {
  keywait, f
    break
  }
}
Return

; No Idle, for use while in other windows, use alt ` to start and stop:

#IfWinActive ; This is where we disable the requirement for star citizen to be active so that this section wont encounter any issues.

!`:: {
   Static on := False
   SetTimer(Fn1, 900000 * on := !on)
}
Fn1() {
  WinActivate, Star Citizen
    Send, {F1 2}
  WinMinimize, Star Citizen
}
Regarding your new question about controlsend, your parameters are still in the wrong locations… so no… But if you fix that, then yes, you can use controlsend for down and then up.
Best of Luck,
The Duck

User avatar
xvz
Posts: 33
Joined: 20 Feb 2023, 15:15

Re: Prevent Star Citizen from disconnecting while idle

Post by xvz » 28 Feb 2023, 17:51

Interesting, an error popped up with a message:
Error: This line does not contain a recognized action.
Text: #IfWinActive Star Citizen
Line: 8
Then with a "program will exit".

I tried changing this:

Code: Select all

#IfWinActive Star Citizen

to this:

Code: Select all

#IfWinActive "Star Citizen"

and received the same response, so I put it back until something else can be used. I searched for IfWinActive in the AHK docs and didn't find it in v2 but did find it in v1, I wonder if there is a v2 variation to how it is used.

Post Reply

Return to “Gaming Help (v1)”