none
Bloquear tecla Alt + ESC RRS feed

  • Pergunta

  • pessoal, 

    eu preciso bloquea a tecla ALT+ ESC, eu peguei um codigo aqui para bloquear outros atalhos com tecla windows, e ctrl + esc.

    mais não consegui bloquear ALT + ESC

    segue o codigo que eu uso para bloquear a teclas que já consegui

    Private Function LowLevelKeyboardProc(ByVal nCode As Integer, ByVal wParam As IntPtr, ByRef lParam As KBDLLHOOKSTRUCT) As Integer
            If (nCode = HC_ACTION) Then
                Select Case CType(wParam, Integer)
                    Case WM_KEYDOWN, WM_KEYUP, WM_SYSKEYDOWN, WM_SYSKEYUP
                        ' ALT+F4 
                        If ((lParam.flags And LLKHF_ALTDOWN) <> 0) AndAlso (lParam.vkCode = VK_F4) Then
                            Debug.WriteLine("ALT+F4")
                            Return 1 ' Engole mensagem
                        End If
                        ' ALT+TAB 
                        If ((lParam.flags And LLKHF_ALTDOWN) <> 0) AndAlso (lParam.vkCode = VK_TAB) Then
                            Debug.WriteLine("ALT+TAB")
                            Return 1
                        End If
    
                        ' CTRL+ESC 
    
                        If ((GetAsyncKeyState(VK_CONTROL) And &H8000) <> 0) AndAlso lParam.vkCode = VK_ESCAPE Then
                            Debug.WriteLine("CTRL+ESC")
                            Return 1
                        End If
    
                        'ALT + ESC
                        If ((GetAsyncKeyState(LLKHF_ALTDOWN) And &H8000) <> 0) AndAlso lParam.vkCode = VK_ESCAPE Then
                            Debug.WriteLine("ALT+ESC")
                            Return 1
                        End If
    
                        ' Tecla Windows
                        If lParam.vkCode = VK_LWIN OrElse lParam.vkCode = VK_RWIN Then
                            Debug.WriteLine("LWIN - RWIN")
                            Return 1
                        End If
                End Select
            End If
            Return CallNextHookEx(KeyboardHandle, nCode, wParam, lParam)
        End Function
    

    quinta-feira, 17 de abril de 2014 13:46

