[X3AP] Point and click commands using AutoHotKey

The place to discuss scripting and game modifications for X³: Terran Conflict and X³: Albion Prelude.

Moderators: Moderators for English X Forum, Scripting / Modding Moderators

Post Reply
Gwizzz
Posts: 7
Joined: Sat, 15. Dec 07, 01:50
x3

[X3AP] Point and click commands using AutoHotKey

Post by Gwizzz » Sat, 7. Dec 13, 11:53

FUNCTION:
This is an AutoHotKey macro script to provide some point and click commands plus other useful macro commands to help simplify using the X3AP menu system.

INSTALLATION
1. Download and install AutoHotKey from http://www.autohotkey.com.
2. Copy and paste the script text into Notepad and save it with whatever name you like as long as it ends in .ahk Example: X3AP PNCP.ahk
3. Double click on the newly created icon and it will load into AutoHotKey ready for use in the X3AP.

As always, before using for the first time, backup your save games.

This works with X3AP running windows 7. It should work with Windows XP, and may work with Windows 8.

The script is heavily commented and serves to act as both program and documentation. Read though the script to see which commands are supported, which keys are mapped, and how to use them.
You can change the key mappings by referring to the AutoHotKey documentation on their website.

Supported Point and Click commands include:
Move to Position
Dock at [specified location]
Dock at [specified location] in another sector
Dock at My target
Attack [specified target]
Attack My Target.

Other key combination macros include:
Attack All Enemies
Protect Me
Defend Position
Defend Station
Defend Sector
Cancel orders and go into Standby
Player ship undock from station and immediately go into Standby
NPC ship salvager
Player ship salvager

Other menus commands can be added following the same structure in the script. Feel free to post your new commands macros.

LIMITATIONS:
The script works by sending key inputs to mimic selecting menu numbers associated with various commands. The menu commands can change depending on what software is installed in a ship. I tried to keep to some pretty basic commands that most ships would have available. If you don’t have Fight Command software in your TS, don’t activate the Attack Target command. The macro will still execute and may cause unwanted results. Use common sense when using the macros.

I would like to be able to call scripts directly like S9ilent's Vocal Control (SVC). That would open up a lot more script commands to direct input without resorting to using the menus.

There are some delays between sending key inputs to X3 denoted by the Sleep command. Depending on how fast (or slow) your computer is, you may have to adjust these values. If the commands don’t seem to be completing correctly try increasing the delay values. If you have a super-fast system you can decrease or comment out the delays as long as the commands still complete when you activate the hotkey.

CREDIT TO:
kurush for his tuning finder AutoHotKey script that showed how to use #UseHook On, and SendInput to get AutoHotKey to work with X3AP.
Unknown poster (I can’t find the original post) that mentioned pressing a numpad key while in the sector map would move the cursor off the station and allow you to click ANYWHERE to use the Move to Position command in open space.
Of course the developer of AutoHotKey!

Code: Select all

; X3AP PNCP.ahk (Point and Click Plus macro commands for X3AP)
; Version 1.2  
; AutoHotkey	v1.0.48.05 http://www.autohotkey.com/
; Language:	English
; Platform:	Windows XP, 7, 8? 
; Author:	Gwizzz (Steam and EGOsoft) 
; Function: Simplify menu commands in X3 Albion Prelude using point and click and Hotkey macros (may work with X3TC*)
; Input key/mouse command mapping can be changed to suit your needs.  It is recommended that you use multiple
; keys to activate these macros and don't assign them to anything already in use in X3.
; For example don't assign the "Dock at" macro to SHIFT+D if that is already assigned to the Dock At command in X3.
; See the AutoHotkey reference for specific key and mouse shortcuts http://www.autohotkey.com/docs/Hotkeys.htm


; Uses common windows sound files to inform you of its status:  
; Exclamation sound = ready for your input
; Critical Stop sound = input not received, aborting command

#IfWinActive ahk_class X3AP ; Macros will only execute if X3AP is the active window. 

#UseHook On ; required for the command SendInput to work with X3

; *** START OF MACROS  ***

