NathanAldenSr
Greenhorn
I discovered today that animation canceling is a thing in Stardew Valley. I found the AutoHotKey script that I'm sure everyone's seen before:
www.reddit.com
However, being a fan of game engine design (I'm writing my own game engine), I realized the sleep values could likely be tweaked a bit. Here is the resulting script:
As you can see, I extracted a function called SleepForFrames to make it more obvious what is going on. I was able to reduce the delay by approximately three frames compared to the script from Reddit.
Games have what is known as a "game loop." Traditionally, the loop will run once every 1/60 of a second, or approximately 16.6 (repeating) milliseconds. Many games will process input on every frame, and it appears (although I have not verified this by looking at the code) that Stardew is no exception. Using this knowledge, we can tweak the number of frames to delay by accordingly.
I should note that low-delay timers are notoriously unpredictable on Windows. I've run into these issues myself in my own game engine. Delays less than Windows 10's high-resolution timer frequency are not guaranteed and are often longer in execution. Still, the above script worked fine on my system and it's easier for most folks to modify without needing to know how to calculate FPS.
Reddit - Dive into anything

However, being a fan of game engine design (I'm writing my own game engine), I realized the sleep values could likely be tweaked a bit. Here is the resulting script:
Code:
#SingleInstance, Force
#IfWinActive, Stardew Valley
SleepForFrames(x)
{
Sleep, x * 16.666
}
Space::
While GetKeyState("Space", "P")
{
SendEvent, {LButton Down}
SleepForFrames(1)
SendEvent, {LButton Up}
SleepForFrames(5) ; This value depends heavily on the actual FPS you're getting
SendEvent, {r Down}{Delete Down}{RShift Down}
SleepForFrames(1)
SendEvent, {r Up}{Delete Up}{RShift Up}
}
SleepForFrames(1)
return
Games have what is known as a "game loop." Traditionally, the loop will run once every 1/60 of a second, or approximately 16.6 (repeating) milliseconds. Many games will process input on every frame, and it appears (although I have not verified this by looking at the code) that Stardew is no exception. Using this knowledge, we can tweak the number of frames to delay by accordingly.
I should note that low-delay timers are notoriously unpredictable on Windows. I've run into these issues myself in my own game engine. Delays less than Windows 10's high-resolution timer frequency are not guaranteed and are often longer in execution. Still, the above script worked fine on my system and it's easier for most folks to modify without needing to know how to calculate FPS.