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?

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.

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 :)

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

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 :).

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.