Results 1 to 6 of 6

Thread: Stupid VB question.

  1. #1
    Constant Bitrate
    Join Date
    May 2002
    Posts
    146

    Stupid VB question.

    Ok so im programing in vb not to hard. How do i make a button work when i press a key? Like make "k" button equal play. Or the key pad number 4 as pause.

  2. #2
    FLAC
    Join Date
    Apr 2001
    Location
    Here, There, Everywhere
    Posts
    1,436

    Re: Stupid VB question.

    a simple way is if you preceed the "caption" setting of the VB button with a '&' the following character will activate the button....

    so...

    &Play - will play when u hit the "P" key
    Ma&gnetik = will hit the magnetik button when u presses the "G" key....

    u can do more advanced things with APIs/etc to read keyboard keypresses too....
    Project - GAME OVER :(

  3. #3
    FLAC Gutter's Avatar
    Join Date
    Dec 1999
    Location
    Casina, Italy
    Posts
    901
    Use the Form_Keydown event to catch keys. Unfortunately, the form has to be active for that to work, meaning it won't catch anything if the form isn't active. There's ways of catching all keystrokes, but that should be good enough for now.

  4. #4
    Variable Bitrate
    Join Date
    Jul 2001
    Location
    The Netherlands
    Posts
    307
    the best way to do this is to place a timer on the form, set the interval to like 100 and add this code:

    private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer

    Private Sub keyTimer_Timer()
    If (GetAsyncKeyState(&H68) <> 0) Then command1_click 'if number 8 is pressed, emulate click on command1 button

    End Sub

    using the getasync function it will "capture" your keypress even if an other app is active...

    I'm not sure how to find out what the keycode's are, do a search on internet....
    If at first you don't succeed.........
    destroy all evidence you tried

    for info on t6369c LCD or Presslab's powersupply check:
    http://www.namms.tk <=updated!!

  5. #5
    Constant Bitrate
    Join Date
    May 2002
    Posts
    146
    cosidering I am a dumb *** can you post an example of the key down function,

  6. #6
    FLAC Gutter's Avatar
    Join Date
    Dec 1999
    Location
    Casina, Italy
    Posts
    901
    Create a form with two command buttons (Command1 and Command2). Set the "KeyPreview" property of the form to "True." Add this code to your project:

    ''''''''''''''''''''''''''''''''''''''''''''''''''
    Private Sub Command1_Click()
    Debug.Print "Button 1 was clicked"
    End Sub
    Private Sub Command2_Click()
    Debug.Print "Button 2 was clicked"
    End Sub

    Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
    Select Case KeyCode
    Case vbKeyT
    Command1_Click
    Case vbKeyW
    Command2_Click
    End Select
    End Sub

    ''''''''''''''''''''''''''''''''''''''''''''''''''

Bookmarks

Posting Permissions

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