Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Checking Ctrl-Key

Posted on 1998-06-06
1
Medium Priority
?
178 Views
Last Modified: 2010-05-03
Is there any chance to check if Ctrl- or Alt- key are pressed for some seconds while no other key is hit?
0
Comment
Question by:mas11
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 

Accepted Solution

by:
loguea earned 400 total points
ID: 1462691
Create a new project and copy the following into the code window for Form1.
Then run the project and hold down the control key. After 5 seconds you will
see a message box come up.

Private Declare Function timeGetTime Lib "winmm.dll" () As Long

Private Const TIME_LIMIT As Long = 5000 ' milli secs
Private Const ONE_SECOND As Long = 1000
Private mlTime As Long
Private mbCtrlPressed As Boolean

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    If mbCtrlPressed Then
        If (timeGetTime() - mlTime) >= TIME_LIMIT Then
            ' Control key has been pressed for the
            ' specified amount of time.
            MsgBox "Ctrl Key pressed for " & CStr(TIME_LIMIT / ONE_SECOND) & " secs"
            mlTime = 0
            mbCtrlPressed = False
        End If
    End If
    If KeyCode = vbKeyControl And Not mbCtrlPressed Then
        mbCtrlPressed = True
        mlTime = timeGetTime()
    End If
End Sub

Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
    If KeyCode = vbKeyControl Then
        mbCtrlPressed = False
        mlTime = 0
    End If
End Sub


0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

604 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