I think the intention is good, but it actually works out not to be great in practice.
I alt + tab between code and amibroker so if I put the mouse in the amibroker window, it will trigger keyboard events regardless of which window is active.
If I have the mouse outside of amibroker, it won't activate.
Without the mouse cursor check, it only intermittently picks up typing outside of amibroker. Amibroker doens't seem to pick up fast typing all the time... I'm now thinking of having a keyboard toggle to listen to keypress.
GetAsyncKeyState does NOT trigger anything. It your formula refreshing normally (because of real-time data arriving and/or RequestTimedRefresh calls).
Again: GetAsyncKeyState does NOT trigger execution of your formula.
All what GetAsyncKeyState does is to retrieve current keyboard state, REGARDLESS of what window is in focus. This function is transparent call to Windows API and it's function documented in Windows API docs
If you want to respond to key presses when given window has a focus and have your formula executed when user presses key INSIDE your window, you have to use Gui functions, namely GuiSendKeyEvents(), for example code see (as always) the great manual that covers everything you need to know about AmiBroker: