Solved

Checking Ctrl-Key

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

815 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now