Sign in to follow this  
Followers 0
greenmachine

Checking entire keyboard state via DllCall

8 posts in this topic

I was reading through some scripts on here, and there's dealing with hotkeys that got my attention. Someone asked whether you could make a function to get key presses and make a hotkey out of that. I looked up some DllCall stuff, and found GetKeyboardState. I want to try this function to see if it does anything I want it to, but I can't figure out how to use the DllCall.

The GetKeyboardState function copies the status of the 256 virtual keys to the specified buffer.

Syntax

BOOL GetKeyboardState(

PBYTE lpKeyState

);

Parameters

lpKeyState [in] Pointer to the 256-byte array that receives the status data for each virtual key.

I get this far:

Global $KeyboardState[257] ; one extra just in case

$returnvalue = DllCall ("user32.dll", "int", "GetKeyboardState", "_____", $KeyboardState)

MsgBox (0, "return", $returnvalue & @CRLF & @error)

No matter what it put in the ___ part (where it should be pbyte according to MSDN), I get a return value of 0 and @error is 2. So... anyone know what the equivalent of Pbyte is in AutoIt? Or, another function that I could use instead of this?

Share this post


Link to post
Share on other sites



Good idea. Now to learn how to do that.

Share this post


Link to post
Share on other sites

I don't think I'm getting it. I made a struct:

$struct = DllStructCreate ("byte[257]")

Then do I call it like this?

$returnvalue = DllCall ("user32.dll", "int", "GetKeyboardState", "ptr", DllStructGetPtr ($struct))

I need help on the call part.. what should I use instead of ptr (since it doesn't seem to work), or am I doing something else wrong?

Share this post


Link to post
Share on other sites

not sure if all the numbers are perfect but it definately works

$struct = DllStructCreate ("byte[256]")
$returnvalue = DllCall ("user32.dll", "int", "GetKeyboardState", "ptr", DllStructGetPtr ($struct))
$temp = DLLStructGetData($struct,1,1)
$message = DLLStructGetData($struct,1,1)
For $i = 2 to 256
message = $message & @CRLF & DLLStructGetData($struct,1,$i)
Next
Msgbox(0,"Keys",$message)

sorry it doesn't look any prettier.... lol :lmao:

Share this post


Link to post
Share on other sites

Eh, I was almost getting there. Thanks for the help.

Share this post


Link to post
Share on other sites

VB isn't being nice to me. I evidently don't have the right tools to work with normal VB programs, so the Winsock script I downloaded can't be edited and re-run.. because I don't have a compiler.... Something like that. I don't even know. I just haven't had any luck with file transfer with tcp.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0