Change modes with scripts

Switch a Pacto Tech controller between 2 player, 4 player, twinstick, d-pad, analog, keyboard mode and more from a batch file, a front end, PowerShell, Python, AutoHotkey or Linux — and read the current mode back.

Before you script anything: try Game profiles.

If what you want is “this game should always start in 4 player”, “twinstick for Robotron”, “turbo for shmups” or “keyboard mode for this gamepad game”, the Pacto Tech Utility already does it by itself: it sees which game, emulator or front end is running, switches the controller, and puts it back when the game ends. Nothing to launch, nothing to time — and it can do things scripts cannot, such as turbo, per-game button remaps and the exit combo.

Read the Game profiles guide

Use the scripts on this page when you want a front end, a launcher, a hotkey tool or your own program to be in charge.

Download all examples (.zip) Browse the examples
Ready-made scripts LaunchBox / CoinOps / RetroFE How it works Mode names Browser / shortcut Batch files Front ends PowerShell Python AutoHotkey Full API Reading the mode Linux / Batocera Troubleshooting

How it works

While the Pacto Tech Utility runs (it sits in the tray and starts with Windows by default), it listens on a fixed local address that is the same on every PC:

http://127.117.73.87:47391

Opening /mode/<name> on that address switches the controller straight away — no setup, no password. It only answers programs on the same PC, so nothing on your network can reach it. On Linux, the PactoLink service does the same job.

Mode names

GroupNames
Player layout2p 4p twinstick twinstick-1p twinstick-2p
Stick outputdpad analog-fast analog-slow
Keyboard modekeyboard-on keyboard-off
8-to-68to6-on 8to6-off
Interlockinterlock-on interlock-off

The answer is plain text: ok: 4 Player on success, or an error such as controller rejected the command (not connected, or a kiosk lock refused it). /modes lists every name.

Keyboard mode makes the controller restart as a keyboard (it disappears for a moment — that is normal). Coming back to gamepad mode takes about 12 seconds so Windows can forget the old controller.

Ready-made scripts for every mode download & run

One file per mode, per method — nothing to edit. Click to download a single file, or get them all: PactoTech-Control-Examples.zip (folder ready-made).

ModeSilent VBSBatchPowerShellPythonAutoHotkeyLinux
Keyboard / disconnect mode
DongleMaster gamepads take over
vbsbatps1pywahksh
Leave keyboard mode
back to arcade gamepads (~12 s)
vbsbatps1pywahksh
2 playervbsbatps1pywahksh
4 playervbsbatps1pywahksh
Analog fastvbsbatps1pywahksh
D-padvbsbatps1pywahksh
Analog slowvbsbatps1pywahksh
8-to-6 onvbsbatps1pywahksh
8-to-6 offvbsbatps1pywahksh
MethodShows anything on screen?Needs
Silent VBS (.vbs)Nothing at allNothing — built into Windows
Batch (.bat)A console window can flash for a momentNothing (uses the curl built into Windows 10/11)
PowerShell (.ps1)A brief flash, even with -WindowStyle HiddenNothing
Python (.pyw)Nothing (.pyw runs without a window)Python 3
AutoHotkey (.ahk)Nothing (no tray icon)AutoHotkey v2
Linux (.sh)NothingPactoLink on the cabinet

Every script exits with code 0 when the mode switched and 1 (or another non-zero code) when it did not — for example when the Utility is not running or no controller is connected.

Turbo on / off cannot be switched from a script yet. Use the board’s turbo button or switch, or set turbo per game on the Utility’s Game profiles page.

Best choice for LaunchBox, CoinOps and RetroFE

Most reliable: Game profiles, no scripts. The Utility recognises LaunchBox / Big Box, CoinOps, RetroFE and 30+ emulators by the program that is running, switches the controller when a game starts and puts it back when the game ends. Nothing to launch, nothing to time, nothing to fail.

If you want the front end itself in charge, use the silent VBS scripts. They show nothing on screen — so they never steal focus from the front end (a flashing console window can, and some front ends ignore the controls while they are not in focus) — and they need nothing installed.

LaunchBox / Big Box

  1. Copy the .vbs files to a fixed folder, for example C:\Pacto.
  2. Edit the game → Additional Apps → Add: application path C:\Windows\System32\wscript.exe, command-line parameters "C:\Pacto\Pacto - 4 Player.vbs", and tick Automatically run before main application.
  3. Add a second one with "C:\Pacto\Pacto - 2 Player.vbs" and Automatically run after main application to switch back afterwards.

CoinOps / RetroFE (and other launcher-based front ends)

Point the launcher at wscript.exe and let launch-with-mode.vbs start the emulator. It sets the mode, waits for the emulator to close, then switches back to 2 player:

executable = C:\Windows\System32\wscript.exe
arguments  = "C:\Pacto\launch-with-mode.vbs" 4p "C:\Emulators\MAME\mame.exe" %ITEM_NAME%

Keep the emulator’s usual arguments after its path. (%ITEM_NAME% is RetroFE’s placeholder for the game — use whatever your launcher file already passes.)

Microsoft plans to phase VBScript out of a future Windows version; it is still built in and on by default in Windows 11 24H2 and 25H2. If it is ever removed, the .bat files do the same job (with a brief window flash).

1. Browser or desktop shortcut no tools

Paste into any browser on the same PC:

http://127.117.73.87:47391/mode/4p

For a one-click desktop shortcut: right-click the desktop → New → Shortcut, paste the address above, and name it “4 Player”.

2. Batch files Windows

One line

curl is built into Windows 10 and 11:

curl -s http://127.117.73.87:47391/mode/twinstick

Ready-made scripts in the Utility

The Utility already writes one .bat per mode for you: App Settings → External control → Open scripts folder (files like Pacto - 4 Player.bat). They are identical on every PC, so they are safe to copy between cabinets.

pacto-mode.bat — any mode, with error checking

pacto-mode.bat 4p
pacto-mode.bat keyboard-on
pacto-mode.bat            (lists every mode)

Sets %ERRORLEVEL% to 1 and prints why when the switch fails, so a calling script can react. The core of it:

@echo off
curl -s --fail-with-body --max-time 5 http://127.117.73.87:47391/mode/%~1
if errorlevel 1 echo Could not switch - is the Pacto Tech Utility running?

launch-with-mode.bat — play a game in a mode, then switch back

launch-with-mode.bat 4p "C:\Emulators\MAME\mame.exe" gauntlet
launch-with-mode.bat twinstick "C:\Games\Robotron\robotron.exe"

Sets the mode, starts the program, waits for it to close, then returns to 2p (change AFTER_MODE at the top to taste).

pacto-menu.bat — a pick-a-mode menu

Double-click it and press a number. Handy on a cabinet keyboard or over remote desktop.

3. Front ends

Easiest: Game profiles. The Utility’s Game profiles page switches modes (and turbo, remaps, keyboard mode…) automatically when it sees a game or front end start — no scripts at all. Use scripts when you want the front end in charge.

4. PowerShell Windows

Invoke-RestMethod http://127.117.73.87:47391/mode/dpad

PactoApi.ps1 wraps the whole API in a few functions:

. .\PactoApi.ps1
Set-PactoMode 4p                                  # switch (no token)
Get-PactoStatus                                   # live modes (full API)
Watch-PactoModes { param($m) "now: $($m -join ', ')" }   # react to every change

5. Python Windows

Standard library only:

import urllib.request
urllib.request.urlopen("http://127.117.73.87:47391/mode/twinstick").read()

pacto_mode.py is a small command line tool and module:

python pacto_mode.py 4p          # switch
python pacto_mode.py --status    # print the live modes   (full API)
python pacto_mode.py --watch     # print every change live (full API)

6. AutoHotkey Windows

pacto-hotkeys.ahk (AutoHotkey v2) puts every mode on Ctrl+Alt+1…0 and shows the answer as a tooltip:

PactoMode(mode) {
    req := ComObject("WinHttp.WinHttpRequest.5.1")
    req.Open("GET", "http://127.117.73.87:47391/mode/" mode, false)
    req.Send()
}
^!1:: PactoMode("2p")
^!2:: PactoMode("4p")

