Results 1 to 3 of 3

Thread: What is the keycode of the F12 Key?? Or how do I catch it's keystroke?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2000
    Posts
    103
    need to know if the user pressed F12...

  2. #2
    Hyperactive Member billwagnon's Avatar
    Join Date
    Jul 1999
    Location
    St. Louis, Missouri, Mississippi Valley
    Posts
    290
    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]

  3. #3
    Fanatic Member
    Join Date
    Sep 1999
    Location
    Bethel, North Carolina, USA
    Posts
    987

    Talking

    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


    {Insert random techno-babble here}

    {Insert quote from some long gone mofo here}

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width