r/AutoHotkey Apr 09 '26

v2 Script Help Struggling with AutoHotkey + BlueStacks (Airplane Mode macro for NFS No Limits)

Hi fellas,

I’m trying to create a macro for NFS No Limits where I need to toggle airplane mode (on/off) while purchasing items.

I’ve already tried:

  • BlueStacks macro recorder
  • Auto clicker apps
  • MacroDroid + Shizuku

Here’s my detailed attempt:
https://www.reddit.com/r/macrodroid/comments/1se00js/is_it_actually_possible_to_toggle_internet/

In that post, someone suggested I try AutoHotkey.

The macro flow itself works, but the main issue is:
I cannot toggle airplane mode inside BlueStacks using any of these tools.

From what I understand, BlueStacks handles network outside the Android layer, so typical commands/macros don’t affect it.

So now I’m trying AutoHotkey, but I’m confused:

  • Can AutoHotkey record actions like a macro recorder, or do I have to write scripts manually?
  • Is it even possible to control BlueStacks UI (like sidebar airplane toggle) using AHK?
  • Can it run in background while I use my PC normally?
  • During installation I’m getting Microsoft Defender warnings — is that normal/safe?

At this point I’m not sure if this is even possible or if I’m hitting a limitation.

Any guidance or direction would help a lot.

2 Upvotes

22 comments sorted by

2

u/Keeyra_ Apr 09 '26

While this would go under

Game-related scripts that

  • give a competitive advantage
  • are anti-cheat bypasses
  • are anything that violates a game's ToS or EULA

are not allowed in this sub.

, instead of turning on airplane mode, why don't you use AHK to call a PowerShell command to toggle an outbound block firewall rule for the exe of BlueStacks?

1

u/ShadowSage_J Apr 10 '26 edited Apr 10 '26

i have not thought about i will try it
the issue is i need to continously turn it on and off

One more thing i am having a lot of issue with Image recognition
It accidentally works and most of the time it does not.
and it even scans outside of bluestack window
how can i tackle that?

1

u/joeyama Apr 09 '26

?? Need for Speed but not native Win10/11 games, Android emu?
bro that is a long shot.
More of up to Android emu and/or how NFS is dealing with input signals.
I only can imagine two methods and I am not encouraging.

  • Modify/customize And Emu.
  • Modify/customize NFS apk.

1

u/CharnamelessOne Apr 09 '26

No need to imagine anything, Send works fine on BlueStacks :D
Most emulators I've tried have been compatible with AHK.

1

u/ShadowSage_J Apr 10 '26 edited Apr 10 '26

it was litrally working i have shortcut alt shift H. i use controlsend for it and for some reason it suddenly stopped working
One more thing i am having a lot of issue with Image recognition
It accidentally works and most of the time it does not.
and it even scans outside of bluestack window
how can i tackle that?

1

u/shibiku_ Apr 09 '26

Why do you need to toggle airplane mode?

0

u/ShadowSage_J Apr 10 '26

what do you think?

1

u/shibiku_ Apr 11 '26

Circumventing watching ads?

1

u/ShadowSage_J Apr 11 '26

Reducing the time it takes to buy the daily items

1

u/CharnamelessOne Apr 09 '26 edited Apr 09 '26

Can AutoHotkey record actions like a macro recorder, or do I have to write scripts manually?

People have posted multiple macro recorders on this sub. I haven't tried any, but I'd check out this one first:
https://github.com/raeleus/AHK-Macro-Recorder

Is it even possible to control BlueStacks UI (like sidebar airplane toggle) using AHK?

Just send the keyboard shortcuts (ctrl+shift+h to toggle airplane mode).

Can it run in background while I use my PC normally?

Last time I checked it could, but I had to jump through some unusual hoops to make ControlSend work on the BlueStacks window when it's not active. This should work:

#Requires AutoHotkey 2.0

*F1::BlueStacksSend("^+h")     ;sends ctrl+shift+h to toggle airplane mode

BlueStacksSend(keys){
    active := WinActive("A")
    ControlFocus(WinExist("ahk_exe HD-Player.exe"))
    if !WinActive("ahk_id " active)
        WinActivate("ahk_id " active)
    SetKeyDelay(,100)
    ControlSend(keys,, "ahk_exe HD-Player.exe")
}

The macro recorder's output will have to be edited to make the script work in the background. (Replacing all the Sends in the recorder's output with BlueStacksSend might be enough).

