Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Vitual CTRL key - SetKeyboardState?

Posted on 2006-04-17
2
Medium Priority
?
661 Views
Last Modified: 2012-08-14
Can I use the user32 function SetKeyboardState to virtually enable the CTRL key?  I'm trying to code a button that when clicked will programatically "hold down" the CTRL key until the button is clicked again.

Any other suggestions?
0
Comment
Question by:CaitlinRoberts
2 Comments
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 750 total points
ID: 16468812
You can use the keybd_event() API:

    Private Declare Sub keybd_event Lib "user32.dll" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Integer, ByVal dwExtraInfo As Integer)
    Private Declare Function MapVirtualKey Lib "user32" Alias "MapVirtualKeyA" (ByVal wCode As Integer, ByVal wMapType As Integer) As Integer

    Private Sub KeyDown(ByVal key As Byte)
        keybd_event(key, MapVirtualKey(key, 0), 0, 0) ' Down
    End Sub

    Private Sub KeyUp(ByVal key As Byte)
        keybd_event(key, MapVirtualKey(key, 0), 2, 0) ' Up
    End Sub

Examples:

    KeyDown(Keys.ControlKey)
    KeyUp(Keys.ControlKey)


0
 

Author Comment

by:CaitlinRoberts
ID: 16469539
Thanks!
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses
Course of the Month15 days, 7 hours left to enroll

575 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question