dgatsoulis
ele2png user
I am trying to implement keypress detection in lua.
I am creating a function in a dll with GetAsyncKeyState and I am accessing the function with package.loadlib.
keystate.dll
lua script:
whether the A key is pressed or not, the response I am getting is: "DLL loaded successfully A key is not pressed".
Can anyone tell me why this isn't working?
Any help is much appreciated.
I am creating a function in a dll with GetAsyncKeyState and I am accessing the function with package.loadlib.
keystate.dll
C++:
#include <Windows.h>
extern "C" __declspec(dllexport) bool IsKeyPressed(int virtualKeyCode)
{
return (GetAsyncKeyState(virtualKeyCode) & 0x8000) != 0;
}
Code:
func = package.loadlib("keystate.dll", "IsKeyPressed")
if func then
msg1 = ("DLL loaded successfully")
else
msg1 =("Error loading DLL")
end
goals = 0
while goals < 1 do
keyPressed = func(0x41) -- 0x41 is the virtual key code for the 'A' key
if keyPressed then
msg =("A key is pressed")
else
msg =("A key is not pressed")
end
note:set_text(msg1.." "..msg)
proc.skip()
if goals > 0 then end
end
whether the A key is pressed or not, the response I am getting is: "DLL loaded successfully A key is not pressed".
Can anyone tell me why this isn't working?
Any help is much appreciated.
Last edited: