如何获取光标的状态? [英] How to get the state of the cursor?
本文介绍了如何获取光标的状态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道 Python 3.8 中是否有任何方法可以读取游标类型,例如 win32gui
如何使用 win32gui.GetCursorInfo()
,找到光标.以下是我所说的光标状态:
I was wondering if there was any way in Python 3.8 to read the cursor type like how win32gui
could do with win32gui.GetCursorInfo()
, Finding the id of the cursor. Below is what I mean by cursor state:
推荐答案
请在下面找到代码.
参考:https://www.iditect.com/how-to/10284849.html,但我稍微修改了一下:
reference: https://www.iditect.com/how-to/10284849.html, but I modified it a little bit:
from win32con import IDC_APPSTARTING, IDC_ARROW, IDC_CROSS, IDC_HAND, \
IDC_HELP, IDC_IBEAM, IDC_ICON, IDC_NO, IDC_SIZE, IDC_SIZEALL, \
IDC_SIZENESW, IDC_SIZENS, IDC_SIZENWSE, IDC_SIZEWE, IDC_UPARROW, IDC_WAIT
from win32gui import LoadCursor, GetCursorInfo
def get_current_cursor():
curr_cursor_handle = GetCursorInfo()[1]
return Cursor.from_handle(curr_cursor_handle)
class Cursor(object):
@classmethod
def from_handle(cls, handle):
for cursor in DEFAULT_CURSORS:
if cursor[1].handle == handle:
return cursor[0] #DEFAULT_CURSORS.index(cursor) , Cursor.__init__
return cls(handle=handle)
def __init__(self, cursor_type=None, handle=None):
if handle is None:
handle = LoadCursor(0, cursor_type)
self.type = cursor_type
self.handle = handle
DEFAULT_CURSORS = (('APPSTARTING',Cursor(IDC_APPSTARTING)), ('ARROW',Cursor(IDC_ARROW)), ('CROSS',Cursor(IDC_CROSS)), ('HAND',Cursor(IDC_HAND)), \
('HELP',Cursor(IDC_HELP)), ('IBEAM',Cursor(IDC_IBEAM)), ('ICON',Cursor(IDC_ICON)), ('NO',Cursor(IDC_NO)), ('SIZE',Cursor(IDC_SIZE)),\
('SIZEALL', Cursor(IDC_SIZEALL)),('SIZENESW', Cursor(IDC_SIZENESW)), ('SIZENS',Cursor(IDC_SIZENS)), ('SIZENWSE',Cursor(IDC_SIZENWSE)),\
('SIZEWE', Cursor(IDC_SIZEWE)), ('UPARROW', Cursor(IDC_UPARROW)), ('WAIT',Cursor(IDC_WAIT)))
while(True):
print(get_current_cursor())
这篇关于如何获取光标的状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文