(The Utility also has built-in PC hotkeys on its Modes page if you would rather not install AutoHotkey.)

7. The full API Windows

Beyond switching modes, the Utility can read the live mode and change remaps, keyboard maps, board settings and game profiles. This part needs a key:

  1. In the Utility, turn on App Settings → Allow local AI agents.
  2. The key is in %LOCALAPPDATA%\PactoConfigurator\agent_token.txt (created on first start). Keep it private.
  3. Send it with every request: Authorization: Bearer <key>.
$tok = (Get-Content "$env:LOCALAPPDATA\PactoConfigurator\agent_token.txt" -Raw).Trim()
$h   = @{ Authorization = "Bearer $tok" }
(Invoke-RestMethod http://127.117.73.87:47391/agent/status -Headers $h).status.modes
Invoke-RestMethod -Method Post http://127.117.73.87:47391/agent/mode -Headers $h `
  -ContentType application/json -Body '{"mode":"8to6-on"}'
RequestWhat it does
GET /agent/statuslive modes: {"status":{"modes":["2P","ANALOG_FAST"],"mode_flags":17,…}}
GET /agent/stateeverything: settings, board, modes, remaps, profiles, running game
POST /agent/mode{"mode":"4p"} — same names as above
POST /agent/remap{"profile":0,"map":{"12":13,"13":12},"save":true} — swap A and B
POST /agent/param{"id":1,"value":1,"save":true} — e.g. start up in 4 player
POST /agent/profilesadd or change game profiles
POST /agent/savekeep board changes after a power cycle
GET /agent/promptthe complete reference (no key needed)

8. Reading the current mode

Windows: GET /agent/status (full API) returns the live modes. There is no push stream on Windows yet, so check it every 250 ms or so — cheap, and Watch-PactoModes / pacto_mode.py --watch do exactly that.

Linux: PactoLink pushes every change instantly — see below.

mode_flags bitModebitMode
0x00012P0x0080KEYBOARD
0x00024P0x01008TO6 (left)
0x0004TWINSTICK0x02008TO6 (right)
0x0008DPAD0x0400TWINSTICK 1P
0x0010ANALOG_FAST0x0800TWINSTICK 2P
0x0020ANALOG_SLOW0x1000TURBO
0x0040INTERLOCK

9. Linux, Batocera, RetroPie, Lakka Linux

The Linux side has only been tested in virtual machines so far — not yet on real cabinet hardware.

With PactoLink installed, the cabinet serves the configurator and an API on port 46810 (on the cabinet itself use 127.0.0.1; from another machine use its IP).

Switch a mode

curl -s -X POST -H "Content-Type: application/json" -d '{"id":1,"on":true}' \
  http://127.0.0.1:46810/api/v1/invoke/set_mode
idModeidMode
02 player6keyboard mode ("on":false = off)
14 player78-to-6 (on / off)
2twinstick8interlock (on / off)
3 / 4 / 5d-pad / analog fast / analog slow9 / 10twinstick 1P / 2P

pactolink-mode.sh takes the same names as Windows: ./pactolink-mode.sh 4p.

Live mode changes (no polling)

curl -N http://127.0.0.1:46810/api/v1/events

Every change arrives at once as data: {"event":"pacto://status","payload":{"mode_flags":…}}. pactolink_watch.py turns that into mode names and reconnects by itself — put your own action in on_change().

A mode per system on Batocera

batocera-mode-per-system.sh goes in /userdata/system/scripts/; Batocera runs it at every game start and stop. (For per-game settings, the Game profiles page of the PactoLink web page needs no script.)

From another machine, if the cabinet owner set a PIN, add -H "X-Pacto-Pin: 1234". On the cabinet itself no PIN is needed.

Troubleshooting

You seeWhy / fix
Connection refused / not reachableThe Pacto Tech Utility is not running — start it (tray icon).
controller rejected the commandNo controller connected, or a kiosk lock blocks that mode.
unknown modeTypo in the name — /modes lists them.
401 on /agent/…Missing or wrong key (agent_token.txt).
403 on /agent/…“Allow local AI agents” is off in App Settings.
Controller vanishes for a momentNormal after keyboard-on / keyboard-off: it restarts as a different device.