powershell - CMD 命令(应用程序)更改鼠标灵敏度

标签 powershell cmd server

据我所知,在 cmd/批处理文件中更改鼠标灵敏度是相当困难的(至少我还没有找到正确的方法)。 我尝试添加特定的注册表值并通过重新启动资源管理器进程来重新加载它...但它在系统重新启动之前不起作用。

通过更改 Rundll32 选项,该解决方案似乎更接近。例如:

Rundll32.exe shell32.dll,Control_RunDLL main.cpl @0(或 Rundll32.exe shell32.dll,Control_RunDLL main.cpl,,1) - 显示鼠标设置

Rundll32.exe 用户,setdoubleckilcktime [n] - 更改双击速度

是否有类似的可能性可以改变鼠标光标的灵敏度?

最佳答案

这是使用 Powershell 执行此操作的一种方法。

我在 Windows 10 环境中测试了它,但它应该适用于使用该 API 调用的所有 Windows 版本。 (使用 PS 7.2 和 Windows Powershell 5.1 进行测试)

Function Set-MouseSpeed {
    [CmdletBinding()]
    param (
        [validateRange(1, 20)]
        [int] $Value
    )

    $winApi = add-type -name user32 -namespace tq84 -passThru -memberDefinition '
   [DllImport("user32.dll")]
    public static extern bool SystemParametersInfo(
       uint uiAction,
       uint uiParam ,
       uint pvParam ,
       uint fWinIni
    );
'

    $SPI_SETMOUSESPEED = 0x0071
    $MouseSpeedRegPath = 'hkcu:\Control Panel\Mouse'
    Write-Verbose "MouseSensitivity before WinAPI call:  $((get-itemProperty $MouseSpeedRegPath).MouseSensitivity)"

    $null = $winApi::SystemParametersInfo($SPI_SETMOUSESPEED, 0, $Value, 0)

    #
    #    Calling SystemParametersInfo() does not permanently store the modification
    #    of the mouse speed. It needs to be changed in the registry as well
    #

    set-itemProperty $MouseSpeedRegPath -name MouseSensitivity -value $Value

    Write-Verbose   "MouseSensitivity after WinAPI call:  $((get-itemProperty $MouseSpeedRegPath).MouseSensitivity)"
}

Set-MouseSpeed -Value 16 -Verbose

引用:

renenyffenegger.ch - Powershell: modify the speed of the mouse

关于powershell - CMD 命令(应用程序)更改鼠标灵敏度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71194925/

相关文章:

arrays - 为什么 PowerShell 会自动展平数组?

powershell - 与 Microsoft Azure AD 模块 PowerShell 和 Microsoft Azure Powershell 的不同之处

c# - 如何从 cmd 获取参数到正在运行的 WPF 应用程序

c++ - 如何从 Win32 C++ 应用程序输出到父控制台窗口?

windows - 使用批处理脚本将相同名称的内容连接在一起,然后将每个内容的值求和

powershell - 使用通配符通过 Invoke-WebRequest 下载文件

java - Keycloak 重定向 localhost 而不是重定向远程 url

C HTTP 套接字过早关闭并明显出现读取错误

ubuntu - 在 Linux 服务器上提供 Go API

powershell - 使用 Powershell 访问日志