Click here to Skip to main content
15,886,780 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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

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.
 
Share this answer
 
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
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
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900