定时更换鼠标光标的脚本

wen 实用脚本 1

本文目录导读:

定时更换鼠标光标的脚本

  1. 方案一:Windows AutoHotkey 脚本
  2. 方案二:Python 版本(跨平台)
  3. 方案三:批处理版本(Windows)
  4. 使用说明
  5. 注意事项

我来为你创建一个定时更换鼠标光标的脚本,实现自动轮换不同的光标样式。

Windows AutoHotkey 脚本

#Persistent
#SingleInstance Force
; ============================================
; 定时更换鼠标光标脚本
; ============================================
; 定义光标样式数组 (使用系统光标ID)
; 32512 = 标准箭头, 32513 = 帮助, 32514 = 后台
; 32515 = 等待, 32516 = 十字, 32517 = 手型
cursorStyles := [32512, 32513, 32514, 32515, 32516, 32517]
cursorNames := ["箭头", "帮助", "后台", "等待", "十字", "手型"]
; 当前索引
currentIndex := 1
; 更换间隔(秒)
changeInterval := 10
; 创建菜单
TrayMenu := Menu()
TrayMenu.Add("立即更换", "ChangeNow")
TrayMenu.Add("更换间隔: 5秒", "Set5s")
TrayMenu.Add("更换间隔: 10秒", "Set10s")
TrayMenu.Add("更换间隔: 30秒", "Set30s")
TrayMenu.Add("更换间隔: 60秒", "Set60s")
TrayMenu.Add()
TrayMenu.Add("退出", "ExitApp")
A_IconTip := "鼠标光标自动更换器"
A_IconMenu := TrayMenu
; 启动定时器
SetTimer ChangeCursor, % changeInterval * 1000
; 显示开始信息
ToolTip "光标自动更换已开始 (每 " changeInterval " 秒更换一次)"
SetTimer RemoveToolTip, -2000
return
; ============================================
; 更换光标函数
; ============================================
ChangeCursor() {
    global currentIndex, cursorStyles, cursorNames
    ; 获取当前光标样式
    cursorPath := "cursors\"
    ; 设置系统光标
    DllCall("SystemParametersInfo", "UInt", 0x0057, "UInt", 0, "Ptr", cursorStyles[currentIndex], "UInt", 0)
    ; 显示当前状态
    ToolTip "当前光标: " cursorNames[currentIndex]
    SetTimer RemoveToolTip, -1500
    ; 更新索引
    currentIndex++
    if (currentIndex > cursorStyles.Length) {
        currentIndex := 1
    }
}
; 立即更换
ChangeNow() {
    ChangeCursor()
}
; 设置间隔
Set5s() {
    global changeInterval
    changeInterval := 5
    SetTimer ChangeCursor, 5000
    ToolTip "更换间隔已设为 5 秒"
    SetTimer RemoveToolTip, -2000
}
Set10s() {
    global changeInterval
    changeInterval := 10
    SetTimer ChangeCursor, 10000
    ToolTip "更换间隔已设为 10 秒"
    SetTimer RemoveToolTip, -2000
}
Set30s() {
    global changeInterval
    changeInterval := 30
    SetTimer ChangeCursor, 30000
    ToolTip "更换间隔已设为 30 秒"
    SetTimer RemoveToolTip, -2000
}
Set60s() {
    global changeInterval
    changeInterval := 60
    SetTimer ChangeCursor, 60000
    ToolTip "更换间隔已设为 60 秒"
    SetTimer RemoveToolTip, -2000
}
; 移除提示
RemoveToolTip() {
    ToolTip
}
; 退出
ExitApp():
ExitApp

Python 版本(跨平台)

