donniedarko801
asked on
keybd_event & SendInput. Simulating Scroll-Lock Press and Release?
Hello Experts,
I'm trying to optimize some VB6 code to .NET and was wondering if you could present any code samples in VB .NET/2005 on how to simulate Scroll-Lock Key press & release using SENDINPUT. Something that would replace the use of keybd_event I think...
I'm trying to optimize some VB6 code to .NET and was wondering if you could present any code samples in VB .NET/2005 on how to simulate Scroll-Lock Key press & release using SENDINPUT. Something that would replace the use of keybd_event I think...
SendKeys.Send("{SCROLLLOCK }")
ASKER
I know the difference between SendKeys and SendInput, but why do you need API if there is the managed class with exactly the same functionality?
This is information about SendInput API, if you have reasons to use it:
http://www.pinvoke.net/default.aspx/user32/SendInput.html
This is information about SendInput API, if you have reasons to use it:
http://www.pinvoke.net/default.aspx/user32/SendInput.html
ASKER
I'm behind a firewall, can you please post the code?
ASKER
SendKeys is bad programing... I need reliable stuff...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks Alex!
ASKER
That works well, but how would you string a keypress and an release into 1 array of structs to be sent all at the same time? And why do lowercase characters not print if you change the string?
ex. message = "HELLO WORLD"
outputs "hello world."
ex. message = "HELLO World"
outputs "hello w/4."
ex. message = "hello world"
outputs "85/ /4."
UINT SendInput( UINT nInputs, LPINPUT pInputs, int cbSize);
Parameters
nInputs
******[in] Specifies the number of structures in the pInputs array. ***** <---use this to send the down and up together
pInputs
[in] Pointer to an array of INPUT structures. Each structure represents an event to be inserted into the keyboard or mouse input stream.
cbSize
[in] Specifies the size, in bytes, of an INPUT structure. If cbSize is not the size of an INPUT structure, the function will fail.
ex. message = "HELLO WORLD"
outputs "hello world."
ex. message = "HELLO World"
outputs "hello w/4."
ex. message = "hello world"
outputs "85/ /4."
UINT SendInput( UINT nInputs, LPINPUT pInputs, int cbSize);
Parameters
nInputs
******[in] Specifies the number of structures in the pInputs array. ***** <---use this to send the down and up together
pInputs
[in] Pointer to an array of INPUT structures. Each structure represents an event to be inserted into the keyboard or mouse input stream.
cbSize
[in] Specifies the size, in bytes, of an INPUT structure. If cbSize is not the size of an INPUT structure, the function will fail.
To get upper case you need to press Shift programmatically.
About array of structures: you must allocate array of structures in unmanaged memory using Marshal class. See: Marshal.AllocHGlobal, Marshal.StructureToPtr methods. In this case second SendInput parameter must be defined as IntPtr.
About array of structures: you must allocate array of structures in unmanaged memory using Marshal class. See: Marshal.AllocHGlobal, Marshal.StructureToPtr methods. In this case second SendInput parameter must be defined as IntPtr.