Solved

Checking Ctrl-Key

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

707 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

14 Experts available now in Live!

Get 1:1 Help Now