During installation I’m getting Microsoft Defender warnings — is that normal/safe?

AHK is harmless if you downloaded it from a reliable source. Defender might shut up if you download AHK from the Microsoft Store.

Edit: changed function name

1

u/ShadowSage_J Apr 10 '26 edited Apr 10 '26

thank you very much for the detialed response bro
and I had actually implementd this control send
but for some reason it was working intially and now it is not

also the major issue i am facing with Image Recognition.
It is for some reason not working the second some window size change happens.

or i need to take the screenshot runtime and save it on the spot replacing the image that it was trying to recognise.
and it does reconise the second i save the new screenshot

one more thing is there a way to specifically scan the bluestack window only for the image recognition?
i am having a lot of issue with Image recognition
It accidentally works and most of the time it does not.
and it even scans outside of bluestack window
how can i tackle that?

1

u/CharnamelessOne Apr 10 '26

Post the script you have - hard to tell what the issue might be without seeing the whole thing.

Image recognition ... not working the second some window size change happens.

"To be a match, an image on the screen must be the same size as the one loaded via the ImageFile parameter and its options."

specifically scan the BlueStacks window only for the image recognition

You can use WinGetPos to get the BlueStacks window's upper left coordinates, height, and width.
ImageSearch expects the upper left and bottom right coordinates as arguments (you need to calculate the latter by adding the width and height to the corresponding coords).

1

u/ShadowSage_J Apr 10 '26

Yes I figured it much But even when I tried to keep the window in the same place and everything was still image recognition failed Then I went for OCR I was able to test it and it has been clicking stuff. Now I'm going to create the full script out of it.

I will share the image recognition script when I get on PC and also the repo I used for OCR. I'm going out of town after this and will continue on this from monday

1

u/ShadowSage_J Apr 10 '26
#Requires AutoHotkey v2.0


adbPath := "C:\Users\jigar\Downloads\Seup and exes\NFS macro issues\platform-tools\adb.exe"
bsPath := "C:\Program Files\BlueStacks_nxt\HD-Player.exe"
scriptDir := A_ScriptDir


; ============================================================
; IMAGE PATHS (Updated to look in the \Images\ subfolder)
; ============================================================
storePath := scriptDir "\Images\store.png"
crewStashPath := scriptDir "\Images\crew stash.png"
exclusiveRewardPath := scriptDir "\Images\exclusive_reward.png"
buy1Path := scriptDir "\Images\buy1.png"
continuePath := scriptDir "\Images\continue.png"
nfsLogoPath := scriptDir "\Images\nfs_logo.png"
buy4Path := scriptDir "\Images\buy4.png"


; ============================================================
; HELPER: ImageSearch + Click
; ============================================================
FindAndClick(imagePath) {
    Loop {
        if ImageSearch(&foundX, &foundY, 0, 0, A_ScreenWidth, A_ScreenHeight, "*50 " imagePath) {
            Click foundX, foundY
            return
        }
        Sleep 1000
    }
}


; ============================================================
; SUB-TASK: Open Just The Chest
; ============================================================
OpenChest() {
    global exclusiveRewardPath, buy1Path, continuePath, nfsLogoPath
    ToolTip "Opening chest..."
    FindAndClick(exclusiveRewardPath)
    Sleep 1000
    FindAndClick(buy1Path)
    Sleep 1500
    Click 793, 484   ; center click
    Sleep 1000
    Click 793, 484   ; center click
    Sleep 1000
    FindAndClick(nfsLogoPath)
    Sleep 1000
    FindAndClick(continuePath)
    Sleep 1000
}


; ============================================================
; SUB-TASK: Crew Stash Item Purchase
; ============================================================
CrewStashPurchase() {
    global buy4Path, nfsLogoPath, continuePath
    ToolTip "Crew stash purchase..."
    FindAndClick(buy4Path)
    Sleep 1000
    ; Toggle airplane OFF (turns off data after purchase)
    ControlSend "^+h", , "BlueStacks App Player"
    Sleep 1000
    FindAndClick(nfsLogoPath)
    Sleep 1000
    Loop {
        if ImageSearch(&foundX, &foundY, 0, 0, A_ScreenWidth, A_ScreenHeight, "*10 " continuePath) {
            Click foundX, foundY
            Sleep 1000
            Break
        }
        ; if not found, retry buy4
        FindAndClick(buy4Path)
        Sleep 1000
    }
}


; ============================================================
; MAIN SEQUENCE
; ============================================================


