簡體   English   中英

檢測鼠標光標是否被任何其他應用程序隱藏或可見

[英]Detect if the mouse cursor is hidden or visible by any other application

我想檢測鼠標當前是否隱藏,這通常是由Windows上的3D應用程序完成的。 這似乎比聽起來更棘手,因為我找不到任何方法來做到這一點。

我希望用Python做這個,但如果不可能,我可以求助於C.謝謝!

GetCursorInfo函數返回CURSORINFO結構,該結構具有包含全局游標狀態的flags字段。 這會做你需要的嗎? 我不熟悉Python,所以我不知道你是否可以從Python調用這個函數。

您需要調用GetCursorInfo函數。 這可以使用pywin32庫直接完成。 或者,如果您不想安裝外部Python庫,則可以使用ctypes模塊直接從User32.dll訪問該函數。

例:

import ctypes

# Argument structures
class POINT(ctypes.Structure):
    _fields_ = [('x', ctypes.c_int),
                ('y', ctypes.c_int)]

class CURSORINFO(ctypes.Structure):
    _fields_ = [('cbSize', ctypes.c_uint),
                ('flags', ctypes.c_uint),
                ('hCursor', ctypes.c_void_p),
                ('ptScreenPos', POINT)]

# Load function from user32.dll and set argument types
GetCursorInfo = ctypes.windll.user32.GetCursorInfo
GetCursorInfo.argtypes = [ctypes.POINTER(CURSORINFO)]

# Initialize the output structure
info = CURSORINFO()
info.cbSize = ctypes.sizeof(info)

# Call it
if GetCursorInfo(ctypes.byref(info)):
    if info.flags & 0x00000001:
        pass  # The cursor is showing
else:
    pass  # Error occurred (invalid structure size?)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM