Autohotkey keyboard script

Talk about anything Legend of Grimrock 1 related here.
Post Reply
Bigpet
Posts: 2
Joined: Thu Aug 28, 2014 1:27 am

Autohotkey keyboard script

Post by Bigpet »

So I tried to make an Autohotkey script to allow playing via keyboard only but I got bored halfway through but I thought
"why not put what you already did online"

I just hardcoded everything for 1920x1080 fullscreen (or borderless) so here it is:

Code: Select all

; IMPORTANT INFO ABOUT GETTING STARTED: Lines that start with a
; semicolon, such as this one, are comments.  They are not executed.

;Legend of Grimmrock Keyboard controller

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Variables
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
LastCharX := 1485
LastCharY := 755
isCasting := false
MPosX := 1458
MPosY := 755
MStep := 60
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Constants (currently hard-coded for 1920x1080 fullscreen or windowed fullscreen)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;Root position (upper left)  coordinates for the 4 character areas
CHAR1X := 1485
CHAR1Y := 755
CHAR2X := 1700
CHAR2Y := 755
CHAR3X := 1485
CHAR3Y := 925
CHAR4X := 1700
CHAR4Y := 925

;offsets to specific actions
LAttackX := 30
LAttackY := 100
RAttackX := 120
RAttackY := 100

Magic1X := 25
Magic1Y := 25
Magic2X := 70
Magic2Y := 25
Magic3X := 113
Magic3Y := 25
Magic4X := 25
Magic4Y := 70
Magic5X := 70
Magic5Y := 70
Magic6X := 113
Magic6Y := 70
Magic7X := 25
Magic7Y := 113
Magic8X := 70
Magic8Y := 113
Magic9X := 113
Magic9Y := 113
MagicAX := 160 ;abort
MagicAY := 20
MagicCX := 160 ;cast
MagicCY := 100

;offsets to screen items 
ChainX := 557
ChainY := 464
MidItemX := 967
MidItemY := 590
BrickX := 1187
BrickY := 301
BotItem1X := 785
BotItem1Y := 1052
BotItem2X := 955
BotItem1Y := 1052


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;; Hotkeys
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

#IfWinActive Legend of Grimrock
~z::Gosub, Char1LHand
~y::Gosub, Char1LHand
~u::Gosub, Char1RHand
~i::Gosub, Char2LHand
~o::Gosub, Char2RHand
~h::Gosub, Char3LHand
~j::Gosub, Char3RHand
~k::Gosub, Char4LHand
~l::Gosub, Char4RHand

~Left::Gosub, Char1LHand
~^Left::Gosub, Char1RHand
~+Left::Gosub, Char1Give
~Up::Gosub, Char2LHand
~^Up::Gosub, Char2RHand
~+Up::Gosub, Char2Give
~Down::Gosub, Char3LHand
~^Down::Gosub, Char3RHand
~+Down::Gosub, Char3Give
~Right::Gosub, Char4LHand
~^Right::Gosub, Char4RHand
~+Right::Gosub, Char4Give

~Numpad7::Gosub, TglMagic1
~Numpad8::Gosub, TglMagic2
~Numpad9::Gosub, TglMagic3
~Numpad4::Gosub, TglMagic4
~Numpad5::Gosub, TglMagic5
~Numpad6::Gosub, TglMagic6
~Numpad1::Gosub, TglMagic7
~Numpad2::Gosub, TglMagic8
~Numpad3::Gosub, TglMagic9

~!Numpad7::Gosub, MClick
~!Numpad8::Gosub, MUp
~!Numpad9::Gosub, MClickR
~!Numpad4::Gosub, MLeft
~!Numpad5::Gosub, MDown
~!Numpad6::Gosub, MRight

~!Numpad1::Gosub, TakeItemB1
~!Numpad2::Gosub, TakeItemB2
~!Numpad3::Gosub, PullChainL

~NumpadSub::Gosub, CancelMagic
~NumpadAdd::Gosub, CancelMagic
~NumpadEnter::Gosub, CastMagic
~Numpad0::Gosub, CastMagic

^!n::
IfWinExist Legend of Grimrock
{
	WinActivate
	Run Notepad
}
else
{
	MsgBox Grimrock not found
}
return

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;; Functions
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

MClick:
Click
return

MUp:
MPosY := MPosY - MStep
MouseMove, %MPosX%, %MPosY%, 0
return 

MLeft:
MPosX := MPosX - MStep
MouseMove, %MPosX%, %MPosY%, 0
return 

MDown:
MPosY := MPosY + MStep
MouseMove, %MPosX%, %MPosY%, 0
return 

MRight:
MPosX := MPosX + MStep
MouseMove, %MPosX%, %MPosY%, 0
return 


MClickR:
Click right
return

PullChainL:
Click %ChainX%, %ChainY%
return

TakeItemM:
Click %MidItemX%, %MidItemY%
return

PushBrick:
Click %BrickX%, %BrickY%
return 

TakeItemB1:
Click %BotItem1X%, %BotItem1Y%
return 

TakeItemB2:
Click %BotItem2X%, %BotItem2Y%
return 

UseLHand:
OffsetX := LastCharX + LAttackX
OffsetY := LastCharY + LAttackY
Click right %OffsetX%, %OffsetY%
return

UseRHand:
OffsetX := LastCharX + RAttackX
OffsetY := LastCharY + RAttackY
Click right %OffsetX%, %OffsetY%
return

