KeyDown for non Active windows?

  • Thread starter Thread starter gregory_may
  • Start date Start date
G

gregory_may

I want to trap a key at the System wide level.

Similar to Win-Amp ... you can press - Ctrl-Alt-Pg down from Any Program &
switch songs.

How can I do this in VB.Net?
 
gregory_may said:
I want to trap a key at the System wide level.

Similar to Win-Amp ... you can press - Ctrl-Alt-Pg down from Any Program &
switch songs.

How can I do this in VB.Net?
Here's how I do it with Alt-F12 (As always, watch for Line-Wrapping!):

Public Declare Auto Function SendMessage Lib "user32.dll" (ByVal hWnd As
IntPtr, ByVal wMsg As Int32, ByVal wParam As Int32, ByVal s As String)
As Int32

Const WM_SETHOTKEY As Long = &H32
Const HotKey_Alt_F12 As Long = &H47B

Private Sub MainFrm_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load

SendMessage(Me.Handle, WM_SETHOTKEY, HotKey_Alt_F12, 0)

End Sub

Hope this helps.

ShaneO

There are 10 kinds of people - Those who understand Binary and those who
don't.
 
Thanks!

ShaneO said:
Here's how I do it with Alt-F12 (As always, watch for Line-Wrapping!):

Public Declare Auto Function SendMessage Lib "user32.dll" (ByVal hWnd As
IntPtr, ByVal wMsg As Int32, ByVal wParam As Int32, ByVal s As String) As
Int32

Const WM_SETHOTKEY As Long = &H32
Const HotKey_Alt_F12 As Long = &H47B

Private Sub MainFrm_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load

SendMessage(Me.Handle, WM_SETHOTKEY, HotKey_Alt_F12, 0)

End Sub

Hope this helps.

ShaneO

There are 10 kinds of people - Those who understand Binary and those who
don't.
 
gregory_may said:
I found this, but not sure if its overkill? I am curious why your code is
so short?

http://www.dotnet2themax.com/ShowContent.aspx?ID=103cca7a-0323-47eb-b210-c2bb7075ba78
Gregory, I can't access your link at the time of this message (maybe a
temporary problem) however I too have seen some VERY long-winded code
written to do exactly what the code I provided does easily.

If you've tried it yourself then you will know it works perfectly.

The long-winded approach seems more common for .NET solutions than
anything I've ever seen before and is something I have commented on in
the past. I don't know why it is so, but maybe that could be the topic
of a post on its own - like, Why are some people making things that are
easy seem so difficult??

ShaneO

There are 10 kinds of people - Those who understand Binary and those who
don't.
 
Hi,

this is very interesting. I don't understand where to search for the other
key codes on MSDN.
The WM_SETHOTKEY topic isn't of much help.

Thanks,
Tom.
 
Back
Top