Page 1 of 3

Keys for attack, char. swapping (autohotkey script, v 0.4)

Posted: Wed Apr 11, 2012 11:32 pm
by d32
Updated to v 0.4; Added character swapping by techzen, Adakos
--
Hello everyone. After half an hour with the game, I just had to find a way how to do the attacks by key-presses. Here it is:

1.) Download Autohotkey at http://www.autohotkey.com/
2.) Download the script file from mediafire: link

OR

Create file named 'grimrock.ahk' on your desktop (or anywhere else on your computer).
Paste the code found below into the file.
Save the file

3.) Doubleclick the file.
4.) :D Enjoy following features:

- Activate right hands attacks of your characters by pressing keys: j k m,
- Left hands attacks by pressing keys: l ; ./
- Open the inventory of the first character by pressing i

- Swap two left characters by pressing 9
- Swap two left characters by pressing 0
- Swap both columns with Caps
- Swap and attack with the front row immediately: o p

Sorry, still no spellcasting support. (look at posts below for partial solution)

Keys can be changed inside the file, towards the end; look for "j::" and similar.
Consider this beta version, not much tested.

Debug/tweaking:
SpoilerShow
- if the script seems to miss the right areas to perform attack, press ctrl+t; mouse will try to run around your characters. If the rectangle is bigger/smaller than it should be, you can adjust the xAdjust & yAdjust variables in the script to modify its size (>1 means bigger - 1.1 means 110% - <1 means smaller, x for width y for height).
- If the swapping doesn't seem to work or has a side-effects (inventory opening etc), try increasing swapDelay value inside the file
Changelog:
SpoilerShow

v 0.4
- merged with character swapping by techzen, Adakos

v 0.3:
- no need to enter the resolution manually
- mouse now returns to the original position after attacking
- much better support for different resolutions
- debug shortcut, accuracy tweaking

v 0.2:
- support for different aspect ratios, including 16:10 (1920x1200) and 16:9 (1920x1080)

Code: Select all

; Legend of Grimrock
;  Attack keys v 0.2
; Autohotkey Script
;   Created by d32
; Character swapping by techzen, Adakos
; Download Autohotkey at: http://www.autohotkey.com/
#SingleInstance force
SetTitleMatchMode, 2
SetDefaultMouseSpeed, 0
CoordMode, Mouse,

xAdjust := 1 ; Accuracy adjustment for the X axis
yAdjust := 1 ; Accuracy adjustment for the Y axis

swapDelay := 20

; relative positions of weapon slots and character bars
dx1l := 0.14 ; X position of 1st and 3rd char left hand
dx2l := 0.62 ; X position of 2nd and 4th char left hand
dx1r := 0.34 ; X position of 1st and 3rd char right hand
dx2r := 0.81 ; X position of 2nd and 4th char right hand
dy1  := 0.32 ; Y position of 1st and 2nd char hands
dy2  := 0.79 ; Y position of 3rd and 4th char hands

dy1b  := 0.15 ; Y position of 1st and 2nd char portrait
dy2b  := 0.63 ; Y position of 3rd and 4th char portrait

; reads the resolution, determins the corner of characters' rectangle
init()
{
	global
	sysget, resX, 0
	sysget, resY, 1
	chHei := resY * 0.32
	if (chHei > 345) chHei := 345 ; this seems to be maximum height of the characters' bar
	chWid := chHei / 0.76
	
	chWid := chWid * xAdjust
	chHei := chHei * yAdjust
	
	chX := resX-chWid
	chY := resY-chHei
}

storeMousePos() 
{
	global
	MouseGetPos, mX, mY
}

restoreMousePos() 
{
	global
	MouseMove, mX, mY
}

rightClickAndReturn(x, y)
{
	global
	init()
	storeMousePos()
	MouseClick, right, x, y
	restoreMousePos()
	return
}

attackTopLeft() {
	global
	rightClickAndReturn(chX+(chWid*dx1l),  chY+(chHei*dy1))
}

attackTopRight() {
	global
	rightClickAndReturn(chX+(chWid*dx2l),  chY+(chHei*dy1))
}

