Jump to content
Sign in to follow this  
programadorvb6

[Resolvido] Detectar combinação de 3 teclas

Recommended Posts

programadorvb6

Olá bom dia.

Tenho este código exemplo que me detecta, o pressionar da combinação entre duas teclas ALT+F10, mas gostaria de lhes adicionar mais a tecla: SHIFT ou seja ( SHIFT + ALT+F10 ).

Como o posso fazer?

Grato desde já pela vossa atenção.

ProgramadorVB6

Imports System.Runtime.InteropServices
Public Class Form1
 Public Const MOD_ALT As Integer = &H1		   'Alt key
 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
 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("Pressionou as teclas ALT+F9")
			 Case "200"
				 MessageBox.Show("Pressionou as teclas ALT+F10")
		 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

 Private Sub Form_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
	 RegisterHotKey(Me.Handle, 100, MOD_ALT, Keys.F9)
	 RegisterHotKey(Me.Handle, 200, MOD_ALT, Keys.F10)
 End Sub
 Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
	 Me.Hide()
 End Sub
End Class


______________________________________________________________________________

Que minha coragem seja maior que meu medo e que minha força seja tão grande quanto minha fé.
 

Share this post


Link to post
Share on other sites
programadorvb6

Arranjei esta solução, não sei se será a mais indicada ..

Imports System.Runtime.InteropServices
Public Class Form1
Public Const MOD_CONTROL As Integer = &H2 'Tecla: Control
Public Const MOD_SHIFT As Integer = &H4 'Tecla: Shift
Public Const MOD_ALT As Integer = &H1	 'Tecla: Alt
Public Const WM_HOTKEY As Integer = &H312 'Liga.
<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
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("Pressionou as teclas ALT+F9")
		 Case "200"
			 MessageBox.Show("Pressionou as teclas ALT+F10")
		 Case "300"
			 ' MessageBox.Show("Pressionou as teclas CTRL+ALT+SHIFT+F10")
			 Me.Show()
	 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)
 UnregisterHotKey(Me.Handle, 300)
End Sub

Edited by programadorvb6

______________________________________________________________________________

Que minha coragem seja maior que meu medo e que minha força seja tão grande quanto minha fé.
 

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
Sign in to follow this  

×
×
  • Create New...

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.