Respostas

  • Parece que neste artigo há um código que faz este bloqueio:

    C# Disable CTRL-ALT-DEL, ALT-TAB, ALT-F4, Start Menu and so on…

    Está em C#, mas você pode usar este conversor para prosseguir na empreitada:

    Convert C# to VB.NET - A free code conversion tool - developer Fusion


    Herbert Lausmann

    herbert obrigrado pela ajuda, o poste ajudou eu entender os codigos que eu tinha pego nesse site, já solucionei o problema, vou deixa abaixo o codigo que bloqueia as seguintes tecla ctrl + esc, alt + esc , alt + tab, alt + f4 e tecla windows. 

    para os codigos serem executados com sucesso e nessesario desativar " ENABLE THE VISUAL STUDIO HOSTING PROCESS"

    para localizar essa opção vá em propriedade do projeto > debug > desmaque a opção " ENABLE THE VISUAL STUDIO HOSTING PROCESS"

    Imports System.Reflection
    Imports System.Drawing
    Imports System.Runtime.InteropServices
    Imports System.Diagnostics
    
    Public Class KeyboardHook
        <DllImport("user32.dll")> _
        Private Shared Function UnhookWindowsHookEx(hhk As IntPtr) As Boolean
        End Function
        <DllImport("user32.dll")> _
        Private Shared Function SetWindowsHookEx(idHook As Integer, lpfn As KeyboardHookDelegate, hMod As IntPtr, dwThreadId As UInteger) As IntPtr
        End Function
        <DllImport("user32.dll")> _
        Private Shared Function GetAsyncKeyState(vKey As Integer) As Short
        End Function
        <DllImport("user32.dll")> _
        Private Shared Function CallNextHookEx(hhk As IntPtr, nCode As Integer, wParam As IntPtr, ByRef lParam As KBDLLHOOKSTRUCT) As Integer
        End Function
    
        Private Structure KBDLLHOOKSTRUCT
            Public vkCode As Integer
            Public scanCode As Integer
            Public flags As Integer
            Public time As Integer
            Public dwExtraInfo As Integer
        End Structure
    
        Private Const HC_ACTION As Integer = &H0
        Private Const LLKHF_EXTENDED As Integer = &H1
        Private Const LLKHF_INJECTED As Integer = &H10
        Private Const LLKHF_ALTDOWN As Integer = &H20
        Private Const LLKHF_UP As Integer = &H80
    
        Private Const VK_TAB As Integer = &H9
        Private Const VK_CONTROL As Integer = &H11
        Private Const VK_ALT As Integer = &H12
        Private Const VK_ESCAPE As Integer = &H1B
        Private Const VK_DELETE As Integer = &H2E
        Private Const VK_F4 As Integer = &H73
        Private Const VK_LWIN As Integer = &H5B
        Private Const VK_RWIN As Integer = &H5C
    
        Private Const WM_KEYDOWN As Integer = &H100
        Private Const WM_SYSKEYDOWN As Integer = &H104
        Private Const WM_SYSKEYUP As Integer = &H105
        Private Const WM_KEYUP As Integer = &H101
    
        Private Const WH_KEYBOARD_LL As Integer = &HD
    
        Private KeyboardHandle As IntPtr
    
        ' Callback
        Private Function LowLevelKeyboardProc(nCode As Integer, wParam As IntPtr, ByRef lParam As KBDLLHOOKSTRUCT) As Integer
            If (nCode = HC_ACTION) Then
                Select Case CInt(wParam)
                    Case WM_KEYDOWN, WM_KEYUP, WM_SYSKEYDOWN, WM_SYSKEYUP
                        ' ALT+F4 
    
                        If (lParam.flags And LLKHF_ALTDOWN) <> 0 AndAlso lParam.vkCode = VK_F4 Then
                            Debug.WriteLine("ALT+F4")
                            ' engole mensagem
                            Return 1
                        End If
                        ' ALT+TAB 
    
                        If (lParam.flags And LLKHF_ALTDOWN) <> 0 AndAlso lParam.vkCode = VK_TAB Then
                            Debug.WriteLine("ALT+TAB")
                            Return 1
                        End If
                        ' CTRL+ESC 
    
                        If ((GetAsyncKeyState(VK_CONTROL) And &H8000) <> 0) AndAlso lParam.vkCode = VK_ESCAPE Then
                            Debug.WriteLine("CTRL+ESC")
                            Return 1
                        End If
    
                        ' LWIN - RWIN 
    
                        If lParam.vkCode = VK_LWIN OrElse lParam.vkCode = VK_RWIN Then
                            Debug.WriteLine("LWIN - RWIN")
                            Return 1
                        End If
    
                        'Alt + TAB
                        If (lParam.flags And LLKHF_ALTDOWN) <> 0 AndAlso lParam.vkCode = VK_ESCAPE Then
                            Debug.WriteLine("ALT+TAB")
                            Return 1
                        End If
    
                        Exit Select
                End Select
            End If
            Return CallNextHookEx(KeyboardHandle, nCode, wParam, lParam)
        End Function
    
        Private Delegate Function KeyboardHookDelegate(Code As Integer, wParam As IntPtr, ByRef lParam As KBDLLHOOKSTRUCT) As Integer
        <MarshalAs(UnmanagedType.FunctionPtr)> _
        Private callback As KeyboardHookDelegate
    
        Public Sub HookKeyboard()
            callback = New KeyboardHookDelegate(AddressOf LowLevelKeyboardProc)
            KeyboardHandle = SetWindowsHookEx(WH_KEYBOARD_LL, callback, Marshal.GetHINSTANCE(Assembly.GetExecutingAssembly().GetModules()(0)), CUInt(0))
            If CInt(KeyboardHandle) = 0 Then
                Throw New Exception("Hook Falhou")
            End If
        End Sub
    
        Public Sub UnhookKeyboard()
            If CInt(KeyboardHandle) <> 0 Then
                UnhookWindowsHookEx(KeyboardHandle)
            End If
        End Sub
    
        Private Sub KeyboardHook_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
            HookKeyboard()
        End Sub

    • Marcado como Resposta Jonnathanvb quarta-feira, 23 de abril de 2014 15:09
    quarta-feira, 23 de abril de 2014 15:09

