我在我的4K屏幕上喜欢增大Windows中的鼠标指针大小。
这对95%的使用非常有用,但是有时候需要小一点的鼠标指针进行更精细的工作。
由于我不想每次都打开设置,所以我需要一个可以用来切换大鼠标和小鼠标的快捷键。
因此,我编写了以下内容,希望它能起到作用:
- 更新注册表以设置新的鼠标大小
- 使用参数
SPI_SETCURSORS
调用SystemParametersInfo()
函数,以促使系统重新读取鼠标设置。
然而,没有成功。
是否有人能够指出我的错误之处?
感谢, Dave
下面是代码:
param([int]$MouseSize=0)
###########################################
#
# DISAPPOINTINGLY THIS DOES NOT YET WORK
# Need to figure out why
#
###########################################
##################
# Constants
##################
[int]$small_mouse = 48
[int]$big_mouse = 80
[int]$min_mouse = 1
[int]$max_mouse = 256
[string]$path = 'HKCU:\Control Panel\Cursors'
[string]$name = 'CursorBaseSize'
##################
# API Import
##################
Try{
[void][SysParams]
} Catch {
Add-Type @'
using System;
using System.Runtime.InteropServices;
public class SysParams {
[DllImport("user32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
internal static extern bool SystemParametersInfo(uint uiAction, uint uiParam, uint pvParam, uint fWinIni);
public static bool RefreshCursor()
{
return SystemParametersInfo(0x0057, 0, 0, 0); // SPI_SETCURSORS = 0x0057;
}
}
'@
}
##################
# Main
##################
# Is $MouseSize passed in valid?
if ($MouseSize -ge $min_mouse -and $MouseSize -le $max_mouse) {
$new_size = $MouseSize
} else {
# If invalid $MouseSize passed in, toggle current mouse setting
# First determine if current setting closer to $small_mouse or $big_mouse
$current_size = (Get-ItemProperty $path).$name
$diff_small = [math]::Abs($current_size - $small_mouse)
$diff_big = [math]::Abs($current_size - $big_mouse)
if ($diff_small -lt $diff_big) {
$new_size = $big_mouse # Mouse is small, so toggle big
} else {
$new_size = $small_mouse # Mouse is big, so toggle small
}
}
Set-ItemProperty -Path $path -Name $name -Value $new_size
$resp = [SysParams]::RefreshCursor()
SystemParametersInfo
调用不起作用? - zett42SystemParametersInfo
的互操作代码没有执行它应该执行的操作。我尝试了几个其他签名,但到目前为止都没有运气。还添加了SPIF_UPDATEINIFILE
和SPIF_SENDWININICHANGE
标志,但仍然无法工作。 - zett42pvParam
)设置为null
而不是0
?来自文档 除非另有说明,否则必须将此参数指定为NULL。 - Theo