KVM 客户机 Windows 系统中的光标不随手写板笔尖移动

尝试从 VirtualBox 切换到 QEMU/KVM 的时候发现客户机 Windows 系统中的光标不随手写板笔尖移动。这真是个奇怪的问题。甚至想用 passthrough 来看看会不会好些,最后因为配置 passthrough 太麻烦而放弃了。然后看到一位网友的天才解决办法,就是打开 Windows 中鼠标设置里面的「显示指针轨迹 display pointer trails」,同时将其拖影长度调节到最小。

但是这样设置后有个最大的缺点就是,鼠标移动会有较大的延迟。所以不需要的时候就赶紧关掉比较好。在关掉的情况下,鼠标指针的移动跟在主机里面几乎是没什么差别的。

可以写个简单的 Powershell 脚本来一键启用/禁用「显示鼠标指针轨迹」并同时设定拖影数目。

运行 Powershell 脚本需要首先开启权限(详见微软文档),以管理员身份运行 Powershell,输入 Set-ExecutionPolicy 并回车,然后根据提示,可输入 Unrestricted 后同意,表示开启无限制的脚本运行权限,如下运行结果所示,

Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.

PS C:\Windows\system32> Set-ExecutionPolicy

cmdlet Set-ExecutionPolicy at command pipeline position 1
Supply values for the following parameters:
ExecutionPolicy: Unrestricted

Execution Policy Change
The execution policy helps protect you from scripts that you do not trust. Changing the execution policy might expose
you to the security risks described in the about_Execution_Policies help topic at
https:/go.microsoft.com/fwlink/?LinkID=135170. Do you want to change the execution policy?
[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "N"): y

然后就是 PowerShell 的代码了。假设代码都存放在 C 盘根目录。先来开启指针轨迹的。我给命名为 EnableTrails.ps1 了。

$CSharpSig = @'
[DllImport("user32.dll", EntryPoint = "SystemParametersInfo")]
public static extern bool SystemParametersInfo(
uint uiAction,
uint uiParam,
uint pvParam,
uint fWinIni);
'@

$CursorRefresh = Add-Type -MemberDefinition $CSharpSig -Name WinAPICall -Namespace SystemParamInfo –PassThru

$CursorRefresh::SystemParametersInfo(0x005D,2,$null,$null)

下面是禁用指针轨迹的。我给命名为 DisableTrails.ps1

$CSharpSig = @'
[DllImport("user32.dll", EntryPoint = "SystemParametersInfo")]
public static extern bool SystemParametersInfo(
uint uiAction,
uint uiParam,
uint pvParam,
uint fWinIni);
'@

$CursorRefresh = Add-Type -MemberDefinition $CSharpSig -Name WinAPICall -Namespace SystemParamInfo –PassThru

$CursorRefresh::SystemParametersInfo(0x005D,0,$null,$null)

然后通过批处理文件来执行它们。批处理文件直接存放在桌面上,方便随时双击执行。启用的批处理代码EnableTrails.bat

@echo off
powershell "& ""C:\EnableTrails.ps1"""

用的批处理代码DisableTrails.bat

@echo off
powershell "& ""C:\DisableTrails.ps1"""

当然也可以给这两个批处理文件创建快捷方式并放到开始菜单上。这样不需要显示桌面就能访问到。©

本文发表于水景一页。永久链接:<https://cnzhx.net/blog/cursor-not-following-pen-point-inkvm-guest-windows/>。转载请保留此信息及相应链接。

2 条关于 “KVM 客户机 Windows 系统中的光标不随手写板笔尖移动” 的评论

  1. 引用通告: 上手 Linux 原生的虚拟机工具 QEMU/KVM | 水景一页

  2. 引用通告: 上手 Linux 原生的虚拟机工具 QEMU/KVM | 水景一页

时间过去太久,评论已关闭。
如果您有话要说,请到讨论区留言并给出此文章链接。
谢谢您的理解 :-)