import ctypes
import time
import threading
import sys
import os
class CursorChanger:
    def __init__(self, interval=10):
        """
        初始化光标更换器
        :param interval: 更换间隔(秒)
        """
        self.interval = interval
        self.running = False
        self.current_cursor = 0
        # Windows系统光标ID
        self.cursor_styles = [
            (32512, "标准箭头"),  # IDC_ARROW
            (32513, "帮助选择"),  # IDC_HELP
            (32514, "后台运行"),  # IDC_APPSTARTING
            (32515, "等待"),      # IDC_WAIT
            (32516, "十字"),      # IDC_CROSS
            (32517, "手型"),      # IDC_HAND
            (32518, "垂直调整"),  # IDC_SIZENS
            (32519, "水平调整"),  # IDC_SIZEWE
        ]
    def set_cursor(self, cursor_id):
        """设置系统光标"""
        try:
            # 使用SystemParametersInfo API
            result = ctypes.windll.user32.SystemParametersInfoW(
                0x0057,  # SPI_SETCURSORS
                0,       # 不设置参数
                None,    # 不使用指针
                0        # 不更新配置
            )
            # 获取当前光标句柄
            cursor_handle = ctypes.windll.user32.LoadCursorW(
                None, 
                cursor_id
            )
            if cursor_handle:
                # 设置当前光标
                ctypes.windll.user32.SetSystemCursor(
                    cursor_handle,
                    32512  # OCR_NORMAL
                )
                print(f"已更换光标为: {self.cursor_styles[self.current_cursor][1]}")
                return True
            return False
        except Exception as e:
            print(f"设置光标失败: {e}")
            return False
    def change_cursor(self):
        """更换光标"""
        cursor_id, name = self.cursor_styles[self.current_cursor]
        print(f"更换光标: {name} (ID: {cursor_id})")
        self.set_cursor(cursor_id)
        # 更新索引
        self.current_cursor += 1
        if self.current_cursor >= len(self.cursor_styles):
            self.current_cursor = 0
    def run(self):
        """运行定时更换"""
        print(f"光标更换器启动 - 每 {self.interval} 秒更换一次")
        print("按 Ctrl+C 停止")
        self.running = True
        try:
            while self.running:
                self.change_cursor()
                time.sleep(self.interval)
        except KeyboardInterrupt:
            print("\n停止光标更换")
        finally:
            self.running = False
            # 恢复默认光标
            self.restore_default_cursor()
    def restore_default_cursor(self):
        """恢复默认光标"""
        try:
            ctypes.windll.user32.SystemParametersInfoW(
                0x0057,  # SPI_SETCURSORS
                0,
                None,
                0
            )
            print("已恢复默认光标")
        except:
            pass
    def set_interval(self, new_interval):
        """修改更换间隔"""
        self.interval = new_interval
        print(f"更换间隔已改为: {new_interval} 秒")
    def get_cursor_list(self):
        """显示所有可用光标"""
        print("\n可用光标样式:")
        for i, (cursor_id, name) in enumerate(self.cursor_styles, 1):
            print(f"{i}. {name} (ID: {cursor_id})")
def main():
    # 检查是否为Windows系统
    if sys.platform != 'win32':
        print("此脚本仅支持Windows系统")
        return
    # 创建实例,默认10秒间隔
    changer = CursorChanger(interval=10)
    # 显示光标列表
    changer.get_cursor_list()
    # 尝试从命令行参数读取间隔
    if len(sys.argv) > 1:
        try:
            interval = float(sys.argv[1])
            changer.set_interval(interval)
        except:
            pass
    # 启动
    changer.run()
if __name__ == "__main__":
    main()

批处理版本(Windows)

@echo off
setlocal enabledelayedexpansion
定时更换鼠标光标
echo ========================================
echo     定时更换鼠标光标脚本
echo ========================================
echo.
REM 设置默认间隔(秒)
set interval=10
echo 请选择功能:
echo 1. 启动定时更换(每10秒)
echo 2. 自定义间隔时间
echo 3. 退出
echo.
set /p choice=请选择(1-3): 
if "%choice%"=="1" (
    goto start
) else if "%choice%"=="2" (
    set /p interval=请输入更换间隔(秒): 
    goto start
) else if "%choice%"=="3" (
    exit
) else (
    echo 无效选择
    timeout /t 2 >nul
    exit
)
:start
echo.
echo 光标更换已启动,每 %interval% 秒更换一次
echo 按任意键停止...
echo.
set count=1
:loop
if %count% gtr 6 set count=1
REM 根据计数器更换光标
if %count%==1 (
    echo [%time%] 光标: 标准箭头
) else if %count%==2 (
    echo [%time%] 光标: 帮助选择
) else if %count%==3 (
    echo [%time%] 光标: 后台运行
) else if %count%==4 (
    echo [%time%] 光标: 等待
) else if %count%==5 (
    echo [%time%] 光标: 十字
) else (
    echo [%time%] 光标: 手型
)
set /a count+=1
timeout /t %interval% /nobreak >nul
REM 检查是否有按键
if errorlevel 1 (
    echo.
    echo 程序结束
    exit
)
goto loop

使用说明

AHK版本(推荐)

  1. 安装 AutoHotkey
  2. 保存为 .ahk 文件并双击运行
  3. 在系统托盘会出现图标,右键可控制

Python版本

  1. 确保Python已安装
  2. 运行:python cursor_changer.py 5 (5表示5秒换一次)
  3. 按 Ctrl+C 停止

批处理版本

  1. 保存为 .bat 文件
  2. 双击运行即可

注意事项

  • 需要管理员权限运行
  • 在某些系统上可能需要调整兼容性设置
  • 建议在测试环境中先运行

希望这个脚本对你有帮助!如果需要调整或添加其他功能,请告诉我。

抱歉,评论功能暂时关闭!