Results 1 to 6 of 6

Thread: HOTKEY PLS!!!

  1. #1

    Thread Starter
    Member
    Join Date
    Oct 2000
    Location
    Philippines
    Posts
    49

    Exclamation

    how can i make hotkeys for graphical command buttons? I know its easy if i have a standard-command button (i will just have to use the ampersand & command right?) my command button does not use captions but i need to have a hotkey for it. Hope you guys can help me ASAP.

  2. #2
    Lively Member
    Join Date
    Aug 2000
    Location
    quebec
    Posts
    81
    You can do this very simply by using a timer and the API GetAsyncKeyState(vkey) function.

    Code:
    Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
    
    
    Private Sub Form_Load()
        Timer1.Interval = 100 'interval at which to check keys
    End Sub
    
    Private Sub Timer1_Timer()
        If GetAsyncKeyState(vbKeyControl) And GetAsyncKeyState(vbKeyC) Then ' check if Ctrl+C was entered
            MsgBox "Ctrl+C entered"
        End If
    End Sub
    For some reason there is no vbAlt key code.

    You could also do this in a less elegant way by entering your hotkey & in the button's caption as usual then selecting
    a font size of 1 - however a tiny dot will still appear on the button.

    The other, more complicated but probably best way, is to use the API SendMessage function with the WM_SETHOTKEY command.

    But this requires you to subclass the control.

    You can find an example of this here: http://www.vbsquare.com/articles/hotkey/

    Hope this helps
    C/C++,Delphi,VB6,Java,PB (blech!),ASP,JSP,SQL...bla bla bla and bla
    I love deadlines. I like the whooshing sound they make as they fly by.
    —Douglas Adams

  3. #3
    Junior Member
    Join Date
    Sep 2000
    Location
    South Africa
    Posts
    25

    Cool

    you could also put a label with a description of the button on it , next to the button and the assign the hotkey to the label.
    all you then have to do is link , through code , the button and respective label.

    but a word of note : unless you are developing the program for some kiddies to use , you should stay away from pics on cmdbuttons , they ruin the look of the app and take up more RAM . Users also get sick of the pictures after using the app for some time.
    Trust me , I know from experience
    {just a word of advice , use it , abuse it :-) }
    Go Luke , and may the source be with you.

  4. #4
    Lively Member
    Join Date
    Aug 2000
    Location
    quebec
    Posts
    81

    Arrow

    Railor

    Good idea also, but if the label has a tab order just before the button's tab order you don't need any code link.

    The label can't be edited and it never receives focus so the next control in the tab order receives it.

    And if you make the label so small you can't see it the user won't even know it's there.
    C/C++,Delphi,VB6,Java,PB (blech!),ASP,JSP,SQL...bla bla bla and bla
    I love deadlines. I like the whooshing sound they make as they fly by.
    —Douglas Adams

  5. #5
    Guest
    Even easier, set the Form's KeyPreview property to True and put this code in the Command1_KeyDown or Form_KeyDown event.

    Code:
    Private Sub Command1_KeyDown(KeyCode As Integer, Shift As Integer)
    Select Case KeyCode
        Case vbKeyA To vbKeyZ:
        MsgBox Chr(KeyCode) & " key pressed."
    End Select
    End Sub
    If any key from A to Z is pressed, than a Msgbox will pop up telling you which key was pressed.

  6. #6
    Junior Member
    Join Date
    Sep 2000
    Location
    South Africa
    Posts
    25

    Smile

    Hitcgar

    thnaks 4 reminding me , i forgot about that one (label no focus)
    I just said that , because we have a program here (where i work) that has labels and cmdbuttons as mentioned b4
    we have now removed the pics from the cmdbuttons but still have the labels so that users can use the label kotkey as well as click on the labels
    :-)
    Go Luke , and may the source be with you.

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