DESATIVANDO TECLA F2

XAVIER 13/09/2012 12:06:41
#409577
Olá pessoal !

Me perdoem a insistência.

Encontrei este código aquí, porém estou com uma dúvida:
Onde devo implementar o código para que eu possa cancelar somente a tecla F2 ?

Desde já agradeço.

Eis o código:

[ô]Desabilita Crtl-Esc+Alt-Tab+Alt-Esc- Windows Xp/2000 *

[ô]Coloca isso em um módulo
Option Explicit
Public Declare Sub CopyMemory Lib [Ô]kernel32[Ô] Alias [Ô]RtlMoveMemory[Ô] (Destination As Any, Source As Any, ByVal Length As Long)
Public Declare Function GetKeyState Lib [Ô]user32[Ô] (ByVal nVirtKey As Long) As Integer
Public Declare Function SetWindowsHookEx Lib [Ô]user32[Ô] Alias [Ô]SetWindowsHookExA[Ô] (ByVal idHook As Long, ByVal lpfn As Long, ByVal hmod As Long, ByVal dwThreadId As Long) As Long
Public Declare Function CallNextHookEx Lib [Ô]user32[Ô] (ByVal hHook As Long, ByVal nCode As Long, ByVal wParam As Long, lParam As Any) As Long
Public Declare Function UnhookWindowsHookEx Lib [Ô]user32[Ô] (ByVal hHook As Long) As Long
Public Const HC_ACTION = 0
Public Const WM_KEYDOWN = &H100
Public Const WM_KEYUP = &H101
Public Const WM_SYSKEYDOWN = &H104
Public Const WM_SYSKEYUP = &H105
Public Const VK_TAB = &H9
Public Const VK_ESCAPE = &H1B
Public Const VK_SHIFT = &H10 [ô]Tecla SHIFT
Public Const VK_CONTROL = &H11 [ô]Tecla CTRL
Public Const VK_MENU = &H12 [ô]Tecla ALT
Public Const VK_LWIN = &H5B
Public Const VK_RWIN = &H5C
Public Const VK_APPS = &H5D
Public Const WH_KEYBOARD_LL = 13
Public Const LLKHF_ALTDOWN = &H20
Public Type KBDLLHOOKSTRUCT
vkCode As Long
scanCode As Long
flags As Long
time As Long
dwExtraInfo As Long
End Type
Dim p As KBDLLHOOKSTRUCT
Public Function LowLevelKeyboardProc(ByVal nCode As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Dim fEatKeystroke As Boolean

If (nCode = HC_ACTION) Then
If wParam = WM_KEYDOWN Or wParam = WM_SYSKEYDOWN Or wParam = WM_KEYUP Or wParam = WM_SYSKEYUP Then
CopyMemory p, ByVal lParam, Len(p)
fEatKeystroke = _
p.vkCode = VK_LWIN Or _
p.vkCode = VK_RWIN Or _
p.vkCode = VK_APPS Or _
p.vkCode = VK_CONTROL Or _
p.vkCode = VK_SHIFT Or _
p.vkCode = VK_MENU Or _
((GetKeyState(VK_CONTROL) And &H8000) <> 0) Or _
((p.flags And LLKHF_ALTDOWN) <> 0)
End If
End If

If fEatKeystroke Then
LowLevelKeyboardProc = -1
Else
LowLevelKeyboardProc = CallNextHookEx(0, nCode, wParam, ByVal lParam)
End If
End Function

[ô]Para Usar no seu formulário ou no botão
[ô]
[ô]Desabilita Crtl-Esc+Alt-Tab+Alt-Esc

Option Explicit
Dim hhkLowLevelKybd As Long
Private Sub ChkDesabilita_Click()
If ChkDesabilita = vbChecked Then
hhkLowLevelKybd = SetWindowsHookEx(WH_KEYBOARD_LL, AddressOf LowLevelKeyboardProc, App.hInstance, 0)
Else
UnhookWindowsHookEx hhkLowLevelKybd
hhkLowLevelKybd = 0
End If
End Sub
[ô]Quando vc sair da sua proteção de tela
[ô]
Private Sub Form_Unload(Cancel As Integer)
If hhkLowLevelKybd <> 0 Then UnhookWindowsHookEx hhkLowLevelKybd
End Sub

--------------------
[txt-color=#e80000]Título editado por Jonathan Stecker[/txt-color] - Regras de uso do Fórum. [txt-color=#e80000] [/txt-color]

  • Títulos incorretos
    Por favor não utilize títulos para seu tópico que não ajudem em nada para quem pode te ajudar. Não coloque títulos como
  • [Ô]Help[Ô], [Ô]Socorro[Ô], [Ô]Pelo Amor de DEUS[Ô] pois isto só dificulta as pessoas interessadas em ajudar à olhar seu tópico.
    --------------------
    MARCELO.TREZE 13/09/2012 15:17:31
    #409598
    Resposta escolhida
    só F2?
    XAVIER 13/09/2012 16:01:02
    #409605
    Obrigado MARCELO-TREZE pela atenção.

    Sim. Preciso somente que ao iniciar a aplicação a tecla F2 seja desativada e ao encerrar seja restaurada.
    Um abraço e mais uma vez obrigado.
    MARCELO.TREZE 13/09/2012 16:46:04
    #409610
    Bom Xavier após algumas pesquisas e testes aqui funcionou pra mim da seguinte maneira veja:

    [ô] no módulo cole:


    Public Declare Function SetWindowsHookEx Lib [Ô]user32[Ô] Alias [Ô]SetWindowsHookExA[Ô] (ByVal idHook As Long, ByVal lpfn As Long, ByVal hmod As Long, ByVal dwThreadId As Long) As Long
    Public Declare Function CallNextHookEx Lib [Ô]user32[Ô] (ByVal hHook As Long, ByVal nCode As Long, ByVal wParam As Long, lParam As Any) As Long
    Public Declare Function UnhookWindowsHookEx Lib [Ô]user32[Ô] (ByVal hHook As Long) As Long
    Public Const HC_ACTION = 0
    Public Const WM_KEYDOWN = &H100
    Public Const WM_KEYUP = &H101
    Public Const WM_SYSKEYDOWN = &H104
    Public Const WM_SYSKEYUP = &H105
    Public Const VK_F2 = &H71 [txt-color=#007100][ô] achei o hexadecimal da tecla F2[/txt-color]
    Public Const WH_KEYBOARD_LL = 13
    Public Const LLKHF_ALTDOWN = &H20
    Public Type KBDLLHOOKSTRUCT
    vkCode As Long
    scanCode As Long
    flags As Long
    time As Long
    dwExtraInfo As Long
    End Type
    Dim p As KBDLLHOOKSTRUCT
    Public Function LowLevelKeyboardProc(ByVal nCode As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    Dim fEatKeystroke As Boolean

    If (nCode = HC_ACTION) Then
    If wParam = WM_KEYDOWN Or wParam = WM_SYSKEYDOWN Or wParam = WM_KEYUP Or wParam = WM_SYSKEYUP Then
    CopyMemory p, ByVal lParam, Len(p)
    fEatKeystroke = _
    p.vkCode = VK_F2
    End If
    End If

    If fEatKeystroke Then
    LowLevelKeyboardProc = -1
    Else
    LowLevelKeyboardProc = CallNextHookEx(0, nCode, wParam, ByVal lParam)
    End If
    End Function


    agora no form cole

    Dim hhkLowLevelKybd As Long

    Private Sub Form_Load()
    hhkLowLevelKybd = SetWindowsHookEx(WH_KEYBOARD_LL, AddressOf LowLevelKeyboardProc, App.hInstance, 0)
    End Sub

    Private Sub Form_Unload(Cancel As Integer)
    If hhkLowLevelKybd <> 0 Then UnhookWindowsHookEx hhkLowLevelKybd
    End Sub


    bom faça o teste e tomara que funcione a gosto porque deu um certo trabalho, rs





    JONATHANSTECKER 13/09/2012 16:50:35
    #409612
    Receitinha de bolo... Esse Marcelo é camarada... hehehe
    XAVIER 13/09/2012 16:58:20
    #409615
    Só podia ser o doutor GURU mesmo !!!

    Valeuzaço, MARCELO.

    Com certeza vai funcionar. Se funcionou aí, aquí também vai.
    XAVIER 15/09/2012 12:37:52
    #409741
    Obrigado pessoal !

    Tópico encerrado , respostas não são mais permitidas