An AutoHotkey2 script that allows dragging the map while holding down a mouse button.
Intro
Given how the left and right mouse buttons work in-game, I find it best used on middle mouse but you can try whatever button or key you like.
Keep in mind this is pretty hacky and has no way of reacting to changing zoom levels, so you have to find a happy medium with the settings. YMMV as they say! 🙂
The basic steps:Â
1. Install AHK v2 or higher
2. Create/copy/paste the script
3. Tune the parameters to your tastes
4. Run the script and play the game
5. Use the mouse the drag the map!
Install AHK and run the Dash
https://www.autohotkey.com/download/
2. Run the AHK Dash
Create the Script
- In AutoHotkey Dash, choose New Script:
- Choose a name, an easily accessible file location, select the ‘Empty (Clean Slate)’ option, then click the ‘Edit’ button:
This should open a new blank script in Notepad by default, if not you can run Notepad or your editor of choice and manually open it.
- Copy/paste the following code, and save the file:
#Requires AutoHotkey v2.0
#SingleInstanceglobal DragButtonName := “MButton” ; LButton, RButton, MButton, XButton1, XButton2
global MouseDeltaPixels := 64 ; send a cursor press every 64 pixels of mouse movement
global MousePollRate := 16 ; check mouse movement every 16 ms
global WindowTitle := “Shadow Empire” ; only check when a window with this title is activeCoordMode(“Mouse”, “Screen”)
SetTimer MonitorMouseDrag, MousePollRate
global oldX, oldY := 0MonitorMouseDrag()
{
if !WinActive(WindowTitle)
{
return
}MouseGetPos(&xPos, &yPos)
if GetKeyState(DragButtonName)
{
CheckAndSend(xpos, &oldX, “{Left}”, “{Right}”)
CheckAndSend(ypos, &oldY, “{Up}”, “{Down}”)
}
else
{
global oldX := xpos
global oldY := ypos
}
}CheckAndSend(currentPos, &oldPos, negativeKey, positiveKey)
{
if currentPos > oldPos + MouseDeltaPixels
{
Send(negativeKey)
oldPos := currentPos
}
else if currentPos < oldPos – MouseDeltaPixels
{
Send(positiveKey)
oldPos := currentPos
}
}
Tune the parameters
It has no way of knowing your preferred zoom level or in-game DPI setting, so some tweaking of the following will likely be required. The defaults at the top of the script are based on my 4k screen running 150% DPI.
global MouseDeltaPixels := 64 ; send a cursor press every 64 pixels of mouse movement
global MousePollRate := 16 ; check mouse movement every 16 ms
- DragButtonName: the button to be held while dragging the map. I use the middle, as left will modify selection and right will move or bring up the context menu. You can also use mouse buttons 4 or 5 (XButton1 or XButton2) or any single key.
- MouseDeltaPixels: the number of pixels the mouse needs to move before a cursor key press is triggered.
- MousePollRate: how frequently to check the mouse, in milliseconds. The default of 16 equates to checking 60 times per second. If you typically make big, fast movements try a value of 8 for 120 checks per second. The more checks, the more processing is required (but I don’t think it should really be an issue on modern hardware).
Save the file after making any changes.
Run the script, and play the game
Do this again after making any changes, to reload and run the updated version.
If everything is working, you’ll see AHK in your system tray. You can also quit AHK by right-clicking here:
Play the game, and try dragging the map with your chosen button.
- If you feel you need to move the mouse too far, decrease MouseDeltaPixels.
- If you feel the movement is too sensitive, increase MouseDeltaPixels.
- If you feel the movement is not responsive enough to big mouse movements, decrease MousePollRate.
Adding some extra functionality
For example, I use mouse button 4 (XButton1) as the ‘Escape’ key, and mouse 5 to open the management screen. The syntax is the thing to press, 2 colons, then the key to send when that thing is pressed.
XButton1::Esc
XButton2::N
There is a full list of things you can bind in the docs here:
https://www.autohotkey.com/docs/v2/KeyList.htm
And that wraps up our share on Shadow Empire: AHK Map Mouse Drag. If you have any additional insights or tips to contribute, don’t hesitate to drop a comment below. For a more in-depth read, you can refer to the original article here by profanicus, who deserves all the credit. Happy gaming!