-
need to know if the user pressed F12...
-
I just made a little program in Excel that tells what key you pressed. Try this.
Code:
Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
TextBox2.Text = TextBox2.Text & vbCrLf & "KeyCode = " & CStr(KeyCode)
TextBox1.SetFocus
End Sub
Private Sub UserForm_Initialize()
Move 0, 0, 570, 380
TextBox1.Move 30, 40, 220, 160
TextBox1.MultiLine = True
TextBox1.WordWrap = True
TextBox1.Text = "Type text here."
TextBox1.EnterKeyBehavior = True
TextBox2.Move 298, 40, 220, 160
TextBox2.MultiLine = True
TextBox2.WordWrap = True
TextBox2.Text = "ASCII code"
TextBox2.Locked = True
TextBox2.ScrollBars = fmScrollBarsVertical
End Sub
Set up a user form with 2 textboxes (textbox1 and textbox2).
Does this work for all situations? I don't know.
[Edited by billwagnon on 05-25-2000 at 03:03 PM]
-
This should do it:
Code:
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Private Const VK_F12 = &H7B
Private b_running As Boolean
Private Sub Form_Load()
b_running = True
Me.Show
Do Until b_running = False
DoEvents
If GetAsyncKeyState(VK_F12) Then
Debug.Print "F12 Pressed"
End If
Loop
End Sub
Private Sub Form_Unload(Cancel As Integer)
b_running = False
End Sub