Todas as Respostas

  • O que que ALT + ESC faz mesmo no Windows?


    Herbert Lausmann

    quinta-feira, 17 de abril de 2014 13:55
  • ele altera para janela seguinte, um pouco parecido com alt + tab, a diferenca e que no alt + esc já muda direto vc não escolhe qual a janela, eu uso windows 7
    quinta-feira, 17 de abril de 2014 14:34
  • ele altera para janela seguinte, um pouco parecido com alt + tab, a diferenca e que no alt + esc já muda direto vc não escolhe qual a janela, eu uso windows 7
    E nesse seu código, as demais combinações tipo ALT + TAB são bloqueadas? Só ALT + ESC que não está sendo bloqueada?

    Herbert Lausmann

    quinta-feira, 17 de abril de 2014 15:03
  • Isso apenas ALT + ESC QUE NÃO ESTA SENDO BLOQUEADA, BEM SE VC SOUBER UM SOLUÇÃO FICO GRATO

    quinta-feira, 17 de abril de 2014 20:57
  • Isso apenas ALT + ESC QUE NÃO ESTA SENDO BLOQUEADA, BEM SE VC SOUBER UM SOLUÇÃO FICO GRATO


    Tem como você postar a fonte onde pegou esse código? Está meio difícil de compreender algumas partes...

    Herbert Lausmann

    sexta-feira, 18 de abril de 2014 14:17
  • Isso apenas ALT + ESC QUE NÃO ESTA SENDO BLOQUEADA, BEM SE VC SOUBER UM SOLUÇÃO FICO GRATO


    Tem como você postar a fonte onde pegou esse código? Está meio difícil de compreender algumas partes...

    Herbert Lausmann

    Aqui esta o codigo completo para bloquear as teclas que eu consegui

    fonte>>>

    http://social.msdn.microsoft.com/Forums/pt-BR/a9aafce8-63bd-4410-a081-d03f8e49d983/bloquear-teclas?forum=vscsharppt

    Imports System.Reflection
    Imports System.Drawing
    Imports System.Runtime.InteropServices
    Imports System.Diagnostics
    
    Public Class KeyboardHook
    	<DllImport("user32.dll")> _
    	Private Shared Function UnhookWindowsHookEx(hhk As IntPtr) As Boolean
    	End Function
    	<DllImport("user32.dll")> _
    	Private Shared Function SetWindowsHookEx(idHook As Integer, lpfn As KeyboardHookDelegate, hMod As IntPtr, dwThreadId As UInteger) As IntPtr
    	End Function
    	<DllImport("user32.dll")> _
    	Private Shared Function GetAsyncKeyState(vKey As Integer) As Short
    	End Function
    	<DllImport("user32.dll")> _
    	Private Shared Function CallNextHookEx(hhk As IntPtr, nCode As Integer, wParam As IntPtr, ByRef lParam As KBDLLHOOKSTRUCT) As Integer
    	End Function
    
    	Private Structure KBDLLHOOKSTRUCT
    		Public vkCode As Integer
    		Public scanCode As Integer
    		Public flags As Integer
    		Public time As Integer
    		Public dwExtraInfo As Integer
    	End Structure
    
    	Private Const HC_ACTION As Integer = &H0
    	Private Const LLKHF_EXTENDED As Integer = &H1
    	Private Const LLKHF_INJECTED As Integer = &H10
    	Private Const LLKHF_ALTDOWN As Integer = &H20
    	Private Const LLKHF_UP As Integer = &H80
    
    	Private Const VK_TAB As Integer = &H9
    	Private Const VK_CONTROL As Integer = &H11
    	Private Const VK_ALT As Integer = &H12
    	Private Const VK_ESCAPE As Integer = &H1b
    	Private Const VK_DELETE As Integer = &H2e
    	Private Const VK_F4 As Integer = &H73
    
    	Private Const WM_KEYDOWN As Integer = &H100
    	Private Const WM_SYSKEYDOWN As Integer = &H104
    	Private Const WM_SYSKEYUP As Integer = &H105
    	Private Const WM_KEYUP As Integer = &H101
    
    	Private Const WH_KEYBOARD_LL As Integer = &Hd
    
    	Private KeyboardHandle As IntPtr
    
    	' Callback
    	Private Function LowLevelKeyboardProc(nCode As Integer, wParam As IntPtr, ByRef lParam As KBDLLHOOKSTRUCT) As Integer
    		If (nCode = HC_ACTION) Then
    			Select Case CInt(wParam)
    				Case WM_KEYDOWN, WM_KEYUP, WM_SYSKEYDOWN, WM_SYSKEYUP
    					' ALT+F4 
    
    					If (lParam.flags And LLKHF_ALTDOWN) <> 0 AndAlso lParam.vkCode = VK_F4 Then
    						Debug.WriteLine("ALT+F4")
    							' engole mensagem
    						Return 1
    					End If
    					' ALT+TAB 
    
    					If (lParam.flags And LLKHF_ALTDOWN) <> 0 AndAlso lParam.vkCode = VK_TAB Then
    						Debug.WriteLine("ALT+TAB")
    						Return 1
    					End If
    					' CTRL+ESC 
    
    					If ((GetAsyncKeyState(VK_CONTROL) And &H8000) <> 0) AndAlso lParam.vkCode = VK_ESCAPE Then
    						Debug.WriteLine("CTRL+ESC")
    						Return 1
    					End If
    					Exit Select
    			End Select
    		End If
    		Return CallNextHookEx(KeyboardHandle, nCode, wParam, lParam)
    	End Function
    
    	Private Delegate Function KeyboardHookDelegate(Code As Integer, wParam As IntPtr, ByRef lParam As KBDLLHOOKSTRUCT) As Integer
    	<MarshalAs(UnmanagedType.FunctionPtr)> _
    	Private callback As KeyboardHookDelegate
    
    	Public Sub HookKeyboard()
    		callback = New KeyboardHookDelegate(AddressOf LowLevelKeyboardProc)
    		KeyboardHandle = SetWindowsHookEx(WH_KEYBOARD_LL, callback, Marshal.GetHINSTANCE(Assembly.GetExecutingAssembly().GetModules()(0)), CUInt(0))
    		If CInt(KeyboardHandle) = 0 Then
    			Throw New Exception("Hook Falhou")
    		End If
    	End Sub
    
    	Public Sub UnhookKeyboard()
    		If CInt(KeyboardHandle) <> 0 Then
    			UnhookWindowsHookEx(KeyboardHandle)
    		End If
    	End Sub
    End Class



    • Editado Jonnathanvb terça-feira, 22 de abril de 2014 16:26 Adicionar informação
    terça-feira, 22 de abril de 2014 16:25
  • Parece que neste artigo há um código que faz este bloqueio:

    C# Disable CTRL-ALT-DEL, ALT-TAB, ALT-F4, Start Menu and so on…

    Está em C#, mas você pode usar este conversor para prosseguir na empreitada:

    Convert C# to VB.NET - A free code conversion tool - developer Fusion


    Herbert Lausmann

    quarta-feira, 23 de abril de 2014 10:49
  • Parece que neste artigo há um código que faz este bloqueio:

    C# Disable CTRL-ALT-DEL, ALT-TAB, ALT-F4, Start Menu and so on…

    Está em C#, mas você pode usar este conversor para prosseguir na empreitada:

    Convert C# to VB.NET - A free code conversion tool - developer Fusion


    Herbert Lausmann

    herbert obrigrado pela ajuda, o poste ajudou eu entender os codigos que eu tinha pego nesse site, já solucionei o problema, vou deixa abaixo o codigo que bloqueia as seguintes tecla ctrl + esc, alt + esc , alt + tab, alt + f4 e tecla windows. 

    para os codigos serem executados com sucesso e nessesario desativar " ENABLE THE VISUAL STUDIO HOSTING PROCESS"

    para localizar essa opção vá em propriedade do projeto > debug > desmaque a opção " ENABLE THE VISUAL STUDIO HOSTING PROCESS"

    Imports System.Reflection
    Imports System.Drawing
    Imports System.Runtime.InteropServices
    Imports System.Diagnostics
    
    Public Class KeyboardHook
        <DllImport("user32.dll")> _
        Private Shared Function UnhookWindowsHookEx(hhk As IntPtr) As Boolean
        End Function
        <DllImport("user32.dll")> _
        Private Shared Function SetWindowsHookEx(idHook As Integer, lpfn As KeyboardHookDelegate, hMod As IntPtr, dwThreadId As UInteger) As IntPtr
        End Function
        <DllImport("user32.dll")> _
        Private Shared Function GetAsyncKeyState(vKey As Integer) As Short
        End Function
        <DllImport("user32.dll")> _
        Private Shared Function CallNextHookEx(hhk As IntPtr, nCode As Integer, wParam As IntPtr, ByRef lParam As KBDLLHOOKSTRUCT) As Integer
        End Function
    
        Private Structure KBDLLHOOKSTRUCT
            Public vkCode As Integer
            Public scanCode As Integer
            Public flags As Integer
            Public time As Integer
            Public dwExtraInfo As Integer
        End Structure
    
        Private Const HC_ACTION As Integer = &H0
        Private Const LLKHF_EXTENDED As Integer = &H1
        Private Const LLKHF_INJECTED As Integer = &H10
        Private Const LLKHF_ALTDOWN As Integer = &H20
        Private Const LLKHF_UP As Integer = &H80
    
        Private Const VK_TAB As Integer = &H9
        Private Const VK_CONTROL As Integer = &H11
        Private Const VK_ALT As Integer = &H12
        Private Const VK_ESCAPE As Integer = &H1B
        Private Const VK_DELETE As Integer = &H2E
        Private Const VK_F4 As Integer = &H73
        Private Const VK_LWIN As Integer = &H5B
        Private Const VK_RWIN As Integer = &H5C
    
        Private Const WM_KEYDOWN As Integer = &H100
        Private Const WM_SYSKEYDOWN As Integer = &H104
        Private Const WM_SYSKEYUP As Integer = &H105
        Private Const WM_KEYUP As Integer = &H101
    
        Private Const WH_KEYBOARD_LL As Integer = &HD
    
        Private KeyboardHandle As IntPtr
    
        ' Callback
        Private Function LowLevelKeyboardProc(nCode As Integer, wParam As IntPtr, ByRef lParam As KBDLLHOOKSTRUCT) As Integer
            If (nCode = HC_ACTION) Then
                Select Case CInt(wParam)
                    Case WM_KEYDOWN, WM_KEYUP, WM_SYSKEYDOWN, WM_SYSKEYUP
                        ' ALT+F4 
    
                        If (lParam.flags And LLKHF_ALTDOWN) <> 0 AndAlso lParam.vkCode = VK_F4 Then
                            Debug.WriteLine("ALT+F4")
                            ' engole mensagem
                            Return 1
                        End If
                        ' ALT+TAB 
    
                        If (lParam.flags And LLKHF_ALTDOWN) <> 0 AndAlso lParam.vkCode = VK_TAB Then
                            Debug.WriteLine("ALT+TAB")
                            Return 1
                        End If
                        ' CTRL+ESC 
    
                        If ((GetAsyncKeyState(VK_CONTROL) And &H8000) <> 0) AndAlso lParam.vkCode = VK_ESCAPE Then
                            Debug.WriteLine("CTRL+ESC")
                            Return 1
                        End If
    
                        ' LWIN - RWIN 
    
                        If lParam.vkCode = VK_LWIN OrElse lParam.vkCode = VK_RWIN Then
                            Debug.WriteLine("LWIN - RWIN")
                            Return 1
                        End If
    
                        'Alt + TAB
                        If (lParam.flags And LLKHF_ALTDOWN) <> 0 AndAlso lParam.vkCode = VK_ESCAPE Then
                            Debug.WriteLine("ALT+TAB")
                            Return 1
                        End If
    
                        Exit Select
                End Select
            End If
            Return CallNextHookEx(KeyboardHandle, nCode, wParam, lParam)
        End Function
    
        Private Delegate Function KeyboardHookDelegate(Code As Integer, wParam As IntPtr, ByRef lParam As KBDLLHOOKSTRUCT) As Integer
        <MarshalAs(UnmanagedType.FunctionPtr)> _
        Private callback As KeyboardHookDelegate
    
        Public Sub HookKeyboard()
            callback = New KeyboardHookDelegate(AddressOf LowLevelKeyboardProc)
            KeyboardHandle = SetWindowsHookEx(WH_KEYBOARD_LL, callback, Marshal.GetHINSTANCE(Assembly.GetExecutingAssembly().GetModules()(0)), CUInt(0))
            If CInt(KeyboardHandle) = 0 Then
                Throw New Exception("Hook Falhou")
            End If
        End Sub
    
        Public Sub UnhookKeyboard()
            If CInt(KeyboardHandle) <> 0 Then
                UnhookWindowsHookEx(KeyboardHandle)
            End If
        End Sub
    
        Private Sub KeyboardHook_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
            HookKeyboard()
        End Sub

    • Marcado como Resposta Jonnathanvb quarta-feira, 23 de abril de 2014 15:09
    quarta-feira, 23 de abril de 2014 15:09