gpt4 book ai didi

c# - 使用 C# 从 Windows 8 读取惯用手设置

转载 作者:可可西里 更新时间:2023-11-01 09:58:22 27 4
gpt4 key购买 nike

在 Windows 8 上,我正在尝试使用 C# 确定鼠标的惯用手习惯。换句话说,我正在尝试读取此设置:

Control Panel\Hardware and Sound\Mouse -> Switch primary and secondary buttons.

我试过使用 WMI,但没有成功。无论我使用什么鼠标,惯用手属性值始终为 null。

SelectQuery selectQuery = new SelectQuery("Win32_PointingDevice");
ManagementObjectSearcher searcher = new ManagementObjectSearcher(selectQuery);

foreach (var mouse in searcher.Get())
{
foreach (var property in mouse.Properties)
{
Console.WriteLine("{0}: {1}", property.Name, property.Value);
}
}

还有其他方法可以完成这个任务吗?

最佳答案

我发现在 user32.dll 上公开的 GetSystemMetrics 可用于返回您寻找的交换鼠标按钮数据。这里有一些引用资料和一个用于测试的快速控制台应用程序。第三个链接包含更多关于如何将 GetSystemMetrics 与 C# 结合使用的“官方”示例。

GetSystemMetrics

Wrong way to detect swapped mouse

Reference for constants, etc

using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
namespace ConsoleApplication2
{

class Program
{
[DllImport("user32.dll")]
public static extern Int32 GetSystemMetrics(Int32 bSwap);

static void Main(string[] args)
{
//normally you would make this as a constant:
int SM_SWAPBUTTON = 23;

int isLeftHanded = GetSystemMetrics(SM_SWAPBUTTON);
//0 means not swapped, 1 means swapped (left handedness?)

}
}
}

关于c# - 使用 C# 从 Windows 8 读取惯用手设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34997186/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com