TglMagic1:
OffsetX := LastCharX + Magic1X
OffsetY := LastCharY + Magic1Y
Click right %OffsetX%, %OffsetY%
return

TglMagic2:
OffsetX := LastCharX + Magic2X
OffsetY := LastCharY + Magic2Y
Click right %OffsetX%, %OffsetY%
return

TglMagic3:
OffsetX := LastCharX + Magic3X
OffsetY := LastCharY + Magic3Y
Click right %OffsetX%, %OffsetY%
return

TglMagic4:
OffsetX := LastCharX + Magic4X
OffsetY := LastCharY + Magic4Y
Click right %OffsetX%, %OffsetY%
return

TglMagic5:
OffsetX := LastCharX + Magic5X
OffsetY := LastCharY + Magic5Y
Click right %OffsetX%, %OffsetY%
return

TglMagic6:
OffsetX := LastCharX + Magic6X
OffsetY := LastCharY + Magic6Y
Click right %OffsetX%, %OffsetY%
return

TglMagic7:
OffsetX := LastCharX + Magic7X
OffsetY := LastCharY + Magic7Y
Click right %OffsetX%, %OffsetY%
return

TglMagic8:
OffsetX := LastCharX + Magic8X
OffsetY := LastCharY + Magic8Y
Click right %OffsetX%, %OffsetY%
return

TglMagic9:
OffsetX := LastCharX + Magic9X
OffsetY := LastCharY + Magic9Y
Click right %OffsetX%, %OffsetY%
return

CastMagic:
OffsetX := LastCharX + MagicCX
OffsetY := LastCharY + MagicCY
Click right %OffsetX%, %OffsetY%
return

CancelMagic:
OffsetX := LastCharX + MagicAX
OffsetY := LastCharY + MagicAY
Click right %OffsetX%, %OffsetY%
return


ResetMagic:
;If isCasting = true
;Gosub CancelMagic
return

GiveChar:
OffsetX := LastCharX + Magic1X
OffsetY := LastCharY + Magic1Y
Click %OffsetX%, %OffsetY%
return

Char1Give:
LastCharX := CHAR1X
LastCharY := CHAR1Y
Gosub GiveChar
return

Char2Give:
LastCharX := CHAR2X
LastCharY := CHAR2Y
Gosub GiveChar
return

Char3Give:
LastCharX := CHAR3X
LastCharY := CHAR3Y
Gosub GiveChar
return

Char4Give:
LastCharX := CHAR4X
LastCharY := CHAR4Y
Gosub GiveChar
return

Char1LHand:
;Gosub ResetMagic
LastCharX := CHAR1X
LastCharY := CHAR1Y
Gosub UseLHand
return

Char1RHand:
;Gosub ResetMagic
LastCharX := CHAR1X
LastCharY := CHAR1Y
Gosub UseRHand
return

Char2LHand:
;Gosub ResetMagic
LastCharX := CHAR2X
LastCharY := CHAR2Y
Gosub UseLHand
return

Char2RHand:
;Gosub ResetMagic
LastCharX := CHAR2X
LastCharY := CHAR2Y
Gosub UseRHand
return

Char3LHand:
;Gosub ResetMagic
LastCharX := CHAR3X
LastCharY := CHAR3Y
Gosub UseLHand
return

Char3RHand:
;Gosub ResetMagic
LastCharX := CHAR3X
LastCharY := CHAR3Y
Gosub UseRHand
return

Char4LHand:
;Gosub ResetMagic
LastCharX := CHAR4X
LastCharY := CHAR4Y
Gosub UseLHand
return

Char4RHand:
;Gosub ResetMagic
LastCharX := CHAR4X
LastCharY := CHAR4Y
Gosub UseRHand
return

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;; Mouse Click functions
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
ButtonRightClick:
GetKeyState, already_down_state, RButton
If already_down_state = D
    return
Button2 = NumPadDot
ButtonClick = Right
Goto ButtonClickStart

ButtonClickStart:
MouseClick, %ButtonClick%,,, 1, 0, D
SetTimer, ButtonClickEnd, 10
return

ButtonClickEnd:
GetKeyState, kclickstate, %Button2%, P
if kclickstate = D
    return

SetTimer, ButtonClickEnd, off
MouseClick, %ButtonClick%,,, 1, 0, U
return

Save this as an *.ahk file and download autohotkey then double click it

This will set the arrow keys to right clicking the Left hand, ctrl+Arrow keys to right clicking the Right hand, the numpad for spell-selection (enter to cast, + to cancel)

Hope this helps someone
User avatar
Komag
Posts: 3659
Joined: Sat Jul 28, 2012 4:55 pm
Location: Boston, USA

Re: Autohotkey keyboard script

Post by Komag »

I'm sure a few people could really make use of this. Maybe you could stick around and make a new version for Grimrock 2 when it comes out soon? :)
Finished Dungeons - complete mods to play
Bigpet
Posts: 2
Joined: Thu Aug 28, 2014 1:27 am

Re: Autohotkey keyboard script

Post by Bigpet »

Like, I said, this really isn't all that sophisticated and quite rudimentary (basically, barely useful, mostly for some combat, picking up items, swapping equip, etc. are so cumbersome you'd better do with the mouse).

Anyone with basic scripting experience could do this easily or modify it slightly for grimrock 2 which seems to be quite similar GUI wise.

I just put this online as a starting point for others, I don't think I'll be buying Grimrock 2 anytime soon, so you might want to ask someone who can actually test it to modify it.
Post Reply