AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Keybinding for Sacred the PC game

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
NHO3



Joined: 23 Jul 2004
Posts: 9

PostPosted: Fri Jul 23, 2004 4:04 am    Post subject: Keybinding for Sacred the PC game Reply with quote

Can somebody tell me how to make a script that will allow me to use the funtion keys to cast spells in this game. In the game you have to select a spell with the number keys (not numpad) and then right click the mouse. I want to just press F1 and it auto select the number 6 spell and cast it for me. I tried this but it didnt work.

#HotkeyInterval 1000 ;default 2000
#MaxHotkeysPerInterval 250 ;default 5
#MaxThreadsPerHotkey 3

run C:\games\sacred\sacred.exe

F1::Send, {"6" MouseClick, right}
F2::Send, {"7" Rbutton}
F3::Send, {8 RButton}
F4::Send, {9 RButton}
F5::Send, {0 RButton}

As you can see I tried two different methods for F1 and F2 cause I cant get it to work. It doesnt do anything when I am in the game.
Back to top
View user's profile Send private message
NHO3



Joined: 23 Jul 2004
Posts: 9

PostPosted: Fri Jul 23, 2004 4:23 am    Post subject: Sorry I double posted Reply with quote

Thanks to chris I got it to work. He suggested I use the following:

F1::
Send 6
MouseClick, right
return

It works great. Now I just need some way to change the spells that are in the 6-0 spots. That requires opening another menu in the game and clicking on another spell to place in the slots. I dont think its complicated but it will require knowing the coordinates of the mouse. I guess it could get a little complicated since different character classes have the spells in different locations on the screen.

If I can get this script to do everything all of us sacred gamers want then there will be hundreds if not more people wanting this program and this script. The fact that you cant change the key bindings in Sacred is the biggest drawback to the game. Most reviews list that as the number one thing that makes the game not perfect.
Back to top
View user's profile Send private message
NHO3



Joined: 23 Jul 2004
Posts: 9

PostPosted: Fri Jul 23, 2004 4:42 am    Post subject: mouse Reply with quote

Is the mouse coordinates the same no matter what the resolution is?

I am having trouble getting the script to exit after the game is closed. I added this to the end of my script but it didnt work.

IfWinNotExist, Sacred
{
ExitApp
}
else
return

I verified that Sacred is the correct title of the window using the AutoScript Writer (Recorder).
Back to top
View user's profile Send private message
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10463

PostPosted: Fri Jul 23, 2004 12:01 pm    Post subject: Reply with quote

Quote:
Is the mouse coordinates the same no matter what the resolution is?

The coordinates of objects on the screen will probably change when the resolution changes. It depends on how the game lays out objects.

Quote:
I am having trouble getting the script to exit after the game is closed.

The recommended way to do that is with SetTimer:
Code:
; At the top of the script:
...
SetTimer, WatchForClose, 1000
...
return
WatchForClose:
IfWinExist, Sacred  ; It would be less ambiguous to use ahk_class ExactClassName.
     return
; Otherwise:
ExitApp
Back to top
View user's profile Send private message Send e-mail
NHO3



Joined: 23 Jul 2004
Posts: 9

PostPosted: Fri Jul 23, 2004 7:53 pm    Post subject: Reply with quote

This is what I have and it doesnt close the script or app when the game exists.

#HotkeyInterval 1000 ;default 2000
#MaxHotkeysPerInterval 250 ;default 5
#MaxThreadsPerHotkey 3
run C:\games\sacred\sacred.exe


SetTimer, WatchForClose, 1000
return
WatchForClose:
IfWinExist, Sacred ; It would be less ambiguous to use ahk_class ExactClassName.
return
; Otherwise
ExitApp

F1::
Send 6
MouseClick, right
return

F2::
Send 7
MouseClick, right
return

F3::
Send 8
MouseClick, right
return

F4::
Send 9
MouseClick, right
return

F5::
Send 0
MouseClick, right
return

Edit:
Ok I changed from window title to ahk_class name and it works.
Back to top
View user's profile Send private message
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10463

PostPosted: Fri Jul 23, 2004 9:30 pm    Post subject: Reply with quote

Quote:
run C:\games\sacred\sacred.exe

You should probably do a WinWait for the game window to appear, otherwise the timer will cause the script to exit before the game even launches.

Quote:
it doesnt close the script or app when the game exists.

Double check the window's title. If it's a full screen game, you should be able to determine the title or class by using WinGetTitle/WinGetClass.
Back to top
View user's profile Send private message Send e-mail
NHO3



Joined: 23 Jul 2004
Posts: 9

PostPosted: Fri Jul 23, 2004 9:47 pm    Post subject: Reply with quote

Like this?

#HotkeyInterval 1000 ;default 2000
#MaxHotkeysPerInterval 250 ;default 5
#MaxThreadsPerHotkey 3

run C:\games\sacred\sacred.exe
WinWait, ahk_class Sacred, , 10
if ErrorLevel = 0
{
SetTimer, WatchForClose, 1000
return
}
else
return

;Check if Sacred is running and when it is closed exit this application.

WatchForClose:
IfWinExist, ahk_class Sacred
return
; If Sacred not running then exit application
ExitApp

F1::
Send 6
MouseClick, right
return

F2::
Send 7
MouseClick, right
return

F3::
Send 8
MouseClick, right
return

F4::
Send 9
MouseClick, right
return

F5::
Send 0
MouseClick, right
return

Without the Winwait it still works on my computer. When the timer is set does it check for the window right away or wait the 1000ms to exitapp? If so then I think the 10s is plenty time for the window to be created.
Back to top
View user's profile Send private message
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10463

PostPosted: Fri Jul 23, 2004 11:14 pm    Post subject: Reply with quote

Quote:
WinWait, ahk_class Sacred, , 10

That's correct as long as the class really is Sacred (presumably you verified that).

Quote:
Without the Winwait it still works on my computer. When the timer is set does it check for the window right away or wait the 1000ms to exitapp? If so then I think the 10s is plenty time for the window to be created.

Timers do not run immediately. The interval must expire before the first run occurs.

If the script still has problems, you could try opening the main from the tray icon. It will show you what the script is doing, and is thus helpful for debugging.
Back to top
View user's profile Send private message Send e-mail
NHO3



Joined: 23 Jul 2004
Posts: 9

PostPosted: Sat Jul 24, 2004 12:14 am    Post subject: Reply with quote

I used the window spy tool to verify the class name and it is Sacred. The script runs fine without the winwait funtion. Since it is waiting 1000ms before it checks if the window has closed windows has plenty of time to create the window. From what I have seen window spy shows the class name for sacred has soon as i execute sacred.exe before i even see the game come up.

How can I make the script run faster? Sometimes in the game when I press F1 or which ever key it doesnt do it. I think I need the script to run faster.
Back to top
View user's profile Send private message
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10463

PostPosted: Sat Jul 24, 2004 12:55 am    Post subject: Reply with quote

It is possible that the game needs more time between the keystroke and the mouse click. If you suspect that is the case, try this:

F1::
Send 6
Sleep 50 ; Increase this value if you think the game needs more time.
MouseClick right
return

To make the script run at its maximum speed, add the following line to the top:
SetBatchLines -1

If it's still a problem, you could also try raising the script's process priority by using a command line utility (or the task manager). There are other topics on the forum that contain info about this.
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group