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

Re: Prevent Star Citizen from disconnecting while idle

Post by xvz » 06 Mar 2023, 15:15

We're making progress, this is getting closer and this is very exciting, it's almost there! Thank you both @DuckingQuack and @off for helping with all of this. Here is an update on the status of this so far:

I am using the caps lock key instead of alt or shift, before pressing w to walk, f to interact, or q to toggle the anti-kick. That works, including some of the anti-kick features.

With the anti-kick or stay-online part of the script, what happens is that it effectively moves, minimizes, activates, the window, and the robot voice says "sending", but unless I click around windows to get it to send the F1 key in Star Citizen, the script actually presses F1 on whichever other window is open at the time.

For example, I have notepad++ open, the F1 key was pressed to open the About window for that program as a result of the script.

I should also mention that Star Citizen has 3 window modes:
1. Windowed
2. Fullscreen
3. Borderless

I tested this with "Windowed" and "Borderless" and the script responded the same way with both settings.

Here's the sequence of what I did and what happened:
1. Pressed caps lock q while in Star Citizen
2. Star Citizen window disappeared
3. "Sending" voice, notepad++ About window opened

The script had to be paused to make it stop. I tested it again after I clicked between more programs, like the web browser, and then it made my web browser disappear after opening the About tab with the F1 key for the browser.

I wonder if I will need to be more specific in the script to prevent it from affecting other programs. Other than that, it is almost working as intended. It's not fully functioning yet, but this is progress, and that is great!

Here's the current draft, I have not set auto-walk and auto-hold interact to toggles yet but that can be done later, right now the focus is on that Stay Online feature:

Code: Select all

#Requires AutoHotkey v2.0
#SingleInstance Force
DetectHiddenWindows 1 ; added this line in case star citizen tries to use hidden windows

; Stay Online
; Press tab q to toggle

CapsLock & q:: {
    Static on := false
    if on := !on {
        SetTimer(Fn1, 15000) ; 15 seconds for testing, set to 900000 (15 minutes) when script is ready
        WinActivate "Star Citizen"
        WinMove A_ScreenWidth, A_ScreenHeight, , , "Star Citizen"
        WinMinimize "Star Citizen"
    } Else {
        SetTimer(Fn1, 0)
        WinActivate "Star Citizen"
        WinMaximize "Star Citizen"
    }
}
Fn1() {
    ComObject("SAPI.SpVoice").Speak("Sending")
    WinActivate "Star Citizen"
    Send "{F1}"
    WinMinimize "Star Citizen"
}

; Auto-Walk
; Press tab w to toggle

#HotIf WinActive("Star Citizen")
CapsLock & w:: {
    Loop {
        Send("{w down}")
        Sleep 100
        KeyWait "w" 
        Break
        
    }
} ;

; Auto-Hold Interact
; Press tab f to toggle

CapsLock & f:: {
    Loop {
        Send("{f down}")
        Sleep 100
        KeyWait "f"
        Break
    }
}



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

Re: Prevent Star Citizen from disconnecting while idle

Post by DuckingQuack » 06 Mar 2023, 19:04

xvz wrote:
06 Mar 2023, 15:15
The script had to be paused to make it stop. I tested it again after I clicked between more programs, like the web browser, and then it made my web browser disappear after opening the About tab with the F1 key for the browser.

I wonder if I will need to be more specific in the script to prevent it from affecting other programs. Other than that, it is almost working as intended. It's not fully functioning yet, but this is progress, and that is great!
There's not much I can do to help you test this, however, Send only sends the keystrokes to the active window, so if you are clicking on other windows during the sending function (fn1), then, yes, it will send F1 to the window you clicked on. That was the purpose of the audible, so you could stop doing things.

Try commenting out the WinMove line to see if your problem persists. If you stop having the problem, then the issue is either the game window being completely off screen, or you were unintentionally interfering with the function. If you were the source of the issue, then we can add a block input to the function as @off mentioned earlier. If the issue is being completely off screen, then put - 10 after the width and height variables in WinMove.

