Grabbing Special Key Combos

Raventara

Member
Joined
Jun 8, 2004
Messages
16
Programming Experience
1-3
okay, I'm writing a program that I want to sit over the desktop area of windows. Kind of a replacment. What I'm trying to work out is, is it possible to grab special windows key combos like Start+D to goto desktop??

I know you can grab normal keys and Ctrl+D type keys, but how can you grab Start+D type keys, if at all??

Regards, Raven
 

Paszt

Staff member
Joined
Jun 3, 2004
Messages
1,500
Location
Raleigh, NC - USA
Programming Experience
Beginner
I wrote a browser that hides when it looses focus and becomes visible when a special key combination is pressed (Winkey+G for examaple. The Start key is often called the Windows Key or WinKey). It uses API calls to hook into the keyBoard so it can capture keys without having to have a form with focus.

Attached is the class I use. It needs a little work.

Let me know if you need help using it, if this is what you want.
 

Attachments

Raventara

Member
Joined
Jun 8, 2004
Messages
16
Programming Experience
1-3
Thanks, that's exactly the kind of thing that I want, but yes, I would like some help on it. ;)
 

Paszt

Staff member
Joined
Jun 3, 2004
Messages
1,500
Location
Raleigh, NC - USA
Programming Experience
Beginner
To use it, first add it to your project (of course :)). Here's some sample code for the Winkey+D (Start+D):

VB.NET:
Public WithEvents kh As New KeyboardHook()

Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) _
  Handles MyBase.Load
    'this causes kh to send only keyups (or downs) for the D key
    kh.SetKeys("D")
End Sub

Private Sub kh_KeyUp(ByVal P As PopUpBrowser.KeyboardHook.KBDLLHOOKSTRUCT) _
  Handles kh.KeyUp
    If kh.WinKey Then
        'show the replacement desktop
    End If
End Sub

Private Sub Form1_Closing(ByVal sender As Object, _
 ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
    kh.Unhook()
End Sub
 

Paszt

Staff member
Joined
Jun 3, 2004
Messages
1,500
Location
Raleigh, NC - USA
Programming Experience
Beginner
The combo WinKey+D (in Windows XP at least) also shows the desktop and minimizes all windows. Doing the above won't stop that, but will only add to it. I'm not sure how to overcome that.
 

Raventara

Member
Joined
Jun 8, 2004
Messages
16
Programming Experience
1-3
hmmmm.... surely there'd be an API call to make your form the active window.....
 

Jonatan

Member
Joined
Jun 8, 2004
Messages
11
Location
Cuba
Programming Experience
3-5
API Function

Raventara said:
hmmmm.... surely there'd be an API call to make your form the active window.....
Sure! It´s name is SetFocus(hwnd) where hwnd is the window's handle.
Enjoy it!
 

Raventara

Member
Joined
Jun 8, 2004
Messages
16
Programming Experience
1-3
Ummm.. Sory if I'm just being blind or something, but SetFocus doesn't seem to appear anywhere in VB.NET... There's form.focus(), but I think that's only for multiple form apps, not when the whole thing's not in focus.
 
Top Bottom