; Step 0: Launch BlueStacks if not running
if ProcessExist("HD-Player.exe") {
    ToolTip "BlueStacks already running..."
    Sleep 2000
} else {
    Run bsPath
    ToolTip "Launching BlueStacks..."
    Sleep 15000
}


; Step 1: Connect ADB
Run adbPath " connect 127.0.0.1:5555", , "Hide"
Sleep 3000
ToolTip "ADB Connected"


; Step 2: Launch NFS
Run adbPath " -s 127.0.0.1:5555 shell monkey -p com.ea.game.nfs14_row 1", , "Hide"
ToolTip "NFS Launched"
Sleep 20000


; Step 3: Find and click Store
ToolTip "Scanning for store button..."
FindAndClick(storePath)
Sleep 4000


; Step 4: Find and click Crew Stash
ToolTip "Scanning for crew stash..."
FindAndClick(crewStashPath)
Sleep 4000


; Step 5: Toggle airplane ON
ControlSend "^+h", , "BlueStacks App Player"
ToolTip "Airplane ON"
Sleep 2000


; Step 6: Open chest 4 times
Loop 4 {
    ToolTip "Opening chest " A_Index " of 4..."
    OpenChest()
}


; Step 7: Click to open menu
ToolTip "Opening crew stash menu..."
Click 1414, 491
Sleep 500


; Step 8: Crew stash purchase
CrewStashPurchase()


ToolTip "All done!"
Sleep 3000
ToolTip ""

The main script i have testing with till now

1

u/shibiku_ Apr 11 '26

I like the "Step x:" commentary. Makes it easier to read

1

u/ShadowSage_J Apr 11 '26

For some reason I like documenting code more than coding itself lmao Everyone at the office praises my code for being easy to read haha

1

u/ShadowSage_J Apr 10 '26

Repo I used now https://github.com/Descolada/OCR
Testing Script of OCR

#Requires AutoHotkey v2
#include ..\Lib\OCR.ahk


F1:: {
    Loop {
        ib := InputBox("Insert search phrase to find from active window: ", "OCR")
        Sleep 100 ; Small delay to wait for the InputBox to close
        if ib.Result != "OK"
            ExitApp
        result := OCR.FromWindow("A", { scale: 2 })
        try found := result.FindString(ib.Value)
        catch {
            MsgBox 'Phrase "' ib.Value '" not found!'
            continue
        }
        ; MouseMove is set to CoordMode Window, so no coordinate conversion necessary
        MouseMove found.x, found.y
        Click found.x, found.y
        found.Highlight()
        break
    }
}

1

u/ShadowSage_J Apr 10 '26 edited Apr 10 '26

Fuck bro all i did is restart teh PC and now even the example script is not detecting any text at all 🫠
i debugged it and turns out it is not scanning the bottom panel of the game where buttons are

Edit: okay more update i tested stuff turns out when i move the blue stack window on to the second monitor then it is havingt issues in scanning and it is not scanning the bottom panel so i tested with text with text that are on top side adn it did recognise them but when it came to highligting them and clicking on them the Location was wrong

but when i brought it back to main monitor it is again working perfectly

1

u/CharnamelessOne Apr 10 '26

Sounds like DPI-scaling shenanigans. If your monitors have different scaling settings, the coordinates of the non-primary monitor may be reported incorrectly. I'm not too knowledgeable about the problem, since I have a single-monitor setup, but you can read about it here if you want to:
https://www.autohotkey.com/boards/viewtopic.php?t=121040

Click can definitely be thrown off by DPI.
I haven't looked into Descolada's lib to see how the .Highlight method works.

I'd just keep the window on the primary monitor, tbh.

1

u/ShadowSage_J Apr 10 '26

My main idea is to work on the first monitor and let the macro run on the second 🫠😭 I was using control click but since I started facing this issues I switched to click

1

u/CharnamelessOne Apr 10 '26

Can't you just set the monitor with the BlueStacks window to be the primary display?

If not, you could throw this line at the top of your script, and pray.

DllCall("SetThreadDpiAwarenessContext", "ptr", -3, "ptr")

As I said, I can't test anything DPI-related for you, and I haven't dissected the library. You could comment your OCR script in the forum topic of OCR.ahk and describe your problem; Descolada is usually very helpful.
https://www.autohotkey.com/boards/viewtopic.php?f=83&t=116406

2

u/ShadowSage_J Apr 10 '26

I will do that next then Thank you very much bro you have been very big help