; Command a ship to "MOVE TO POSITION" at a [selected location] in the SAME sector
; Mapped to CONTROL+LEFT MOUSE BUTTON
; Works in cockpit screen, sector map. sector map ship list (on the right). 
; DOES NOT WORK INSIDE STATIONS OR SHIPS.  
; To use: Hold [Control] and click a ship, wait for the menu commands to execute.  
; When you hear the ready for input sound, left click, in the SAME sector, where you want the ship to move to.
^LButton::		; <--- Control+Left Mouse Button assigned here.  See Autohotkey docs for list of possible key maps
SendInput c		; Send c to open the command console of the ship you click on.
Sleep 300		; delay 300ms or .3 sec.
SendInput 1		; Select option #1,navigation
Sleep 300
SendInput 9		; Select option #9, Move to position
Sleep 300
SendInput {Enter}	; Virtual press [Enter] key to select the current sector
Sleep 400
SendInput {Numpad8}	; By default Numpad8 is set to "move cursor up" in the sector map.
			; Press Numpad 8 once moves the target cursor off of the station and 
			; allows you to click anywhere on the sector map, even in between stations
			; If you remapped the sector move up key, you'll need to update it in this macro
Sleep 400		; a longer delay is required here to allow the sector map cursor to activate
SoundPlay, C:\Windows\Media\Windows Exclamation.wav	; sound ready for dock or ship selection
ErrorLevel = 0	; Set Errorlevel to Known OK value
KeyWait, LButton, D T10 ; Set to wait for 10 seconds for you to click a position or the command aborts
if ErrorLevel ; If 10 seconds elapse with no mouse input, generate an error, sound an alert and escape back to the map
	{
	SoundPlay, C:\Windows\Media\Windows Critical Stop.wav
	SendInput {ESC 3} ; Esc back 3 times
	Return
	}
else				; continue when a mouseclick is detected 
	{	
	Sleep 400
	SendInput {Enter}	; Virtual press [Enter] performs a double click action
	Sleep 500
	SendInput {Esc}		; Escape back to the sector map 
	Return  
	}

; Command a ship to "DOCK AT" a [specified location] in the SAME sector
; Mapped to: ALT+LEFT MOUSE BUTTON 
; Works in: cockpit screen, sector map. sector map ship/station list (on the right). 
; DOES NOT WORK INSIDE STATIONS OR SHIPS.  Use "Dock at My target" for ships landed inside ships or stations.
; To Use: press [ALT] then Left click on a ship to dock, wait for the sound, then click on a ship or station to dock at.
!LButton::	; <--- ALT+Left Mouse button assigned here. "!" is ALT
SendInput c	; Open the Command Console of the ship you click on
Sleep 300	 
SendInput 1	
Sleep 300
SendInput 4	
Sleep 400
SendInput {Enter} 
Sleep 400
SoundPlay, C:\Windows\Media\Windows Exclamation.wav	; audible tone to let you know to select a carrier class ship or station
Sleep 400	
ErrorLevel = 0	; Set Errorlevel to known OK value
KeyWait, LButton, D T10 ; Set to wait for 10 seconds for you to make a selection
if ErrorLevel ; If 10 seconds elapse with no mouse input, generate an error, sound an alert and abort the command
	{
	SoundPlay, C:\Windows\Media\Windows Critical Stop.wav
	SendInput {Esc 3} ; Esc back 3 times to the sector map
	Return	
	}
else				; continue if mouse click is detected
	{	
	Sleep 400
	SendInput {Enter}	; Virtual press of the [Enter] key which automatically confims your selection
	Sleep 500 		
	SendInput {Esc}		; back up to the sector map so you can select more ships to command
	Return  
	}
Return

; Command a ship to "DOCK AT" a [selected location] in ANOTHER sector
; Mapped to: SHIFT+CONTROL+LEFT MOUSE BUTTON 
; Works in: cockpit screen, sector map. sector map ship/station list (on the right). 
; DOES NOT WORK INSIDE STATIONS OR SHIPS.  Use "Dock at My target" for ships landed inside ships or stations.
; To Use: press [Shift] AND [Control] then Left click on a ship to dock. Select a sector then click on a ship or station to dock at.
; When the galaxy map appears, select and enter a sector then select a carrier ship or station by double clicking on it as normal.
; This is not as completely automated as docking in the same sector as there too many variables to consider when choosing the sector to dock at.
; If the ship has a jumpdrive and enough energy cells it will jump to the new sector, otherwise it will fly there.
; If you want a jump warning message, manually select Jump to Sector, or Jump and Fly to Station
+^LButton::	; <--- Shift+Ctrl+Left Mouse button assigned here
SendInput c	
Sleep 300	
SendInput 1	
Sleep 300
SendInput 4	
Return


