?
Solved

Checking Ctrl-Key

Posted on 1998-06-06
1
Medium Priority
?
174 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

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…
Suggested Courses

762 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