none
Macro para Mover o Mouse RRS feed

  • Pergunta

  • Olá, gostaria de saber se tem como criar uma macro para mover o mouse, com o objetivo da implementação da automação em sistemas web
    quarta-feira, 29 de julho de 2015 16:16

Respostas

  • Utilize a API SetCursorPos para alterar a posição do cursor na tela. Você define a nova posição em coordenadas(x e y):

    Private Declare PtrSafe Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long
    
    SetCursorPos 80, 50 'Chamada da função

    Para simular um click você pode utilizar a função mouse_event:

    Private Declare PtrSafe 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_LEFTDOWN = &H2
    Private Const MOUSEEVENTF_LEFTUP = &H4
    Private Const MOUSEEVENTF_RIGHTDOWN As Long = &H8
    Private Const MOUSEEVENTF_RIGHTUP As Long = &H10
    
        'Clique botão esquerdo
        mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0
        mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
      
        'Duplo clique botão esquerdo
        mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0
        mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
        mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0
        mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
      
        'Clique botão direito
        mouse_event MOUSEEVENTF_RIGHTDOWN, 0, 0, 0, 0
        mouse_event MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0
    

    quarta-feira, 29 de julho de 2015 17:20

Todas as Respostas

  • Utilize a API SetCursorPos para alterar a posição do cursor na tela. Você define a nova posição em coordenadas(x e y):

    Private Declare PtrSafe Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long
    
    SetCursorPos 80, 50 'Chamada da função

    Para simular um click você pode utilizar a função mouse_event:

    Private Declare PtrSafe 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_LEFTDOWN = &H2
    Private Const MOUSEEVENTF_LEFTUP = &H4
    Private Const MOUSEEVENTF_RIGHTDOWN As Long = &H8
    Private Const MOUSEEVENTF_RIGHTUP As Long = &H10
    
        'Clique botão esquerdo
        mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0
        mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
      
        'Duplo clique botão esquerdo
        mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0
        mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
        mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0
        mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
      
        'Clique botão direito
        mouse_event MOUSEEVENTF_RIGHTDOWN, 0, 0, 0, 0
        mouse_event MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0
    

    quarta-feira, 29 de julho de 2015 17:20
  • Muito obrigado, resolveu o meu problema
    quarta-feira, 29 de julho de 2015 21:46