Solved

Checking Ctrl-Key

Posted on 1998-06-06
1
170 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 100 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

726 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