Jump to content
  • Revista PROGRAMAR: Já está disponível a edição #60 da revista programar. Faz já o download aqui!

pt_V1p3r

RegisterHotKey

Recommended Posts

pt_V1p3r

Boas,

Tenho um 'pequeno' grande problema o qual necessito de alguma ajuda.

Consigo controlar sem problema o registo de uma hotkey do genero ctrl+d e tudo funciona como e suposto mesmo sem focus no form.

O meu unico problema reside em que necessito que a hotkey seja do genero ctrl+alt+2+3+4, ou seja usando os 2 modifiers (ctrl+alt) que esses ja os controlo, mas depois apenas consigo usar uma unica tecla e eu necessito de mais 3.

Imports System.Runtime.InteropServices


Public Const MOD_ALT As Integer = &H1 'Alt
Public Const MOD_CONTROL As Integer = &H2 'Control
Public Const MOD_SHIFT As Integer = &H4 'shift

Public Const K_Numpad0 As Integer = &H60 'numpad 0
Public Const K_Numpad1 As Integer = &H61 'numpad 1

Public Const WM_HOTKEY As Integer = &H312

<DllImport("User32.dll")> _
Public Shared Function RegisterHotKey(ByVal hwnd As IntPtr, ByVal id As Integer, ByVal fsModifiers As Integer, ByVal vk As Integer) As Integer
End Function

<DllImport("User32.dll")> _
Public Shared Function UnregisterHotKey(ByVal hwnd As IntPtr, ByVal id As Integer) As Integer
End Function

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
	RegisterHotKey(Me.Handle, 100, MOD_CONTROL Or MOD_ALT, Keys.A)
	RegisterHotKey(Me.Handle, 200, MOD_ALT, K_Numpad1)
End Sub

Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
	If m.Msg = WM_HOTKEY Then
		Dim id As IntPtr = m.WParam
		Select Case (id.ToString)
			Case "100"
				MessageBox.Show("CTRL+ALT+A")
			Case "200"
				MessageBox.Show("ALT+NUMPAD1")
		End Select
	End If
	MyBase.WndProc(m)
End Sub

Private Sub Form1_FormClosing(ByVal sender As System.Object, _
					ByVal e As System.Windows.Forms.FormClosingEventArgs) _
					Handles MyBase.FormClosing
	UnregisterHotKey(Me.Handle, 100)
	UnregisterHotKey(Me.Handle, 200)
End Sub

Alguem tem alguma ideia ?

Edited by Caça
GeSHi

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.