Click here to Skip to main content
14,357,858 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hey,

Does anyone know how can I use the Keybd_event function:

Declare Function keybd_event Lib "user32" Alias "keybd_event" ( _
ByVal bVk As Byte, ByVal bScan As Byte, _
ByVal dwFlags As Long, ByVal dwExtraInfo As Long) As Long


When I use it I get the error:

A call to PInvoke function 'test!test.Form1::keybd_event' has unbalanced the stack. This is likely because the managed PInvoke signature does not match the unmanaged target signature. Check that the calling convention and parameters of the PInvoke signature match the target unmanaged signature.

Any Help?
Posted
Rate this:
Please Sign up or sign in to vote.

Solution 1

Here is a good example:

http://pinvoke.net/default.aspx/user32/keybd_event.html[^]

PInvoke.net[^] is a great resource when doing windows API calls.
   
Comments
Sergey Alexandrovich Kryukov 19-Oct-13 21:34pm
   
My 5, but this function has been superseded and its use is not recommended. I suggested appropriate alternative in my answer, please see.
—SA
Rate this:
Please Sign up or sign in to vote.

Solution 2

Using the function keybd_event is not recommended, as it has been superseded with SendInput. Please see:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms646304%28v=vs.85%29.aspx[^],
http://msdn.microsoft.com/en-us/library/windows/desktop/ms646310(v=vs.85).aspx[^].

This is the information of P/Invoke use of it: http://www.pinvoke.net/default.aspx/user32.sendinput[^].

—SA
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100