Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get cursor state in Excel VBA 2013

Tags:

excel

vba

I created a macro to do a series of mouse clicks and mouse moves (keystroke macro) to enter repetitive data into Oracle (Program/database).

I used Dataload Classic or Dataloader Classic (keystroke program) to enter data into Oracle before but it lacked the "Smarts", so I created my own keystroke program with some "Smarts".

I am using the SLEEP command/function to wait a couple of seconds/milliseconds after every mouse move and mouse click. Sometimes Oracle would be slow and "pause"/"load"/or "freeze up" and the freezing time might exceed the SLEEP command initial wait time and continue on with the program, thus messing everything up.

example:

if something_happens then
sleep 2000
end if

In DataLoad classic/Dataloader Classic there are options to change how long you can wait/pause for every mouse click or mouse move, etc. There is an "HOURGLASS CHECK". This says you may set a time for the program to wait if the mouse is in the hourglass state and the user may enter millisecond or seconds.

Is there Excel VBA code to check the HOURGLASS state of the mouse?

like image 770
Proggie Avatar asked Jan 20 '26 05:01

Proggie


1 Answers

You could try the following function which uses win api functions LoadCursor and GetCursorInfo to determine if the current cursor equals to wait cursor.

The function first loads the win-predefined wait cursor then gets current cursor and checks if they are the same. HTH

Option Explicit

Private Const IDC_WAIT As Long = 32514

Private Type POINT
    x As Long
    y As Long
End Type

Private Type CURSORINFO
    cbSize As Long
    flags As Long
    hCursor As Long
    ptScreenPos As POINT
End Type

Private Declare Function GetCursorInfo _
    Lib "user32" (ByRef pci As CURSORINFO) As Boolean
Private Declare Function LoadCursor _
    Lib "user32" Alias "LoadCursorA" _
    (ByVal hInstance As Long, ByVal lpCursorName As Long) As Long

Public Function IsWaitCursor() As Boolean

    ' Get handle to wait cursor
    Dim handleWaitCursor As Long
    handleWaitCursor = LoadCursor(ByVal 0&, IDC_WAIT)

    Dim pci As CURSORINFO
    pci.cbSize = Len(pci)

    ' Retrieve information about the current cursor
    Dim ret As Boolean
    ret = GetCursorInfo(pci)

    If ret = False Then
        MsgBox "GetCursorInfo failed", vbCritical
        Exit Function
    End If

    ' Returns true when current cursor equals to wait cursor
    IsWaitCursor = (pci.hCursor = handleWaitCursor)

End Function
like image 140
Daniel Dušek Avatar answered Jan 22 '26 22:01

Daniel Dušek