Results 1 to 4 of 4

Thread: Key Press Out Side VB Form

  1. #1

    Thread Starter
    Hyperactive Member MikeBAM's Avatar
    Join Date
    Sep 2000
    Location
    Metro Detroit
    Posts
    284

    Question

    I'm wondering how i can make something to tell if a key or combination of keys are pressed while a program is running. The form does not have to be the top window. Like if you are on you computer, where ever you are, with your program running, and you hit CTRL + ESC, then do something. Or any specific keys. How Would You Do This?? Please Help.
    ~* )v( ! /< E *~

  2. #2
    Guest
    Use the GetAsyncKeyState API. Add the following to a Form with a Timer.
    Code:
    Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
    
    Private Sub Form_Load()
        Timer1.Interval = 50
    End Sub
    
    Private Sub Timer1_Timer()
        If GetAsyncKeyState(vbKeyControl) And GetAsyncKeyState(vbKeyEscape) Then MsgBox "CTRL+ESC was pressed"
    End Sub

  3. #3
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Place a timer on the form paste this code:
    Code:
    Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
    Private Const VK_CONTROL = &H11
    Private Const VK_ESCAPE = &H1B
    
    Private Sub Timer1_Timer()
        If GetAsyncKeyState(VK_CONTROL) And GetAsyncKeyState(VK_ESCAPE) Then MsgBox "CTRL + ESC PRESSED"
    End Sub
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  4. #4
    Guest
    The constants are already internally defined in VB, so you can omit them.

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