Jump to content

AutoHotKey script to automate a key press


merlinsons

Recommended Posts

Hi all,

I posted this in the smartcast thread but then thought that this automatic key presser might be useful for other purposes as well. It doesn't need smartcast to work. I have been using balanced magic and smartcast, both old (abandoned?) mods that are still great. I really like smartcast but I have also been having a problem with the spell recast delay. Currently it is recasting stoneskin when more than 2/3 remains on the spell duration time. On the other hand, my alteration skill is far above my other skills, lol. I searched for an alternative solution but haven't found something that worked for me. I tried a few other mods that say that they autocast spells, but they seemed way too big for my needs. So, for lack of something better, I made a little bandaid autohotkey (https://autohotkey.com/) script to automatically push a skyrim hotkey (the 8 key in my case) repeatedly with a fixed wait time (150 seconds) which has to be toggled on and off manually (with the 9 key) since it doesn't have any of the conditional logic settings of smartcast. I use it to automatically re-equip a smartcast ring of stoneskin in hotkey slot 8. Any of those values/item can be changed, of course. Here is the script:


EDIT: here is a link to the script with the original formatting:
http://www.mediafire.com/download/b13qd33x4h9b54a/recast01.ahk


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

; use the 9 key to toggle automatic recasting on hotkey 8
; automatically presses the 8 key every recast_wait seconds
; I use it to re-equip the smartcast ring for stoneskin in hotkey slot 8 every 150 seconds

recast_wait := 150 ; seconds to wait between casts
isRecasting := 0 ; toggle flag whether the spell is being recast
count := 0

Recast: ; the timer calls this every 5 seconds
count += 1
if(isRecasting)
{
if(count*5 > recast_wait)
{
IfWinNotExist, Skyrim ; exit autohotkey if skyrim is not running
{
ExitApp
}
Send 8 ; press the 8 hotkey
count := 0
}
}
else ; recasting is toggled off
{
SetTimer, Recast, Off ; turn off the timer
}
return

#IfWinActive ahk_class Skyrim ; do the following if skyrim is the top window

9:: ; the toggle key
isRecasting := !isRecasting
if(isRecasting)
{
Send 8 ; press the 8 hotkey
count := 0
SetTimer, Recast, 5000 ; set the timer to call Recast every 5000 milliseconds
}
return

Link to comment
Share on other sites

  • 4 years later...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...