MCPcopy Create free account
hub / github.com/AutoHotkey/AutoHotkey-v1.0 / ScriptGetCursor

Method ScriptGetCursor

Source/script.cpp:10636–10679  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10634
10635
10636VarSizeType Script::ScriptGetCursor(char *aBuf)
10637// Adapted from the AutoIt3 source.
10638{
10639 if (!aBuf)
10640 return SMALL_STRING_LENGTH; // we're returning the length of the var's contents, not the size.
10641
10642 POINT point;
10643 GetCursorPos(&point);
10644 HWND target_window = WindowFromPoint(point);
10645
10646 // MSDN docs imply that threads must be attached for GetCursor() to work.
10647 // A side-effect of attaching threads or of GetCursor() itself is that mouse double-clicks
10648 // are interfered with, at least if this function is called repeatedly at a high frequency.
10649 ATTACH_THREAD_INPUT
10650 HCURSOR current_cursor = GetCursor();
10651 DETACH_THREAD_INPUT
10652
10653 if (!current_cursor)
10654 {
10655 #define CURSOR_UNKNOWN "Unknown"
10656 strlcpy(aBuf, CURSOR_UNKNOWN, SMALL_STRING_LENGTH + 1);
10657 return (VarSizeType)strlen(aBuf);
10658 }
10659
10660 // Static so that it's initialized on first use (should help performance after the first time):
10661 static HCURSOR cursor[] = {LoadCursor(0,IDC_APPSTARTING), LoadCursor(0,IDC_ARROW), LoadCursor(0,IDC_CROSS)
10662 , LoadCursor(0,IDC_HELP), LoadCursor(0,IDC_IBEAM), LoadCursor(0,IDC_ICON), LoadCursor(0,IDC_NO)
10663 , LoadCursor(0,IDC_SIZE), LoadCursor(0,IDC_SIZEALL), LoadCursor(0,IDC_SIZENESW), LoadCursor(0,IDC_SIZENS)
10664 , LoadCursor(0,IDC_SIZENWSE), LoadCursor(0,IDC_SIZEWE), LoadCursor(0,IDC_UPARROW), LoadCursor(0,IDC_WAIT)};
10665 // The order in the below array must correspond to the order in the above array:
10666 static char *cursor_name[] = {"AppStarting", "Arrow", "Cross"
10667 , "Help", "IBeam", "Icon", "No"
10668 , "Size", "SizeAll", "SizeNESW", "SizeNS" // NESW = NorthEast or SouthWest
10669 , "SizeNWSE", "SizeWE", "UpArrow", "Wait", CURSOR_UNKNOWN}; // The last item is used to mark end-of-array.
10670 static int cursor_count = sizeof(cursor) / sizeof(HCURSOR);
10671
10672 int a;
10673 for (a = 0; a < cursor_count; ++a)
10674 if (cursor[a] == current_cursor)
10675 break;
10676
10677 strlcpy(aBuf, cursor_name[a], SMALL_STRING_LENGTH + 1); // If a is out-of-bounds, "Unknown" will be used.
10678 return (VarSizeType)strlen(aBuf);
10679}
10680
10681
10682

Callers 1

GetMethod · 0.80

Calls 1

strlcpyFunction · 0.85

Tested by

no test coverage detected