Keyboard Invoke Keypress method - Printable Version +- Support Forums (https://www.supportforums.net) +-- Forum: Categories (https://www.supportforums.net/forumdisplay.php?fid=87) +--- Forum: Coding Support Forums (https://www.supportforums.net/forumdisplay.php?fid=18) +---- Forum: Visual Basic and the .NET Framework (https://www.supportforums.net/forumdisplay.php?fid=19) +---- Thread: Keyboard Invoke Keypress method (/showthread.php?tid=21170) |
Keyboard Invoke Keypress method - AceInfinity - 08-07-2011 This time I've decided to share with you a little function from the Win API in user32.dll. It's an invoke method for a virtual keypress. Here's the general code, in this example i'll show you how to simultate the enter/return keypress event: Code: Imports System.Runtime.InteropServices You need to do the Imports for System.Runtime.InteropServices so that you can call the API with dllimport. Everything is defined at the top of the class in this example. The button event on the form is what calls the enter keypress event. VK_ENTER (Virtual Key Enter) I've defined as a Byte with a value of 13 because that's just the defined value for an enter/return keypress. You always need a key_up event otherwise it will only be a keydown event and not a full key press, so that is defined at the top of the button sub as well with a value of 2. Code: keybd_event(VK_ENTER , 0, 0, 0) Code: keybd_event(VK_ENTER , 0, KEYEVENT_KEYUP, 0) There are certain key values for things like the scroll lock, num lock and virtually almost any key on a standard, and some custom keyboard buttons, but this is just the basics, You can get these key events on a timer, or generate them from a registered global hotkey like i've done in the past, it's really up to you on how you use this. |