Hopefully one of those things helps.
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 » 06 Mar 2023, 20:27

@xvz

Soo, uhh.. you can use 2 modifier keys instead of only 1.
this will prevent some key accidently doing something else, for example

Code: Select all

^+1:: ; Ctrl+Shift+1
MsgBox, Hello
return
I hope this help you to realize CapsLock is not a good modifier key xD
Tho you can always use different/custom modifier keys, like:

Code: Select all

~a & q:: ; a+q button
MsgBox, You pressed a and q button
return
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

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

Re: Prevent Star Citizen from disconnecting while idle

Post by off » 06 Mar 2023, 20:41

So i made this, viewtopic.php?f=6&t=114783
Perhaps this can be used?
i need someone to convert that to v2 syntax too :D
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
DuckingQuack
Posts: 219
Joined: 20 Jan 2023, 18:20

Re: Prevent Star Citizen from disconnecting while idle

Post by DuckingQuack » 08 Mar 2023, 14:22

@off
The v2 code I posted is extremely similar, just add the block input and do the variables and you’ve got your code in v2.
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 » 08 Mar 2023, 18:46

@DuckingQuack
Thank you so much :D
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
DuckingQuack
Posts: 219
Joined: 20 Jan 2023, 18:20

Re: Prevent Star Citizen from disconnecting while idle

Post by DuckingQuack » 08 Mar 2023, 21:23

I added a line to make this script automatically run as admin and changed WinActivate to WinRestore and then removed a WinMove and WinActivate that was not needed. Then I added SendEvent and SendInput for you to test. I commented out the voice since it is a poor representation of when the sending is taking place and doesn't tell you when it ends, so as a replacement I added two SoundBeeps, one at the start that is long and a short one at the end so you know it completed. Only have either the SendEvent or SendInput active for testing. The benefit of SendInput is that it can buffer anything you type while it is happening into a queue to be sent after the send is done, however, this is such a short send, that it is unlikely to actually catch any keystrokes, further, if it did catch one, odds are that it would still be sent to the wrong window. So SendInput isn't actually better in this instance. SendEvent might be better but we might also need a longer keystroke for that game to sense the press, i.e. enable SetKeyDelay( ,250) at the top. But adding a delay increases the duration of the interruption of your work.

Code: Select all

#Requires AutoHotkey v2.0
#SingleInstance Force
;SetKeyDelay( ,250)
DetectHiddenWindows 1
if not A_IsAdmin
	Run '*RunAs "' A_ScriptFullPath '"'

; Stay Online

CapsLock & q:: {
    Static on := false
    if on := !on {
        SetTimer(Fn1, 15000) ; 15 seconds for testing, set to 900000 (15 minutes) when script is ready
        WinRestore "Star Citizen"
        WinMove A_ScreenWidth, A_ScreenHeight, , , "Star Citizen"
        WinMinimize "Star Citizen"
    } Else {
        SetTimer(Fn1, 0)
        WinMaximize "Star Citizen"
    }
}
Fn1() {
    ;ComObject("SAPI.SpVoice").Speak("Sending")
    SoundBeep(250,1000)
    WinActivate "Star Citizen"
    ;SendEvent "{F1}"
    SendInput "{F1}"
    WinMinimize "Star Citizen"
    SoundBeep(500,100)
}

; Auto-Walk

#HotIf WinActive("Star Citizen")
CapsLock & w:: {
    Loop {
        Send("{w down}")
        Sleep 100
        KeyWait "w" 
        Break
        
    }
} ;

; Auto-Hold Interact

CapsLock & f:: {
    Loop {
        Send("{f down}")
        Sleep 100
        KeyWait "f"
        Break
    }
}
This script has no guarantees of solving anything, just some things to test to gain more info to work with.
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 » 09 Mar 2023, 19:38

That is great, thank you! I have seen mention in places about how it may help to add a duration of so many milliseconds on pressing down the key before releasing the key for it to take effect. The beeps will also help with determining which stage it is at in the process. I'll be testing it out and chiming back in here with an update.

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