; Dock at MY TARGET (Must specify a dock at "target" before issuing the command)
; Only use on ships inside stations or carriers that are to be transferred to another ship or station
; If no target is selected the ship will go IDLE but the DOCKING COMMAND ACCEPTED message will still play
; To use: YOU MUST BE UNDOCKED IN THE SAME SECTOR as the ships and the docking target
; Select a target, right click on it so it has >> >> next to its name in the ship/station list on the right side of the sector map
; left Click on a ship or station that has ships to move
; Select "Landed ships"
; When the list of landed ships appears, hold down [ALT] and right click on each ship to move to the target ship or station
; This is useful for quickly transferring a lot of ships from a carrier (Aran) to your PHQ, or vis versa
; Mapped to ALT+RIGHT MOUSE BUTTON
!RButton::
SendInput c
Sleep 400
SendInput 1
Sleep 400
SendInput 2
Sleep 400
SendInput {ESC}
Return

; Command a ship to "Attack [selected target]" 
; Mapped to WINDOWS KEY+LEFT MOUSE BUTTON, 
; Works in sector map, sector map ship list (right side), cockpit view
; DOES NOT WORK INSIDE STATIONS OR SHIPS.    
; To use: Press the [WINDOWS] key and click on the ship you want to command, wait for the ready for input sound, click on the ship to attack
#LButton::
SendInput c
Sleep 400
SendInput 2 ; Combat
Sleep 400
SendInput 1 ; Attack
Sleep 300
SendInput {Enter} 	; select current sector
;Sleep 300
;ErrorLevel = 0	; Set Errorlevel to known OK value
KeyWait, LButton, D T10 ; Set to wait for 10 seconds for you to make a selection
if ErrorLevel ; If 10 seconds elapse with no mouse input, generate an error, sound an alert and abort the command
	{
	SoundPlay, C:\Windows\Media\Windows Critical Stop.wav
	SendInput {Esc 3} ; Esc back 3 times to the sector map
	Return	
	}
else				; continue if mouse click is detected
	{	
	Sleep 300 		
	SendInput {Enter}	; Virtual press of the [Enter] key which automatically confims your selection
	Sleep 400
	SendInput {Esc}		; back up to the sector map so you can select more ships to command
	Return  
	}
Return


; Command a ship to "Attack My target" 
; You must specify a target to attack before using this command
; Mapped to ALT+WINDOWS KEY+LEFT MOUSE BUTTON, 
; Works in cockpit view, sector map, 
; DOES NOT WORK INSIDE STATIONS OR SHIPS.  
; To use: select a target, right click on it so it has >> >> next to it's name in the ship/station list on the right side of the sector map
; Press the [WINDOWS] and [ALT] keys at the same time then click on the ship you want to attack your target
; As long as you have the enemy ship targeted you can continue to Left click on your ships while pressing [WINDOWS KEY] + [ALT]
; and each ship should join in to attack the same target.
!#LButton::
SendInput c
Sleep 300
SendInput 2
Sleep 300
SendInput 5
Sleep 300
SendInput {Esc}
Return

; Command a ship to "Attack All Enemies" 
; Mapped to WINDOWS KEY+e
; Works in cockpit view, sector map, 
; DOES NOT WORK INSIDE STATIONS OR SHIPS.  
; To use: left click to select a friendly target, press [WINDOWS] key and [e]
#e::
SendInput c
Sleep 300
SendInput 2
Sleep 300
SendInput 2
Sleep 300
SendInput {Esc}
Return


; Command a ship to "Protect me" 
; Mapped to WINDOWS KEY+p
; Works in cockpit view, sector map, 
; DOES NOT WORK INSIDE STATIONS OR SHIPS.  
; To use: Left click a friendly ship, press [WINDOWS] key and [p]
#p::
SendInput c
Sleep 300
SendInput 2
Sleep 300
SendInput 3
Sleep 300
SendInput {Esc}
Return


; Command a ship to "Defend position" in the SAME sector
; Mapped to WINDOWS KEY+d
; Works in cockpit view, sector map, 
; DOES NOT WORK INSIDE STATIONS OR SHIPS.  
; To use: Left click a friendly ship, press [WINDOWS] key and [d]
; When you hear the ready for input sound, click on the location to defend
#d::
SendInput c
Sleep 300
SendInput 2
Sleep 300
SendInput 7
Sleep 400
SendInput {Enter}	; Virtual press [Enter] key to select the current sector
Sleep 400
SendInput {Numpad8}	; By default Numpad8 is set to "move cursor up" in the sector map.
			; Press Numpad 8 once moves the target cursor off of the station and 
			; allows you to click anywhere on the sector map, even in between stations
			; If you remapped the sector move up key, you'll need to update it in this macro
Sleep 400		; a longer delay is required here to allow the sector map cursor to activate
SoundPlay, C:\Windows\Media\Windows Exclamation.wav	; sound ready for dock or ship selection
ErrorLevel = 0	; Set Errorlevel to Known OK value
KeyWait, LButton, D T10 ; Set to wait for 10 seconds for you to click a position or the command aborts
if ErrorLevel ; If 10 seconds elapse with no mouse input, generate an error, sound an alert and escape back to the map
	{
	SoundPlay, C:\Windows\Media\Windows Critical Stop.wav
	SendInput {ESC 3} ; Esc back 3 times
	Return
	}
