隐藏鼠标
This commit is contained in:
parent
8ea14bbd97
commit
b551fb4f97
42
face_rec.py
42
face_rec.py
@ -22,14 +22,40 @@ from compreface.service import RecognitionService, DetectionService
|
||||
def hide_cursor():
|
||||
"""隐藏鼠标光标(Linux/X11)"""
|
||||
try:
|
||||
import subprocess
|
||||
# 创建空白cursor文件
|
||||
xbm = '/tmp/invisible_cursor.xbm'
|
||||
with open(xbm, 'w') as f:
|
||||
f.write('#define w 1\n#define h 1\n#define hot_x 0\n#define hot_y 0\nstatic char curs[] = {0};')
|
||||
subprocess.run(['xsetroot', '-cursor', xbm, xbm], check=False)
|
||||
except Exception:
|
||||
pass
|
||||
import ctypes
|
||||
from ctypes import cdll, c_char_p, c_void_p, c_int, byref
|
||||
|
||||
libx11 = cdll.LoadLibrary('libX11.so.6')
|
||||
|
||||
# 打开 Display
|
||||
display = libx11.XOpenDisplay(None)
|
||||
if not display:
|
||||
print("Cannot open X display")
|
||||
return
|
||||
|
||||
root = libx11.XDefaultRootWindow(display)
|
||||
|
||||
# 创建空白 bitmap
|
||||
no_data = b'\x00'
|
||||
bitmap = libx11.XCreateBitmapFromData(display, root, no_data, 8, 8)
|
||||
|
||||
# 创建完全透明的光标(前景和背景都是0,即透明)
|
||||
black = c_int(0)
|
||||
invisible_cursor = libx11.XCreatePixmapCursor(display, bitmap, bitmap,
|
||||
byref(black), byref(black), 0, 0)
|
||||
|
||||
# 设置到根窗口
|
||||
libx11.XDefineCursor(display, root, invisible_cursor)
|
||||
libx11.XFlush(display)
|
||||
|
||||
print("Cursor hidden successfully")
|
||||
|
||||
# 清理
|
||||
libx11.XFreeCursor(display, invisible_cursor)
|
||||
libx11.XFreePixmap(display, bitmap)
|
||||
libx11.XCloseDisplay(display)
|
||||
except Exception as e:
|
||||
print(f"Hide cursor error: {e}")
|
||||
|
||||
|
||||
class FaceRecognitionSystem:
|
||||
|
||||
Loading…
Reference in New Issue
Block a user