Shadow Empire

Shadow Empire

Ei tarpeeksi arvosteluja
AHK Map Mouse Drag
Tekijältä profanicus
An AutoHotkey2 script that allows dragging the map while holding down a button.
   
Palkinto
Lisää suosikkeihin
Lisätty suosikkeihin
Poista suosikeista
Intro
This is an AutoHotkey script to allow basic dragging of the game map while holding down a mouse button and moving the mouse. Until we get proper in-game support I figured others may also find it useful, so am sharing.

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
1. Download and install AutoHotkey v2 or higher

https://www.autohotkey.com/download/

2. Run the AHK Dash
Create the Script
  1. In AutoHotkey Dash, choose New Script:


  2. 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.

  3. Copy/paste the following code, and save the file:
    #Requires AutoHotkey v2.0 #SingleInstance global 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 active CoordMode("Mouse", "Screen") SetTimer MonitorMouseDrag, MousePollRate global oldX, oldY := 0 MonitorMouseDrag() { 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
The script works by checking the mouse every 16 milliseconds, and if it has moved 64 pixels while the button is held, a cursor press is sent to the game to move the map.

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 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

  • 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
To run the script, use Explorer to locate where you saved it earlier and double-click it.
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
At the bottom of the script, you can add any other button or key mappings you might want.

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.

#HotIf WinActive(WindowTitle) 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

1 kommenttia
Imhotep 17.2. klo 19.39 
Essential mod!