Re: Prevent Star Citizen from disconnecting while idle

Post by xvz » 13 Mar 2023, 12:35

Hi @DuckingQuack and @off just checking in to say thanks again for helping and to let you know what's going on.

Star Citizen recently had a new version released and the nearly half-billion-dollar backer-funded project is completely broken, many people are unable to even launch into the menu, the ones that can are unable to launch from menu into the actual environment, and the ones that can do that don't make it far before things completely fall apart.

This is a prime time of train wrecks for the mmo universe/space sim, but to be fair about it the developers did introduce a huge change that affects everything in it, along with several other updates, so they are going to probably have their hands full for a while just trying to resolve the issues, starting with the current major outage.

I will get around to testing updates to the script when Star Citizen is functional again and I can post an update in here on how it goes. I will say just really quick that before Star Citizen completely broke for everybody, I tried the updated script and my mouse cursor kept moving to the bottom right corner of the screen, I had to reboot the computer, or thought I had to, then realized afterward that I had to disable another program (joytokey) that I use with my joysticks, as I have a control on them that also controls the mouse. I don't know if that was the root cause, but once I went back to a previous version of the AHK script the mouse cursor issue stopped. I'm wondering if maybe something other than sending mouse signals would be the way to go for this but I don't know.

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

Re: Prevent Star Citizen from disconnecting while idle

Post by DuckingQuack » 13 Mar 2023, 14:12

xvz wrote:
13 Mar 2023, 12:35
I'm wondering if maybe something other than sending mouse signals would be the way to go for this but I don't know.
What version of the anti-afk script are you testing with mouse movements? Feel free to post the code you suspect caused your mouse to drift continuously.
Best of Luck,
The Duck

FlyInYourCircuit
Posts: 13
Joined: 25 Mar 2023, 14:20

Re: Prevent Star Citizen from disconnecting while idle

Post by FlyInYourCircuit » 25 Mar 2023, 16:04

Hello everyone,

I'm trying to write a ahk script for star citizen emotes. as it is now you can emote with a touchscreen tablet but the emote variations are random.

if you open the global chat(f12) hit enter to open text field and type /emote plus a number at the end you get specific numbered emotes

i have a little experience with python but figured i could make more progress asking some questions.

Also i noticed in a working sc ahk script someone is using they use #IfWinActive ahk_exe StarCitizen.exe so that might help you with yours.


this is what i have so far to get started.

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
 
#IfWinActive ahk_exe StarCitizen.exe
!Numpad1::
Send, , {F12}
Send, , {Enter}
Sendtext "/bored2"
Send, , {Enter}
Send, , {F12}

Mod edit: Added [code][/code] tags. Please use them yourself when posting code.]

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

Re: Prevent Star Citizen from disconnecting while idle

Post by off » 26 Mar 2023, 03:37

@FlyInYourCircuit
Hello!

This may help you understand AHK a little bit

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
 
#IfWinActive ahk_exe StarCitizen.exe
!Numpad1::
Send, {F12}{Enter}
Send, /bored2{Enter}
Send, , {F12}
above is for AHK V1, if you want V2, try to use documentation, the syntax a little bit different, but theyre basically the same
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

FlyInYourCircuit
Posts: 13
Joined: 25 Mar 2023, 14:20

Re: Prevent Star Citizen from disconnecting while idle

Post by FlyInYourCircuit » 26 Mar 2023, 03:52

idk alot of terms and syntax seems to have deprecated v2

this is what i have now and its not returning errors but its not having any effect in sc either

#hotif doesnt seem to be a current thing

Code: Select all

#HotIF WinActive("ahk_exe StarCitizen.exe")

>!Numpad1:: {
SendEvent "{RAlt down}F12{RAlt up}"
SendEvent "{Enter}"
Send "/bored2"
SendEvent "{Enter}"
SendEvent "{RAlt down}F12{RAlt up}"
return
}
#HotIf

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

Re: Prevent Star Citizen from disconnecting while idle

