Home All Groups Group Topic Archive Search About

KeyDown for non Active windows?

Author
7 Apr 2006 5:43 AM
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?

Author
7 Apr 2006 9:39 PM
ShaneO
gregory_may wrote:
> 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.
Author
11 Apr 2006 11:14 PM
gregory_may
Thanks!

Show quoteHide quote
"ShaneO" <shane***@optusnet.com.au> wrote in message
news:4436dbb2$0$7528$afc38c87@news.optusnet.com.au...
> gregory_may wrote:
>> 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.
Author
12 Apr 2006 6:14 AM
gregory_may
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


Show quoteHide quote
"ShaneO" <shane***@optusnet.com.au> wrote in message
news:4436dbb2$0$7528$afc38c87@news.optusnet.com.au...
> gregory_may wrote:
>> 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.
Author
14 Apr 2006 1:10 AM
ShaneO
gregory_may wrote:
> 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.
Author
14 Apr 2006 5:20 PM
Tom Bianchi
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.


Show quoteHide quote
"ShaneO" <shane***@optusnet.com.au> wrote in message
news:4436dbb2$0$7528$afc38c87@news.optusnet.com.au...
> gregory_may wrote:
>> 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.