swapAtX(xPos) {
	global
	BlockInput On
	MouseMove, xPos,  chY+(chHei*dy2b)
	Sleep swapDelay
	
	SendEvent {LButton down}	
	Sleep swapDelay
	
	MouseClickDrag, left, xPos,  chY+(chHei*dy2b), xPos,  chY+(chHei*dy1b)
	SendEvent {LButton up}

	BlockInput Off
}

swapLeft() {
	global
	swapAtX(chX+(chWid*dx1r))
}

swapRight() {
	global
	swapAtX(chX+(chWid*dx2r))
}

#IfWinActive Grimrock ahk_class EWindowClass

init()

i::1
j::attackTopLeft() ;Attack with top left character's right hand
k::attackTopRight() ;Attack with top right character's right hand
m::rightClickAndReturn(chX+(chWid*dx1l),  chY+(chHei*dy2)) ;Attack with bottom left character's right hand
,::rightClickAndReturn(chX+(chWid*dx2l),  chY+(chHei*dy2)) ;Attack with bottom right character's right hand

l::rightClickAndReturn(chX+(chWid*dx1r),  chY+(chHei*dy1)) ;Attack with top left character's left hand
`;::rightClickAndReturn(chX+(chWid*dx2r),  chY+(chHei*dy1)) ;Attack with top right character's left hand
.::rightClickAndReturn(chX+(chWid*dx1r),  chY+(chHei*dy2)) ;Attack with bottom left character's left hand
/::rightClickAndReturn(chX+(chWid*dx2r),  chY+(chHei*dy2)) ;Attack with bottom right character's left hand

; Swap left characters and attack
o:: 
{
	Keywait o
	storeMousePos()
	swapLeft()
	;sleep 50
	restoreMousePos()
	sleep swapDelay
	attackTopLeft()
	return
}

; Swap right characters and attack
p:: 
{
	Keywait p
	storeMousePos()
	swapRight()
	;sleep 50
	restoreMousePos()
	sleep swapDelay
	attackTopRight()
	return
}

; Swap left characters
9::
{
	storeMousePos()
	swapLeft()
	restoreMousePos()
	return
}

; Swap right characters and
0:: 
{
	storeMousePos()
	swapRight()
	restoreMousePos()
	return
}

; Swap both left and right chars
Capslock::
{
	storeMousePos()
	swapLeft()
	swapRight()
	restoreMousePos()
	return
}

; Debug test
^t::
{
	init()
	MouseMove, chX, resY-10, 6
	MouseMove, chX, chY, 6
	MouseMove, resX-10, chY, 6
	MouseMove, resX-10, resY-10, 6
	MouseMove, chX, resY-10, 6
	return
}
#IfWinActive

Re: Keys for attack - Solution (autohotkey script)

Posted: Wed Apr 11, 2012 11:42 pm
by e8hffff
This is a round about way. Lets hope Game maker bring out proper key binding option for most actions.

Re: Keys for attack - Solution (autohotkey script)

Posted: Wed Apr 11, 2012 11:52 pm
by Yosharian
Edit: never mind, I figured it out. I think you mixed up the key sets.

This is a neat solution but it's not the best because when you press the key, it moves the cursor to the weapon/object being activated. I use the mouse to wheel the view around so this results in me having to move the cursor back to the middle of the screen so I can begin wheeling the view again.

Perhaps there is a way to get the Autohotkey script to move the cursor back to the middle of the screen after performing the 'click'?

Re: Keys for attack - Solution (autohotkey script)

Posted: Thu Apr 12, 2012 12:08 am
by Kthanid
Very cool idea to workaround the lack of keys. Will definitely be messing with this script tonight. Thanks.

Re: Keys for attack - Solution (autohotkey script, v 0.2)

Posted: Thu Apr 12, 2012 12:17 am
by d32
Fixed the script to work with different aspect ratios (eg 1920x1080).
Redo the steps 3-6 for the update. (Don't forget to re-enter your resolution)

Yosharian: yes, mouse cursor gets moved as this is the only way I found. It would be possible to send cursor to the center of the screen.

Re: Keys for attack - Solution (autohotkey script, v 0.2)

Posted: Thu Apr 12, 2012 12:20 am
by Yosharian
d32 wrote:Fixed the script to work with different aspect ratios (eg 1920x1080).
Redo the steps 3-6 for the update. (Don't forget to re-enter your resolution)

Yosharian: yes, mouse cursor gets moved as this is the only way I found. It would be possible to send cursor to the center of the screen.
Ok, how? That's what I need, for the click to be sent and then the cursor returns to the centre of the screen.

Re: Keys for attack - Solution (autohotkey script, v 0.2)

Posted: Thu Apr 12, 2012 12:28 am
by d32
I will try to return the cursor to the original position after the click is sent, in the next version of the script.
However, I need to get to bed now, see you tomorrow.

Re: Keys for attack - Solution (autohotkey script, v 0.2)

Posted: Thu Apr 12, 2012 12:29 am
by Kthanid
If I get a chance tonight (and don't get too wrapped up being enthralled by the game) I'll take a stab at modifying his script to do this.

Re: Keys for attack - Solution (autohotkey script, v 0.2)

Posted: Thu Apr 12, 2012 1:16 am
by techzen
Here is an autohotkey script I wrote that will move your characters from back to front so you can melee attack etc. Spacebar and Capslock moves them.

This will only work if you play in fullscreen 1920x1080, but you can edit the file however you like. After hitting space or caps, the cursor will hover over the first equipped item square for easy left clicking should you need to. If you want to change how the mouse moves, open up fraps and take a screenshot of the game while playing. Open that in paint and move the cursor around. At the bottom right you will see the current mouse coordinates, that's how I found them anyway.

I made this for people who may have trouble moving the mouse quick enough or accurate enough for whatever reason that may be. Btw, use the "-" key on the numpad to suspend the script so you can hit space without it moving the mouse around etc.

Oh and to move the mouse to the center of the screen after a part of a script, just add this to the end of the relevant section.

Sleep 50
Mousemove x, y

Replace the x and y with your resolution settings divided by 2. That should put the cursor in the middle of your screen again.

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory. ##831, 441, 437

Numpadsub::suspend

SendMode Play
#SingleInstance
 

 
Space::

Keywait Space
BlockInput On
Mousemove 1500, 950
Sleep 50
SendEvent {LButton down}

Sleep 50

MouseClickDrag, left, 1500, 950, 1500, 750

SendEvent {LButton up}

Sleep 50

MouseMove 1533, 846

BlockInput Off

return

Capslock::

Keywait Capslock
BlockInput On
Mousemove 1715, 950
Sleep 50
SendEvent {LButton down}

Sleep 50

MouseClickDrag, left, 1715, 950, 1715, 750

SendEvent {LButton up}

Sleep 50

MouseMove 1745, 846

BlockInput Off

return
Here is how I hotkey spells, you can put this in the same script file. This is meant to give you a way to make your own and edit them how you see fit. It's actually very easy. It's a bit of a spoiler so hopefully I can do code within a spoiler tag.
SpoilerShow

Code: Select all

F3::  ;Fireburst

Keywait F3

BlockInput On

MouseMove 1745, 1015        ;moves mouse to the bottom right character, first equipment slot, which is my want for spell casting.  
Sleep 50

Click right
Sleep 50

MouseMove 1725, 950    ;chooses the appropriate symbol
Sleep 50

Click
Sleep 50

MouseMove 1858, 1018   ;moves mouse to casting icon
Sleep 50

MouseClick, right

BlockInput Off

return

F4::  ;Poison Cloud

Keywait F4

BlockInput On

MouseMove 1745, 1015
Sleep 50

Click right
Sleep 50

MouseMove 1725, 1040
Sleep 50

Click
Sleep 50

MouseMove 1858, 1018
Sleep 50

MouseClick, right

BlockInput Off

return

Re: Keys for attack - Solution (autohotkey script, v 0.2)

Posted: Thu Apr 12, 2012 6:22 am
by Yosharian
Ok brilliant, I figured it out. Thanks guys, this is a real help.