This follows a previous post, when I was trying to capture a key
pressed during the immediate opening of a form (ie in the first
3-secs before processing any of the code that followed it.
It was mentioned that the KeyDown event fires the instant a key is
pressed down.
So, if you place the following code in a form, you'll see my
concern.
Test1: First run the code 'as is', with the Msgbox off in the
Form_Open. Press any key the instant the form opens.
It seems the KeyDown event occurs during the pause and Msg1 shows the
key value.
Test2: Now UnComment the Form_Open msgbox and see what happens when
you press a key the instant the form opens. Its value is blank and
Msg1 is never revealed.
Any Ideas???
Thanks Greg
Private MyKey As Variant
'***************** Code Start *******************
' This code was originally written by Dev Ashish.
' It is not to be altered or distributed,
' except as part of an application.
' You are free to use it in any application,
' provided the copyright notice is left unchanged.
'
' Code Courtesy of
' Dev Ashish
'
Private Declare Sub sapiSleep Lib "kernel32" _
Alias "Sleep" _
(ByVal dwMilliseconds As Long)
Sub sSleep(lngMilliSec As Long)
If lngMilliSec 0 Then
Call sapiSleep(lngMilliSec)
End If
End Sub
'***************** Code End *********************
' My Test Code Follows:
Public Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
MyKey = KeyCode
MsgBox "Msg1 " & MyKey
End Sub
Public Sub Form_Open(Cancel As Integer)
Dim I As Integer
sSleep (3000) 'stop the code for 3-secs
' MsgBox "Msg2 " & MyKey
End Sub