 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
CraSH23000
Joined: 22 Jun 2007 Posts: 38
|
Posted: Mon Apr 21, 2008 5:51 pm Post subject: Diablo 2 Movement with WASD instead of mouse |
|
|
I was playing the ancient game Diablo again for kicks and was slightly irritated by the fact I could not use WASD like most games now a days. I took a shot at making the WASD keys work.
I got the keys to work individually with this code:
| Code: |
ScreenWidth := 795
ScreenHeight := 595
halfWidth := ScreenWidth/2
halfHeight := ScreenHeight/2
w::
MouseGetPos, saveXpos, saveYpos
MouseClick, left, %halfwidth%, 5, 1, 0, D
MouseGetPos, new_saveXpos, new_saveYpos
;msgbox, orig: %saveXpos%, %saveYpos% new: %new_saveXpos%, %new_saveYpos%
KeyWait w
;msgbox, w was released
MouseClick, left,,, 1, 0, U
MouseMove, %saveXpos%, %saveYpos%
return
a::
MouseGetPos, saveXpos, saveYpos
MouseClick, left, 5, %halfHeight%, 1, 0, D
MouseGetPos, new_saveXpos, new_saveYpos
KeyWait a
MouseClick, left,,, 1, 0, U
MouseMove, %saveXpos%, %saveYpos%
return
s::
MouseGetPos, saveXpos, saveYpos
MouseClick, left, %halfWidth%, %ScreenHeight%, 1, 0, D
MouseGetPos, new_saveXpos, new_saveYpos
KeyWait s
MouseClick, left,,, 1, 0, U
MouseMove, %saveXpos%, %saveYpos%
return
d::
MouseGetPos, saveXpos, saveYpos
MouseClick, left, %ScreenWidth%, %halfHeight%, 1, 0, D
MouseGetPos, new_saveXpos, new_saveYpos
KeyWait d
MouseClick, left,,, 1, 0, U
MouseMove, %saveXpos%, %saveYpos%
return
|
But I do not know how I would make it work to allow you to go diagonal.
I was think of doing something like:
| Code: |
w & d::
MouseGetPos, saveXpos, saveYpos
MouseClick, left, %ScreenWidth%, 5, 1, 0, D
MouseGetPos, new_saveXpos, new_saveYpos
KeyWait d ;THIS IS THE PROBLEM
MouseClick, left,,, 1, 0, U
MouseMove, %saveXpos%, %saveYpos%
return
|
the problem is if w is released then it keeps going north west because I dont know how to check if both keys are up.
EDIT: Thanks to VxE, I've got a good script that I will probably add more to. Heres my final version so far:
| Code: |
ScreenWidth := 800
ScreenHeight := 585
halfWidth := ScreenWidth/2
halfHeight := ScreenHeight/2
keys = wasd ; ULDR
SetDefaultMouseSpeed, 0
StringSplit, key, keys
Loop, Parse, Keys
Hotkey, *$%A_LoopField%, TheTimer, on
Pause::Suspend
TheTimer:
SetTimer, TheMover, 5 ; this number is the speed adjustment, higher = slower
return
TheMover:
dx := GetKeyState( key4, "P" ) - GetKeyState( key2, "P" ) ;Right - Left
dy := GetKeyState( key3, "P" ) - GetKeyState( key1, "P" ) ;Down - Up
If !TheFlag
MouseGetPos, memx, memy
If ( dx + dy*2 )
{
TheSpam = Left Down
;////////////////////////// Uncomment the next line to stop the rapid-click
; IfEqual, TheFlag, 1, StringReplace, TheSpam, TheSpam, Down, 0
Click, % (halfwidth + 50 * dx) " "
. (halfheight + 50 * dy) " " TheSpam
TheFlag = 1
}
else
{
Click, Left Up
Click, %memx% %memy% Left 0
TheFlag = 0
SetTimer, TheMover, off
}
return
|
I changed it so that it does not click to the edge of the screen because it was not ideal that if you just tapped "w, a, s or d" it would go all the way to the edge of the screen, when you may have wanted to only take a few steps.
NOTE:Ran into a problem with finding the center because it was not (400,300) like you would think, because the character is higher than the center.
EDIT: (4/22/08) Well, I liked the sound of ControlClick, because its nice to move the mouse while walking around with wasd, so heres the new script, complete with a hotkey (hold down alt+e) that picks up special items (browns, greens, yellows and blues) and some scripts I use to use skills:
| Code: |
SendMode Play
ScreenWidth := 800
ScreenHeight := 585
halfWidth := ScreenWidth/2
halfHeight := ScreenHeight/2
Skill := 0
xTL := 0
yTL := 0
xBR := 800
yBR := 553
Best1st := 1
keys = wasd ; ULDR
SetDefaultMouseSpeed, 0
StringSplit, key, keys
Loop, Parse, Keys
Hotkey, $%A_LoopField%, TheTimer, on
Pause::Suspend
TheTimer:
SetTimer, TheMover, 5 ; change speed, higher = slower
return
TheMover:
dx := GetKeyState( key4, "P" ) - GetKeyState( key2, "P" ) ;Right - Left
dy := GetKeyState( key3, "P" ) - GetKeyState( key1, "P" ) ;Down - Up
If !TheFlag
MouseGetPos, memx, memy
If (dx | dy)
{
TheSpam = Left Down
;////////////////////////// Uncomment the next line to stop the rapid-click
; IfEqual, TheFlag, 1, StringReplace, TheSpam, TheSpam, Down, 0
; Click, % (halfwidth + 50 * dx) " "
; . (halfheight + 50 * dy) " " TheSpam
xval := halfwidth + 50 * dx
yval := halfheight + 50 * dy
ControlClick, x%xval% y%yval%, Diablo,,,, D
TheFlag = 1
}
else
{
MouseGetPos, memx, memy
;ControlClick, x%xval% y%yval%, Diablo
Click, %xval% %yval% Left 1
Click, %memx% %memy% Left 0
TheFlag = 0
SetTimer, TheMover, off
}
return
q::
tmp_Skill := Skill
Send, {f1}
Loop
{
if not GetKeyState("q", "P" )
break
Sleep 250
Click Right
}
Skill := tmp_Skill
Send {f%Skill%}
return
f::
tmp_Skill := Skill
Send, {f6}
Loop
{
if not GetKeyState("f", "P" )
break
Sleep 250
Click Right
}
Skill := tmp_Skill
Send {f%Skill%}
return
r::
tmp_Skill := Skill
Send, {f2}
Click Right
Sleep 450
Send, {f5}
Click Right
Skill := tmp_Skill
Send {f%Skill%}
return
e::
tmp_Skill := Skill
Send, {f4}
Click Right
Skill := tmp_Skill
Send {f%Skill%}
return
!e::
FileAppend, %Best1st%`n , C:\best1st.txt
if (Best1st < 3)
{
xTL := 63
yTL := 72
Color := "0x588898" ;Gold Items
Gosub, SearchnClick ;Pickup Golds
xTL := 0
yTL := 0
}
else if (Best1st > 2 and Best1st < 5)
{
Color := "0x00C800" ;Green Items
Gosub, SearchnClick ;Pickup Greens
}
else if (Best1st > 4 and Best1st < 7)
{
Color := "0x205858" ;Yellow Items
Gosub, SearchnClick ;Pickup Yellows
}
else if (Best1st > 6 and Best1st < 9)
{
Color := "0xC85058" ;Blue Items
Gosub, SearchnClick ;Pickup Blues
}
else
{
Best1st := 0
}
return
SearchnClick:
Send {Alt Down}
PixelSearch, Px, Py, %xTL%, %yTL%, %xBR%, %yBR%, %Color%, 1, Fast
if ErrorLevel
{
Best1st := Best1st + 1
}
else
{
Px := Px+2
Py := Py+5
Click, %Px% %Py% Left 1
}
return
!x::
Send {esc}{up}{enter}
return
~f1::
Skill := 1
return
~f2::
Skill := 2
return
~f3::
Skill := 3
return
~f4::
Skill := 4
return
~f5::
Skill := 5
return
~f6::
Skill := 6
return
~f7::
Skill := 7
return
~f8::
Skill := 8
return
~f9::
Skill := 9
return
~f10::
Skill := 10
return
~f11::
Skill := 11
return
~f12::
Skill := 12
return
LWin::
send {Alt}
return
|
_________________ What is real in our infinitely alternating perception of reality?
Last edited by CraSH23000 on Wed Apr 23, 2008 4:45 am; edited 2 times in total |
|
| Back to top |
|
 |
Deller
Joined: 21 Nov 2007 Posts: 178 Location: 0x01101110
|
Posted: Mon Apr 21, 2008 7:30 pm Post subject: Re: Diablo 2 Movement with WASD instead of mouse |
|
|
| CraSH23000 wrote: | | the problem is if w is released then it keeps going north west because I dont know how to check if both keys are up. |
To check that use GetKeyState in the help file.
Last edited by Deller on Tue Apr 22, 2008 4:53 am; edited 1 time in total |
|
| Back to top |
|
 |
CraSH23000
Joined: 22 Jun 2007 Posts: 38
|
Posted: Mon Apr 21, 2008 11:26 pm Post subject: |
|
|
Yeah, I was thinking of using GetKeyState(), wasnt that familiar with it, but I think I get it now.
| Code: |
ScreenWidth := 795
ScreenHeight := 595
halfWidth := 400
halfHeight := 300
^+z::
loop
{
wIsD := GetKeyState("w")
aIsD := GetKeyState("a")
sIsD := GetKeyState("s")
dIsD := GetKeyState("d")
;MouseGetPos, saveXpos, saveYpos
if (wIsD=1 and aIsD=0 and sIsD=0 and dIsD=0)
{;W is Down
MouseClick, left, %halfwidth%, 5, 1, 0, D
}
else if (wIsD=0 and aIsD=1 and sIsD=0 and dIsD=0)
{;A is Down
MouseClick, left, 5, %halfHeight%, 1, 0, D
}
else if (wIsD=0 and aIsD=0 and sIsD=1 and dIsD=0)
{;S is Down
MouseClick, left, %halfWidth%, %ScreenHeight%, 1, 0, D
}
else if (wIsD=0 and aIsD=0 and sIsD=0 and dIsD=1)
{;D is Down
MouseClick, left, %ScreenWidth%, %halfHeight%, 1, 0, D
}
else if (wIsD=1 and aIsD=1 and sIsD=0 and dIsD=0)
{;W & A are Down
MouseClick, left, 5, 5, 1, 0, D
}
else if (wIsD=1 and aIsD=0 and sIsD=0 and dIsD=1)
{;W & D are Downs
MouseClick, left, %ScreenWidth%, 5, 1, 0, D
}
else if (wIsD=0 and aIsD=1 and sIsD=1 and dIsD=0)
{;S & A are Down
MouseClick, left, 5, %ScreenHeight%, 1, 0, D
}
else if (wIsD=0 and aIsD=0 and sIsD=1 and dIsD=1)
{;S & D are Down
MouseClick, left, %ScreenWidth%, %ScreenHeight%, 1, 0, D
}
else
{
MouseClick, left,,, 1, 0, U
}
}
;MouseMove, %saveXpos%, %saveYpos%
return
|
There is a problem though, after I use it, I cant drag anything.  _________________ What is real in our infinitely alternating perception of reality? |
|
| Back to top |
|
 |
orbik
Joined: 09 Apr 2008 Posts: 25 Location: Espoo, Finland
|
Posted: Tue Apr 22, 2008 12:43 am Post subject: |
|
|
Ouch, is that an infinite loop i see there? How about using something like this instead:
| Code: |
SendMode, Input
ScreenWidth := 795
ScreenHeight := 595
halfWidth := 400
halfHeight := 300
clickX := halfWidth
clickY := halfHeight
wasdMoveActive := 0
w::
clickY := 5
Gosub, wasd_click
return
s::
clickY := %ScreenHeight%
Gosub, wasd_click
return
a::
clickX := 5
Gosub, wasd_click
return
d::
clickX := %ScreenWidth%
Gosub, wasd_click
return
w up::
if (clickY < halfHeight)
clickY := halfHeight
Gosub, wasd_click
return
s up::
if (clickY > halfHeight)
clickY := halfHeight
Gosub, wasd_click
return
a up::
if (clickX < halfWidth)
clickX := halfWidth
Gosub, wasd_click
return
d up::
if (clickX < halfWidth)
clickX := halfWidth
Gosub, wasd_click
return
wasd_click:
if (clickX != halfWidth || clickY != halfHeight)
{
Click down %clickX% %clickY%
if (!wasdMoveActive)
{
wasdMoveActive := 1
MouseGetPos, mouseOldX, mouseOldY
}
}
else
{
Click up
if (wasdMoveActive)
{
wasdMoveActive := 0
MouseMove, mouseOldX, mouseOldY
}
}
return
|
That aside, couldn't you move with the arrow keys in Diablo? If so, just remap them to wasd.
EDIT: Added MouseGetPos and MouseMove |
|
| Back to top |
|
 |
[VxE]
Joined: 07 Oct 2006 Posts: 943
|
Posted: Tue Apr 22, 2008 1:11 am Post subject: |
|
|
This should allow 8-direction movement (and can spam click optionally)
| Code: | ScreenWidth := 795
ScreenHeight := 595
halfWidth := ScreenWidth/2
halfHeight := ScreenHeight/2
keys = wasd ; ULDR
SetDefaultMouseSpeed, 0
StringSplit, key, keys
Loop, Parse, Keys
Hotkey, *$%A_LoopField%, TheTimer, on
Pause::Suspend
TheTimer:
SetTimer, TheMover, 5 ; this number is the speed adjustment, higher = slower
return
TheMover:
dx := GetKeyState( key4, "P" ) - GetKeyState( key2, "P" )
dy := GetKeyState( key3, "P" ) - GetKeyState( key1, "P" )
If !TheFlag
MouseGetPos, memx, memy
If ( dx + dy*2 )
{
TheSpam = Left Down
;////////////////////////// Uncomment the next line to stop the rapid-click
; IfEqual, TheFlag, 1, StringReplace, TheSpam, TheSpam, Down, 0
Click, % (halfwidth + Floor( halfwidth * 0.97 ) * dx) " "
. (halfheight + Floor( halfheight * 0.97 ) * dy) " " TheSpam
TheFlag = 1
}
else
{
Click, Left Up
Click, %memx% %memy% Left 0
TheFlag = 0
SetTimer, TheMover, off
}
return |
_________________ My Home Thread
More Common Answers: 1. It's in the FAQ 2. Ternary ( ? : ) guide 3. Post code with [code][/code] tags |
|
| Back to top |
|
 |
CraSH23000
Joined: 22 Jun 2007 Posts: 38
|
Posted: Tue Apr 22, 2008 1:59 am Post subject: |
|
|
| orbik wrote: | | Ouch, is that an infinite loop i see there? |
I thought that would not be the best thing, then again its the only way I could figure out how to do diagonal combinations like:
"w & a" at the same to go north west
"w & d" at the same to go north east
"s & a" at the same to go south west
"s & d" at the same to go south east
| orbik wrote: | | That aside, couldn't you move with the arrow keys in Diablo? If so, just remap them to wasd. |
The reason I'm making this script is because the game does not support moving with keyboard.
| [VxE] wrote: | | This should allow 8-direction movement (and can spam click optionally) |
Thanks alot VxE works great, your script fixes issue I had with not being able to drag things.
EDIT: Sweet, I took your code and have my final version for this aspect of the program
| Code: |
ScreenWidth := 800
ScreenHeight := 585
halfWidth := ScreenWidth/2
halfHeight := ScreenHeight/2
keys = wasd ; ULDR
SetDefaultMouseSpeed, 0
StringSplit, key, keys
Loop, Parse, Keys
Hotkey, *$%A_LoopField%, TheTimer, on
Pause::Suspend
TheTimer:
SetTimer, TheMover, 5 ; this number is the speed adjustment, higher = slower
return
TheMover:
dx := GetKeyState( key4, "P" ) - GetKeyState( key2, "P" ) ;Right - Left
dy := GetKeyState( key3, "P" ) - GetKeyState( key1, "P" ) ;Down - Up
If !TheFlag
MouseGetPos, memx, memy
If ( dx + dy*2 )
{
TheSpam = Left Down
;////////////////////////// Uncomment the next line to stop the rapid-click
; IfEqual, TheFlag, 1, StringReplace, TheSpam, TheSpam, Down, 0
Click, % (halfwidth + 50 * dx) " "
. (halfheight + 50 * dy) " " TheSpam
TheFlag = 1
}
else
{
Click, Left Up
Click, %memx% %memy% Left 0
TheFlag = 0
SetTimer, TheMover, off
}
return
|
I changed it so that it does not click to the edge of the screen because it was not ideal that if you just tapped "w, a, s or d" it would go all the way to the edge of the screen, when you may have wanted to only take a few steps.
NOTE:Ran into a problem with finding the center because it was not (400,300) like you would think, because the character is higher than the center. _________________ What is real in our infinitely alternating perception of reality? |
|
| Back to top |
|
 |
orbik
Joined: 09 Apr 2008 Posts: 25 Location: Espoo, Finland
|
Posted: Tue Apr 22, 2008 3:46 am Post subject: |
|
|
@VxE
While your code works, it's terribly inefficient by being based on a loop running at short intervals, and by repeating redundant arithmetic operations. The only advantage to my version is maintainability, by allowing easy redefinition of the movement keys. This should be addressed by using a better language (that supports higher level abstraction) instead of compromising performance. You also managed to make one part both hard to read and slow. Change If ( dx + dy*2 ) to If (dx | dy)
</rant> |
|
| Back to top |
|
 |
[VxE]
Joined: 07 Oct 2006 Posts: 943
|
Posted: Tue Apr 22, 2008 6:27 am Post subject: |
|
|
| orbik wrote: | @VxE
While your code works, it's terribly inefficient by being based on a loop running at short intervals, and by repeating redundant arithmetic operations. The only advantage to my version is maintainability, by allowing easy redefinition of the movement keys. This should be addressed by using a better language (that supports higher level abstraction) instead of compromising performance. You also managed to make one part both hard to read and slow. Change If ( dx + dy*2 ) to If (dx | dy)
</rant> |
So sue me...
Really, what's your point? Are you disappointed to see code that hasn't been in development for at least 3 months? Or is it that you prefer your own spaghetti-code style to my semi-arcane style?
As for efficiency.... whoop-de-doo.... who's gonna notice?
And about easy redefinition of the keys, I think I've got you beat in that department since | I wrote: | | keys = wasd ; ULDR | is unquestionably easier to deal with than 8 separate hotkeys.
Meh, anyone who's interested will just use whatever code they like better anyways. I suppose, If I really wanted to rewrite this code for myself, I'd use ControlClick instead of hijacking the mouse. _________________ My Home Thread
More Common Answers: 1. It's in the FAQ 2. Ternary ( ? : ) guide 3. Post code with [code][/code] tags |
|
| Back to top |
|
 |
aobrien
Joined: 14 Feb 2008 Posts: 30
|
Posted: Tue Apr 29, 2008 5:19 pm Post subject: |
|
|
Hi CraSH,
I actually wrote a DiabloII leveling script not too long ago. It is pretty slick if I do say so myself. It will play endlessly, if you die it will recognize that fact and reload the last saved game.
I've been toying with the idea of posting it to the forum. I'll speed up my timeline if you are interested.
aobrien |
|
| Back to top |
|
 |
CraSH23000
Joined: 22 Jun 2007 Posts: 38
|
Posted: Sat May 03, 2008 7:25 am Post subject: |
|
|
Yes, I am very interested. I am curious how you are targeting enemies, and if your script works for multiple abilities and classes. _________________ What is real in our infinitely alternating perception of reality? |
|
| Back to top |
|
 |
aobrien
Joined: 14 Feb 2008 Posts: 30
|
Posted: Tue May 13, 2008 8:15 am Post subject: |
|
|
Hi Crash,
Sorry it took so long to reply... I don't check my personal email as much as I should.
I tried several different methods of targeting enemies, but came to the conclusion that it was just better to flail around and let them come to me (Use the shift key while clicking left-mouse), it is actually pretty effective.
I have used the script to level my Druid (Dimensional Blade - undestructible - kind of important) and Amazon archer.
I posted the script here:
Diablo 2 Expansion Auto-Leveling Script
aobrien |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|