=================
== Claus' Blog ==
=================
Made with Hugo and ❤️

Geforce Now Anti Idle Autohotkey Script

#games #autohotkey #script #autohotkey

I have been playing Geforce Now for the past two years and I absolutely love it. The convenience of being able to stream my favorite games without the need for high-end hardware has been a game-changer for me. Although i just bought a 4070 Ti. Right now it was a bad investment.

But as much as I enjoy playing on Geforce Now, I sometimes encounter the issue of idle disconnects. To address this, I have created an Autohotkey script that keeps my session active even during periods of inactivity. For that my script switches back to the Geforce Windows and moves the mouse a bit. Whatever I was doing at that moment. For example: I’m looking up something on the Internet (about the game) or I reply to a text message. I forget about time and suddenly my game session got disconnected. Which could be very annoying if my game wasn’t saved recently. This happens after a few minutes, 7 or 8 minutes it was, I guess.

For those of you, who don’t know AutoHotkey here is a small summary from ChatGPT 😉

  • Autohotkey is a scripting language that allows you to automate tasks and create hotkeys for various actions on your computer.
  • It provides a simple syntax and a wide range of built-in functions, making it easy to write scripts for automating repetitive tasks or customizing your workflow.
  • With Autohotkey, you can automate keystrokes, mouse movements, window management, and much more, making it a powerful tool for increasing productivity and efficiency.

The Script

So here is my script for Autohotkey:

 1; GeForceNOW
 2
 3; keyboard commands only available if GFN is active
 4#IfWinExist ahk_exe GeForceNOW.exe
 5
 6  ; turn timer on
 7  ^+k::
 8    ; timer action every 3 minutes
 9    Timer := 240 * 1000
10    SetTimer, MoveTheMouse, %Timer%
11    Menu, Tray, Icon, %A_ScriptDir%\assets\green.ico, 1
12    SoundBeep, 750, 500
13    SetKeyDelay, 50
14  Return
15
16  ; turn timer off
17  ^+l::
18    SetTimer, MoveTheMouse, Off
19    Menu, Tray, Icon, %A_ScriptDir%\assets\red.ico, 1
20    SoundBeep, 500, 500
21    SetKeyDelay, 50
22  Return
23#IfWinExist
24
25MoveTheMouse:
26  ; helps with windows on different virtual windows desktop
27  DetectHiddenWindows, On
28  ; sleep timer (seconds) for random execution
29  Random, rand, 90, 120
30  SleepTimer := rand * 1000
31
32  ; Mouse movement in pixels (also randomized)
33  Random, x, -10, 10
34  Random, y, -10, 10
35
36  ; activates sleep timer
37  Sleep, SleepTimer
38
39  Idle := Timer + SleepTimer
40
41  if (WinActive("ahk_exe GeForceNOW.exe"))
42  {
43    ; if window is active and system idle time exceeds Idle
44    if (A_TimeIdle > Idle) {
45      MouseMove, x, y, 10, R
46    }
47
48  } else if (WinExist("ahk_exe GeForceNOW.exe"))
49  {
50    ; if window exists
51    WinActivate
52    MouseMove, x, y, 10, R
53
54  } else {
55    ; if window does not exist, turn timer off
56    SetTimer, MoveTheMouse, Off
57    Menu, Tray, Icon, %A_ScriptDir%\assets\red.ico, 1
58  }
59Return

Short explanation

The first hotkey ^+k (Ctrl + Shift + K) enables the timer. But it only works if a Geforce Now window is active. When this hotkey is pressed, a timer is set to trigger the MoveTheMouse label every 3 minutes. I’ve added two icons in the asset folder, so i can see when the script is active. The second hotkey ^+l (Ctrl + Shift + L) turns off the timer.

The script checks if the GeForce NOW window is active. If it is and the system idle time exceeds the calculated idle time, the mouse cursor is moved by the random x and y values. If the window exists but is not active, it activates the window and moves the mouse. If the window does not exist, the timer is turned off, and the system tray icon changes to red.

If you have an suggestion or a question, you can get in touch with me on Mastodon or Matrix.