954,582 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Hiding a form with keyboard shortcuts...

I can easily hide my form with the event KeyDown, but only by pressing ONE key, and I wanna hide it by pressing CTRL+SHIFT+O, for example. And the biggest problem is when I wanna restore it, because I have to go to the Task Manager, make the aplication has the focus and then press SHIFT. What can I do?

killbill07
Newbie Poster
17 posts since Oct 2010
Reputation Points: 10
Solved Threads: 1
 
I can easily hide my form with the event KeyDown, but only by pressing ONE key, and I wanna hide it by pressing CTRL+SHIFT+O, for example. And the biggest problem is when I wanna restore it, because I have to go to the Task Manager, make the aplication has the focus and then press SHIFT. What can I do?

The first problem can be easily solved. The keydown event has a second parameter (the so called shift value). This second parameter captures the state of the modifier keys.

Example:

Private Sub WhateverCtrl_KeyDown (KeyCode As Integer, Shift As Integer)
    Dim ShiftDown, AltDown, CtrlDown

    ShiftDown = (Shift And vbShiftMask) > 0
    AltDown = (Shift And vbAltMask) > 0
    CtrlDown = (Shift And vbCtrlMask) > 0

    if KeyCode = "O" And CtrlDown And ShiftDown then
        msgbox "Ctrl + Shift + O"
    end if
End Sub


The second one I would guess is not easily solved. As the focus is with another application, you have no control over that applications KeyPress ... events.

What you can do is use "Ctrl-Tab" (the normal Windows functionality) to get the focus back to your application and then use another key combination at the main form level to restore it.

maba001
Junior Poster in Training
60 posts since Jun 2008
Reputation Points: 9
Solved Threads: 9
 

Thanks for helping but I had that solution before you answered. I'll show my code for other people that may need the code...

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
    Case Is = vbKeyControl
    ctrl = True
    Case Is = vbKeyAlt
    alt = True
    Case Is = vbKeyO
    o = True
End Select
'As you can see, I created variables for every key, but that's optional.
    If Me.Visible = True Then
            If ctrl = True And alt = True And o = True Then
                WindowsMediaPlayer1.settings.mute = True
                Me.Visible = False
            End If
    Else
            If ctrl = True And alt = True And o = True Then
                WindowsMediaPlayer1.settings.mute = False
                Me.Visible = True
            End If
    End If

You can use an If if you want, but is better for me with a select case because if I have more than one key combination, I'll have some trouble in the future reading more than four ifs.
P.S.:This is a .mp3 player :)

killbill07
Newbie Poster
17 posts since Oct 2010
Reputation Points: 10
Solved Threads: 1
 

Killbill,
If your problem is solved, please mark it as Resolved.
Thanks

kinwang2009
Posting Whiz in Training
243 posts since Feb 2010
Reputation Points: 17
Solved Threads: 42
 
You can use an If if you want, but is better for me with a select case because if I have more than one key combination, I'll have some trouble in the future reading more than four ifs. P.S.:This is a .mp3 player :)

Was meant as an example of the shift parameter only :). And I would call it "a shell around windows media player" instead of an MP3-player. It will not run without it :).

maba001
Junior Poster in Training
60 posts since Jun 2008
Reputation Points: 9
Solved Threads: 9
 

Yes, I know, but I can't find another way to play music by now.

killbill07
Newbie Poster
17 posts since Oct 2010
Reputation Points: 10
Solved Threads: 1
 

Finally, I have the solution. I wrote the code using the getasynckey function and a timer. It was easier than I thought it was.
If someone need to do it, this docs can help:
http://msdn.microsoft.com/en-us/library/aa243025(VS.60).aspx
http://msdn.microsoft.com/en-us/library/ms646293(VS.85).aspx

killbill07
Newbie Poster
17 posts since Oct 2010
Reputation Points: 10
Solved Threads: 1
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: