USUÁRIO:      SENHA:        SALVAR LOGIN ?    Adicione o VBWEB na sua lista de favoritos   Fale conosco 

 

  Dicas

  Visual Basic    (Mouse/Teclado)

Título da Dica:  Bloquear clique do botão direito do Mouse
Postada em 16/4/2004 por David Pomarico      Clique aqui para enviar email para o autor  dcpomarico@yahoo.com.br
Em General do form inclua:
==========================
' << Bloquear botão direito do mouse >>
' reconhece qual botão foi clicado e seu estado Down ou UP
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer

' checa posição mouse e gera um clique/eventos no mouse
Private Declare Function GetCursorPos Lib _
      "user32" (lpPoint As POINTAPI) As Long
Private Declare Function ClientToScreen Lib _
      "user32" (ByVal hwnd As Long, lpPoint As POINTAPI) As Long
Private Declare Sub mouse_event Lib "user32" _
      (ByVal dwFlags As Long, ByVal dx As Long, _
      ByVal dy As Long, ByVal cButtons As Long, _
      ByVal dwExtraInfo As Long)


Private Const MOUSEEVENTF_MOVE = &H1          ' mouse move
Private Const MOUSEEVENTF_LEFTDOWN = &H2      ' left button down
Private Const MOUSEEVENTF_LEFTUP = &H4        ' left button up
Private Const MOUSEEVENTF_RIGHTDOWN = &H8     ' right button down
Private Const MOUSEEVENTF_RIGHTUP = &H10      ' right button up
Private Const MOUSEEVENTF_MIDDLEDOWN = &H20   ' middle button down
Private Const MOUSEEVENTF_MIDDLEUP = &H40     ' middle button up
Private Const MOUSEEVENTF_WHEEL = &H800       ' wheel button rolled
Private Const MOUSEEVENTF_ABSOLUTE = &H8000   ' absolute move

Private Type POINTAPI
    X As Long
    Y As Long
End Type

Dim pt As POINTAPI
Dim pts As POINTAPI
Dim cur_x As Single
Dim cur_y As Single
Dim dest_x As Single
Dim dest_y As Single
'FIM General form


'INCLUA UM TIMER NO FORM COM INTERVALO = 1

Private Sub Timer1_Timer()

    If GetAsyncKeyState(2) = 0 Then
        ' clicou botão esquerdo e não faz nada
    Else
        ' clicou botão direito
        ' Things are easier working in pixels.
        Me.ScaleMode = vbPixels
    
        ' mouse_event moves in a coordinate system where
        ' (0, 0) is in the upper left corner and
        ' (65535,65535) is in the lower right corner.
    
        ' Get the current mouse coordinates and convert them into this new
        ' system.GetCursorPos pt
        cur_x = pt.X * 65535 / ScaleX(Screen.Width, vbTwips, vbPixels)
        cur_y = pt.Y * 65535 / ScaleY(Screen.Height, vbTwips, vbPixels)
        
        ' Salva as coordenadas do mouse (NOVO)
        pts.X = cur_x
        pts.Y = cur_y

        ' Convert the coordinates of the center of the form into this new
        ' system.
        pt.X = Me.ScaleLeft
        pt.Y = Me.ScaleTop
        'pt.X = Me.ScaleWidth / 2
        'pt.Y = Me.ScaleHeight / 2
        ClientToScreen Me.hwnd, pt
        dest_x = pt.X * 65535 / ScaleX(Screen.Width, vbTwips, vbPixels)
        dest_y = pt.Y * 65535 / ScaleY(Screen.Height, vbTwips, vbPixels)
    
        ' Move the mouse to its final destination and click it.
        mouse_event _
            MOUSEEVENTF_ABSOLUTE + _
            MOUSEEVENTF_MOVE + _
            MOUSEEVENTF_LEFTDOWN + _
            MOUSEEVENTF_LEFTUP, _
            dest_x, dest_y, 0, 0
            
        ' move o mouse para a posição inicial (NOVO)
        mouse_event _
                MOUSEEVENTF_ABSOLUTE + _
                MOUSEEVENTF_MOVE, _
                pts.X, pts.Y, 0, 0
    End If
End Sub
 


CyberWEB Network Ltda.    © Copyright 2000-2024   -   Todos os direitos reservados.
Powered by HostingZone - A melhor hospedagem para seu site
Topo da página