Post by DuckingQuack » 26 Mar 2023, 07:32

@FlyInYourCircuit Please don't hijack someone else's thread.

@off Here is a link to the duplicate question: viewtopic.php?f=94&t=115417
Best of Luck,
The Duck

FlyInYourCircuit
Posts: 13
Joined: 25 Mar 2023, 14:20

Re: Prevent Star Citizen from disconnecting while idle

Post by FlyInYourCircuit » 26 Mar 2023, 10:58

Sorry the parallels of the problem suggested similarities and the possibility of solving together

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

Re: Prevent Star Citizen from disconnecting while idle

Post by xvz » 28 Mar 2023, 00:38

@DuckingQuack, I was able to test it out again. It took the Star Citizen developers most of the month of March to get Star Citizen working again, just barely at that, and it's still in rough shape. I was at least able to recently test this out again. I forgot what I used before that caused the mouse cursor to constantly move to the corner and then f1 press would happen in other application windows, although I tested this one and it didn't do anything when trying to use the Stay Online part, while the auto-walk and auto-hold-interact sections did work, all I changed in this were the keys to trigger the sections, using the shift key now:

Code: Select all

#Requires AutoHotkey v2.0
#SingleInstance Force
;SetKeyDelay( ,250)
DetectHiddenWindows 1
if not A_IsAdmin
	Run '*RunAs "' A_ScriptFullPath '"'

; Stay Online

+q:: {
    Static on := false
    if on := !on {
        SetTimer(Fn1, 15000) ; 15 seconds for testing, set to 900000 (15 minutes) when script is ready
        WinRestore "Star Citizen"
        WinMove A_ScreenWidth, A_ScreenHeight, , , "Star Citizen"
        WinMinimize "Star Citizen"
    } Else {
        SetTimer(Fn1, 0)
        WinMaximize "Star Citizen"
    }
}
Fn1() {
    ;ComObject("SAPI.SpVoice").Speak("Sending")
    SoundBeep(250,1000)
    WinActivate "Star Citizen"
    ;SendEvent "{F1}"
    SendInput "{F1}"
    WinMinimize "Star Citizen"
    SoundBeep(500,100)
}

; Auto-Walk

#HotIf WinActive("Star Citizen")
+w:: {
    Loop {
        Send("{w down}")
        Sleep 100
        KeyWait "w" 
        Break
        
    }
} ;

; Auto-Hold Interact

+f:: {
    Loop {
        Send("{f down}")
        Sleep 100
        KeyWait "f"
        Break
    }
}

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

Re: Prevent Star Citizen from disconnecting while idle

Post by DuckingQuack » 28 Mar 2023, 06:00

So pressing shift+Q doesn’t move the star citizen window?
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 Mar 2023, 15:40

Correct. Just to make sure I set Star Citizen to windowed mode.

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

Re: Prevent Star Citizen from disconnecting while idle

Post by off » 28 Mar 2023, 17:54

@xvz
Test the moving part with simple script first and see if it work.

Code: Select all

#Requires AutoHotkey v2.0
Shift & q:: ;try to use this hotkey if +q not working at all
{
WinActivate "Star Citizen"
WinMove A_ScreenWidth, A_ScreenHeight,,, "Star Citizen"
WinGetPos &X, &Y,,, "Star Citizen"
MsgBox "Screen Width" A_ScreenWidth "Screen Height" A_ScreenHeight "`n Star Citizen Pos X" X "Star Citizen Pos Y" Y
Return
}
Edit : clearify this script for V2
Last edited by off on 28 Mar 2023, 20:54, edited 4 times in total.
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
DuckingQuack
Posts: 219
Joined: 20 Jan 2023, 18:20

Re: Prevent Star Citizen from disconnecting while idle

Post by DuckingQuack » 28 Mar 2023, 20:18

Thank you for the assistance @off, but please tag the script with the ahk version number that it uses. It is very confusing flipping back and forth without letting us newbies know it's v1.
Best of Luck,
The Duck

Post Reply

Return to “Gaming Help (v1)”