Results 1 to 4 of 4

Thread: show form at shortcut key

  1. #1

    Thread Starter
    Lively Member adifel's Avatar
    Join Date
    Jan 2006
    Location
    California
    Posts
    103

    show form at shortcut key

    I have this form which I need to be hidden (me.hide) and I would like still to be able to view it sometimes without putting it on tray, is it possible to create a shortcut key to make it visible(me.show)? Thanks

  2. #2
    Addicted Member
    Join Date
    Apr 2006
    Posts
    155

    Re: show form at shortcut key

    Yes there is, and since the form won't have focus while you press this keyevent occurs we're going to have to get it from GetAysncKeyState.

    VB Code:
    1. 'Put this in General Declarations
    2. Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As KeyCodeConstants) As Long
    3.  
    4. 'Function to capture key-events
    5. Public Function KeyDown(ByVal vKey As KeyCodeConstants) As Boolean
    6.    KeyDown = GetAsyncKeyState(vKey) And &H8000
    7. End Function

    Now create a timer and paste this code;

    VB Code:
    1. If KeyDown(vbKeyControl) And KeyDown(vbKeyS) Then
    2.    Me.Show
    3.  End If

  3. #3

    Thread Starter
    Lively Member adifel's Avatar
    Join Date
    Jan 2006
    Location
    California
    Posts
    103

    Re: show form at shortcut key

    Thanks, that works wonderful.

  4. #4
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,729

    Re: show form at shortcut key

    You can try RegisterHotKey API.
    VB Code:
    1. ' Paste this code inside a form
    2. Option Explicit
    3. Private Const MOD_ALT = &H1
    4. Private Const MOD_CONTROL = &H2
    5. Private Const MOD_SHIFT = &H4
    6. Private Const PM_REMOVE = &H1
    7. Private Const WM_HOTKEY = &H312
    8. Private Type POINTAPI
    9.     x As Long
    10.     y As Long
    11. End Type
    12. Private Type Msg
    13.     hWnd As Long
    14.     Message As Long
    15.     wParam As Long
    16.     lParam As Long
    17.     time As Long
    18.     pt As POINTAPI
    19. End Type
    20. Private Declare Function RegisterHotKey Lib "user32" (ByVal hWnd As Long, ByVal id As Long, ByVal fsModifiers As Long, ByVal vk As Long) As Long
    21. Private Declare Function UnregisterHotKey Lib "user32" (ByVal hWnd As Long, ByVal id As Long) As Long
    22. Private Declare Function PeekMessage Lib "user32" Alias "PeekMessageA" (lpMsg As Msg, ByVal hWnd As Long, ByVal wMsgFilterMin As Long, ByVal wMsgFilterMax As Long, ByVal wRemoveMsg As Long) As Long
    23. Private Declare Function WaitMessage Lib "user32" () As Long
    24. Private bCancel As Boolean
    25. Private Sub ProcessMessages()
    26.     Dim Message As Msg
    27.     'loop until bCancel is set to True
    28.     Do While Not bCancel
    29.         'wait for a message
    30.         WaitMessage
    31.         'check if it's a HOTKEY-message
    32.         If PeekMessage(Message, Me.hWnd, WM_HOTKEY, WM_HOTKEY, PM_REMOVE) Then
    33.             'Hide/Unhide the form
    34.             [b]Me.Visible = Not Me.Visible[/b]
    35.         End If
    36.         'let the operating system process other events
    37.         DoEvents
    38.     Loop
    39. End Sub
    40. Private Sub Form_Load()
    41.     'KPD-Team 2000
    42.     'URL: [url]http://www.allapi.net/[/url]
    43.     'E-Mail: [email][email protected][/email]
    44.     Dim ret As Long
    45.     bCancel = False
    46.     'register the Ctrl-F hotkey
    47.     ret = RegisterHotKey(Me.hWnd, &HBFFF&, MOD_CONTROL, vbKeyF)
    48.     'show some information
    49.     Me.AutoRedraw = True
    50.     Me.Print "Press CTRL-F to minimize this form"
    51.     'show the form and
    52.     Show
    53.     'process the Hotkey messages
    54.     ProcessMessages
    55. End Sub
    56. Private Sub Form_Unload(Cancel As Integer)
    57.     bCancel = True
    58.     'unregister hotkey
    59.     Call UnregisterHotKey(Me.hWnd, &HBFFF&)
    60. End Sub
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


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