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
Printable View
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.Quote:
Originally Posted by Alphamonkey
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
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
You already are:If you want to do something other than write a line to the Debug listener then do so.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
woop woop... i have to remember that one.
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
also how would i have it so it knows that two hotkeys are pressed.....like alt-prntscreen
I look it up pretty quickly, but I think this is the correct combo. MOD_ALT is correct, 44 is the value in question.Code:Public Const MOD_ALT = &H1
Call RegisterHotKey(Me.Handle, 14, MOD_ALT, 44)
source:
http://www.developerfusion.co.uk/show/271/
thanxks superbovine! but does anyone know a solution to my original problem?
this code should do that, it an API call so, it will global towards windows and it should over ride any key presses.