|
-
Jan 7th, 2007, 11:33 PM
#1
Thread Starter
Lively Member
[RESOLVED] [2005] Addhandler of Current Window
I want it so that whenever a button is pressed no matter what window its in...my program will know it.
basically i want to add a handler of the currentwindow.keypress
-
Jan 8th, 2007, 12:19 AM
#2
Hyperactive Member
Re: [2005] Addhandler of Current Window
 Originally Posted by Alphamonkey
I want it so that whenever a button is pressed no matter what window its in...my program will know it.
basically i want to add a handler of the currentwindow.keypress
You'll have to use the Windows API for that.
Here is a good working example in 2005. I got the example workig in the post with a little tweaking.
http://forums.microsoft.com/msdn/sho...28399&siteid=1
-
Jan 8th, 2007, 12:27 AM
#3
Thread Starter
Lively Member
Re: [2005] Addhandler of Current Window
I found this on the link you sent me, but i am still confused as now...how would i tell my program to, when the hotkey is pressed, do something.
VB Code:
Public Declare Function RegisterHotKey Lib "user32" (ByVal hwnd As IntPtr, ByVal id As Integer, ByVal fsModifiers As Integer, ByVal vk As Integer) As Integer
Public Declare Function UnregisterHotKey Lib "user32" (ByVal hwnd As IntPtr, ByVal id As Integer) As Integer
Public Const WM_HOTKEY As Integer = &H312
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
If m.Msg = WM_HOTKEY Then
' Pressed the hotkey!
Debug.WriteLine(m.Msg.ToString & ":" & m.WParam.ToString & ":" & m.LParam.ToString)
End If
MyBase.WndProc(m) '<-- Never Ever Forget This!
End Sub
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
Call UnregisterHotKey(Me.Handle, 9) '<-- Don't forget this
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Call RegisterHotKey(Me.Handle, 9, 0, 44) '<-- Play with these settings
End Sub
-
Jan 8th, 2007, 12:34 AM
#4
Re: [2005] Addhandler of Current Window
You already are:
VB Code:
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
If m.Msg = WM_HOTKEY Then
' Pressed the hotkey! [COLOR=Red]<--- Woop, Woop[/COLOR]
Debug.WriteLine(m.Msg.ToString & ":" & m.WParam.ToString & ":" & m.LParam.ToString)
End If
MyBase.WndProc(m) '<-- Never Ever Forget This!
End Sub
If you want to do something other than write a line to the Debug listener then do so.
-
Jan 8th, 2007, 12:41 AM
#5
Hyperactive Member
Re: [2005] Addhandler of Current Window
woop woop... i have to remember that one.
-
Jan 8th, 2007, 01:06 AM
#6
Thread Starter
Lively Member
Re: [2005] Addhandler of Current Window
im still having a problem now.....
the prtscr works, but only when the application is active.
VB Code:
Public Class Form1
Public Declare Function RegisterHotKey Lib "user32" (ByVal hwnd As IntPtr, ByVal id As Integer, ByVal fsModifiers As Integer, ByVal vk As Integer) As Integer
Public Declare Function UnregisterHotKey Lib "user32" (ByVal hwnd As IntPtr, ByVal id As Integer) As Integer
Public Const WM_HOTKEY As Integer = &H312
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
If m.Msg = WM_HOTKEY Then
' Pressed the hotkey!
PictureBox1.Image = Clipboard.GetImage()
Me.ShowInTaskbar = False
Me.WindowState = FormWindowState.Normal
End If
MyBase.WndProc(m) '<-- Never Ever Forget This!
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.ShowInTaskbar = True
Me.WindowState = FormWindowState.Minimized
RegisterHotKey(Me.Handle, 9, 0, 44)
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
SaveFileDialog1.ShowDialog()
PictureBox1.Image.Save(SaveFileDialog1.FileName)
End Sub
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
Call UnregisterHotKey(Me.Handle, 9) '<-- Don't forget this
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Call RegisterHotKey(Me.Handle, 9, 0, 44) '<-- Play with these settings
End Sub
End Class
i have it so it minimizes, you press a key (prntscreen) then it takes the screenshot (using windows) and pastes it in the picture box. it goes back to normal windowed mode when prnt screen is pressed, but it doesnt actually prnt screen. Windows only prntscreens when my app is active. If im not making myself clear tell me and i will clarify
-
Jan 8th, 2007, 02:19 AM
#7
Thread Starter
Lively Member
Re: [2005] Addhandler of Current Window
also how would i have it so it knows that two hotkeys are pressed.....like alt-prntscreen
-
Jan 8th, 2007, 09:24 AM
#8
Hyperactive Member
Re: [RESOLVED] [2005] Addhandler of Current Window
Code:
Public Const MOD_ALT = &H1
Call RegisterHotKey(Me.Handle, 14, MOD_ALT, 44)
I look it up pretty quickly, but I think this is the correct combo. MOD_ALT is correct, 44 is the value in question.
source:
http://www.developerfusion.co.uk/show/271/
-
Jan 8th, 2007, 04:17 PM
#9
Thread Starter
Lively Member
Re: [RESOLVED] [2005] Addhandler of Current Window
thanxks superbovine! but does anyone know a solution to my original problem?
-
Jan 8th, 2007, 07:32 PM
#10
Hyperactive Member
Re: [RESOLVED] [2005] Addhandler of Current Window
this code should do that, it an API call so, it will global towards windows and it should over ride any key presses.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|