Basically I’ve been writing a system for macros where someone types in the keys they want in a specific window and the application relays the keys after recording them, essentially a bot to do different little tasks and allow them to save those tasks into a script file so they can re-run them at any time they want almost like a simplistic programming language of sorts via recording what a user enters, clicks on, mouse movements, and pixel color detection at some points as well.
The problem I’m encountering currently though is while using the GetKeyboardState API in order to determine the states of all the keys and passing that into ToAscii it seems to be lagging or delayed.
For example if I hold shift and press A immediately after holding shift down it will report “a” instead of A(which is what is really being entered), if I were to press 1 immediately after holding shift it would report 1 instead of “!” which is what is really being typed.
Like wise the key up event is also delayed/lagged when I let go of shift and I press “1” it reports “!” instead of 1 which is what’s really being entered, and likewise with “a” it reports “A” when it should report “a” as shift has been lifted.
With the above being said I thank anyone in advance who can help me out with this here’s the code, hopefully someone here knows if I’m doing something wrong or what could possibly be causing this issue.
It’s actually a very bad/program destroying issue as when recording and playing back it doesn’t work as the end user intended,
it’ll start pressing the wrong keys.
For instance I was making it play a game like a pre-programmed bot and it would press the wrong keys every once in awhile due to this issue.
I’d run using shift then try to use the action bound to 1 and it would type ! instead of 1 and fail to perform the action.
Function ToAscii(uVirtKey as UInt32,uScanCode as UInt32, uFlags as UInt32) As string
Declare Function GetKeyboardState Lib "User32" ( lpKeyState as Ptr ) as Integer
Declare Function ToAscii Lib "User32" ( uVirtKey as uint32, uScanCode as uint32, lpKeyState as Ptr, lpChar as Ptr, uFlags as Uint32) as Integer
dim mb as new MemoryBlock( 256 )
dim char as New MemoryBlock(2)
Dim RetString As String
if GetKeyBoardState( mb ) <> 0 Then // Non-Zero is success
if ToAscii(uVirtKey,uScanCode,mb,char,uFlags) > 0 Then // 0 is invalid ASCII character, from what I read.
return char.CString(0)
end
else
MsgBox "Issue getting keyboardstate" // I never actually got this so I know it's not returning zero
end
End Function