else				; continue when a mouseclick is detected 
	{	
	Sleep 400
	SendInput {Enter}	; Virtual press [Enter] performs a double click action
	Sleep 500
	SendInput {Esc}		; Escape back to the sector map 
	Return  
	}

; Command a ship to "Defend station" in the SAME sector
; Mapped to WINDOWS KEY+s
; Works in cockpit view, sector map, 
; DOES NOT WORK INSIDE STATIONS OR SHIPS.  CAN NOT SELECT A TARGET
; To use: left click to select a friendly target, press [WINDOWS] key and [s]
; When you hear the ready for input sound, click on the location to defend
#s::
SendInput c
Sleep 300
SendInput 2
Sleep 300
SendInput 8
Sleep 400
SendInput {PgDn}	; Virtual press [Page Down] key to go to the last selection choice
Sleep 400
SendInput {Enter}	; Virtual press [Enter] key to select the current option
Sleep 400
SendInput {Enter}	; Virtual press [Enter] key to select the current sector
Sleep 400
SoundPlay, C:\Windows\Media\Windows Exclamation.wav	; sound ready for dock or ship selection
ErrorLevel = 0	; Set Errorlevel to Known OK value
KeyWait, LButton, D T10 ; Set to wait for 10 seconds for you to click a position or the command aborts
if ErrorLevel ; If 10 seconds elapse with no mouse input, generate an error, sound an alert and escape back to the map
	{
	SoundPlay, C:\Windows\Media\Windows Critical Stop.wav
	SendInput {ESC 3} ; Esc back 3 times
	Return
	}
else				; continue when a mouseclick is detected 
	{	
	Sleep 400
	SendInput {Enter}	; Virtual press [Enter] performs a double click action
	Sleep 500
	SendInput {Esc}		; Escape back to the sector map 
	Return  
	}

; Command a ship to "Defend sector" in the SAME sector the ship  is in
; Mapped to WINDOWS KEY+z (for zone)
; Works in cockpit view, sector map, 
; DOES NOT WORK INSIDE STATIONS OR SHIPS.  CAN NOT SELECT A TARGET
; To use: left click to select a friendly target, press [WINDOWS] key and [z]
#z::
SendInput c
Sleep 300
SendInput 2
Sleep 300
SendInput 9
Sleep 400
SendInput {PgDn}	; Virtual press [Page Down] key to go to the last selection choice
Sleep 400
SendInput {Enter}	; Virtual press [Enter] key to select the current option
Sleep 1000
SendInput {Enter}	; Virtual press [Enter] key to select the current sector
Sleep 1000
SendInput {Esc}		; Escape back to the sector map 
Return


; Cancel active command and put the ship in STANDBY mode
; Mapped to WINDOWS KEY+x
; Works in Sector Map, cockpit view
; DOES NOT WORK INSIDE STATIONS OR SHIPS.
; To use: left click [highlight] on one of your ships and press [WINDOWS] key and [x]
#x::
SendInput c
Sleep 300
SendInput 1 ; Navigation
Sleep 300
SendInput 1 ; Standby
Sleep 300
SendInput {Esc}
Return

; IMMEDIATE UNDOCK and put ship into STANDBY mode
; Mapped to WINDOWS KEY+u
; NOTE: the following Sleep delays are commented out.  If the commands don't activate immediately you'll get an error that the STANDBY command 

can not be completed because you are to close to the station.
#u::
SendInput {Del}		;Sends the command to close all open menus
SendInput {Enter}	;Presses [Enter} to UNDOCK
;Sleep 300		
SendInput +c		; Activate the current ships command console (THIS IS +c by DEFAULT)
;Sleep 300
SendInput 1	; Navigation
;Sleep 200	; Extra delay to get clear of the station
SendInput 1	; Standby
;Sleep 300
SendInput {Esc}
Return

; NPC ship Sector Salvager
; Must have the salvage MOD installed
; Mapped to WINDOWS KEY+g (for Get the goods!)
; Works in Sector Map, cockpit view
; DOES NOT WORK INSIDE STATIONS OR SHIPS.
#g::
SendInput c
Sleep 400
SendInput 5 ; Piracy menu
Sleep 400
SendInput 1 ; Sector Salvager
Sleep 400
SendInput {Esc}
Return

; Player ship Sector Salvager
; Must have the salvage MOD installed
; Mapped to ALT+WINDOWS KEY+g (for Get the goods!)
; Works in Sector Map, cockpit view
; DOES NOT WORK INSIDE STATIONS OR SHIPS.
!#g::
SendInput +c
Sleep 400
SendInput 5 ; Piracy menu
Sleep 400
SendInput 2 ; Sector salvager
Sleep 400
SendInput {Esc}
Return

Rwin::Return ; Right Windows key is disabled, preventing it from switching out of the game window
I hope you find it as useful as I do. Cheers and good gaming.

Gwizzz

EDIT: Corrected a fragmented line in the script code.
Pasted in revised 1.1 code
Rev 1.2 removed line in code:
#IfWinActive ahk_class X3TC ; Macros will run if X3TC is the active window.
Both of the X3AP and X3TC checks can't be active at the same time. If you play TC change X3AP to X3TC in the macro code and it should work.

Last edited by Gwizzz on Wed, 8. Jan 14, 11:52, edited 2 times in total.

User avatar
Jack08
Posts: 2993
Joined: Sun, 25. Dec 05, 10:42
x3tc

Post by Jack08 » Thu, 12. Dec 13, 06:17

AutoHotKey key remapping isn’t supported for Windows 95, 98, ME. There is a suggested alternative syntax at http://www.autohotkey.com/docs/misc/Remap.htm#Win9x.
Since I don’t run Win 9x/ME I don’t know if it would work with this script. If you are running an older version of windows and want to modify this script with the suggested changes, let us know if it works.
Errm... If anyone still still on 9x or ME - they wouldnt be playing X....
[ external image ]
"One sure mark of a fool is to dismiss anything that falls outside his experience as being impossible."
―Farengar Secret-Fire

Patholos
Posts: 821
Joined: Fri, 16. Apr 10, 11:24
x4

Post by Patholos » Fri, 13. Dec 13, 05:09

I tip my space hat at you.

This is exactly what I've been looking for, but never got into autohotkey.

Thanks a bunch :wink:
Sure glad I didn't purchase a new computer this release.

Gwizzz
Posts: 7
Joined: Sat, 15. Dec 07, 01:50
x3

Post by Gwizzz » Thu, 19. Dec 13, 04:01

Sorry for the delay getting back to respond and do a little clean up. I lost a 400+ hour X3AP game due to a corrupted save problem. So I've been reinstalling the multitude of mods in preparation to start anew. I play a highly modified game that usually involves more combat than trading or complex building. I started as an Argon Peacekeeper and was always jumping around helping the poor Argons against Xenons, Terrans, Kha'ak, Pirates, and Paranid. I had 3 M2s (Atlas, Akuma, Phoenix), 2 M1s (Aran and J), a dozen misc M6s, a couple of TLs, dozen of TS, and a smattering of fighters. I completed the PHQ quest and had started a factory complex but some new mods weren't installing correctly. After installing, and reinstalling.. my saves didn't match the scripts anymore and started to CTD. So I decided to get everything installed correctly and then start from scratch. I finally figured out how to get the XSP ships to spawn and have been joyfully checking them out to see which ones I want in my X'verse.

@Jack08
Thanks for the clarification on the OS that X3TC/AP run under. I started with X3 Reunion and am pretty sure it ran under 9x/ME as well as XP.
I deleted the reference to using this macro with 9x/ME.

@Patholos thanks for the thanks, I'm glad to see someone is using it. I was expecting a little more hoopla since one of the main complaints I've read about the X3 games is having to click though a bunch of menus to perform basic commands.

Here's a couple of changes to the original post and to the Rev 1.1 code:

Removed the semicolon in front of the line:
#IfWinActive ahk_class X3TC ; Macros will run if X3TC is the active window.
The two #If WinACTIVE lines (one for TC and one for AP) appear to work as OR logic. If you are running either then the macros will work in the game. Outside of the game, the point and click macros won't function and any [WINDOWS KEY] + [KEY] revert to their default Windows function.
Example: WINDOWS KEY + e will open a new explorer window and not cause you to attack all enemies. :wink:

Changed the Command Console selection from +c to c and vis versa where used.
By default Shift+c brings up the Command Console for the current ship and c will comm another ship or station. I swapped these around in
my personal keymap setup and forgot to set it back for default users macros. Sorry if it was a bit confusing or just didn't work.

Fixed the Attack [Selected target] macro. It was missing a SendInput {Enter} command that prevented it from completing correctly.

Let me know if there are any other problems, questions, or suggestions.

Gwizzz

Post Reply

Return to “X³: Terran Conflict / Albion Prelude - Scripts and Modding”