Detect Mouse Cursor Type

Detecting mouse cursor type change over element

Since it may not have been defined inline, you need the computed style:

I use Click here, because it is easier to demo

document.addEventListener('click', e => {
const tgt = e.target;
const inline = tgt.style.cursor || "Not defined"
const computed = window.getComputedStyle(tgt)["cursor"]
console.log("Inline: ",inline,"Computed: ",computed)
});
.help { cursor: help }
<span style="cursor:pointer">Inline Pointer</span>
<hr>
<span class="help">CSS help</span>

The way to detect the current mouse cursor type from bash or python

You can use xdotool to continuously click where the link would be until the program notices the window title changes. When the window title changes, that means the link has been clicked, and the new page is loading.

Clicking function:

ff_window=$(xdotool search --all --onlyvisible --pid "$(pgrep firefox)" --name ".+")

click-at-coords() {
title_before=$(xdotool getwindowname $ff_window)
while true; do
sleep 1
title_now=$(xdotool getwindowname $ff_window)
if [[ $title_now != $title_before]]; then
break
else
xdotool windowfocus --sync "$ff_window" mousemove --sync "$1" "$2" click 1
fi
done
}

Assuming that you're using xdotool to click using coordinates:

# replace each x and y with the coordinates of each link
# example with 2 sets of coordinates: all_coords=("67 129" "811 364")
all_coords=("x y" "x y")

for sub in "${all_coords[@]}"; do
coords=($sub)
click-at-coords "${coords[@]}"
done

get current mouse cursor type

After thee years its time to answer my own question. Here's how you check if the current global cursor is hourglass in C# (extend the code for you own needs if you need):

private static bool IsWaitCursor()
{
var h = Cursors.WaitCursor.Handle;

CURSORINFO pci;
pci.cbSize = Marshal.SizeOf(typeof(CURSORINFO));
if(!GetCursorInfo(out pci))
throw new Win32Exception(Marshal.GetLastWin32Error());

return pci.hCursor == h;
}

[StructLayout(LayoutKind.Sequential)]
struct POINT
{
public Int32 x;
public Int32 y;
}

[StructLayout(LayoutKind.Sequential)]
struct CURSORINFO
{
public Int32 cbSize; // Specifies the size, in bytes, of the structure.
// The caller must set this to Marshal.SizeOf(typeof(CURSORINFO)).
public Int32 flags; // Specifies the cursor state. This parameter can be one of the following values:
// 0 The cursor is hidden.
// CURSOR_SHOWING The cursor is showing.
public IntPtr hCursor; // Handle to the cursor.
public POINT ptScreenPos; // A POINT structure that receives the screen coordinates of the cursor.
}

[DllImport("user32.dll", SetLastError = true)]
static extern bool GetCursorInfo(out CURSORINFO pci);

How to detect the current mouse cursor type using python in linux?

Use this library PyXCursor to get the image of cursor/mouse-pointer for an arbitrary application window in Linux - in Python using ctypes

How to get a Mouse Cursor Type?

Selenium can only query things in your browser, and the cursor display is controlled by your OS.

The best I can suggest would be to check the CSS cursor attribute value using:

function String getElementCursorType(WebElement element) {
return element.getCssValue("cursor");
}

See http://www.w3schools.com/cssref/tryit.asp?filename=trycss_cursor for a list of possible return values and a live demo to see the actual cursor used by your system.



Related Topics



Leave a reply



Submit