Where do I start if I want to program something that can change the configuration of Keyboard/Mouse in Windows?
Configuration as in the options you see in the Keyb开发者_开发知识库oard/Mouse settings under Windows. I have some .NET programming experience.
Win-API is your friend here. Google this API for more information, with this you can retrieve and set a lots of systems parameters about mouse and keyboad:
SystemParametersInfo
The SystemParametersInfo function queries or sets systemwide parameters. This function can also update the user profile while setting a parameter.
Declare Function SystemParametersInfo Lib "user32" Alias "SystemParametersInfoA" (ByVal uAction As Long, ByVal uParam As Long, ByVal lpvParam As Any, ByVal fuWinIni As Long) As Long
If you for example send the uAction SPI_GETKEYBOARDDELAY to the function you will retrieve the keyboard repeat-delay setting. The pvParam parameter must point to an integer variable that receives the setting.
Some other (there are more) intreresting constants are:
GET:
SPI_GETMOUSE, SPI_GETMOUSEHOVERHEIGHT, SPI_GETMOUSEHOVERTIME, SPI_GETMOUSEHOVERWIDTH, SPI_GETMOUSEKEYS, SPI_GETMOUSETRAILS, SPI_GETNONCLIENTMETRICS, SPI_GETSTICKYKEYS, SPI_GETTOGGLEKEYS, SPI_GETWHEELSCROLLLINES
SET:
SPI_SETDOUBLECLICKTIME, SPI_SETDOUBLECLKHEIGHT, SPI_SETDOUBLECLKWIDTH, SPI_SETKEYBOARDDELAY, SPI_SETKEYBOARDPREF, SPI_SETKEYBOARDSPEED, SPI_SETLANGTOGGLE, SPI_SETMOUSE, SPI_SETMOUSEBUTTONSWAP, SPI_SETMOUSEHOVERHEIGHT, SPI_SETMOUSEHOVERTIME, SPI_SETMOUSEHOVERWIDTH, SPI_SETMOUSEKEYS, SPI_SETMOUSETRAILS
If you only wanted it to affect your own process you could use the InputLanguage class to change keyboard layout, but if I understand correctly you want to change the system wide settings?
As Stuart says, you're not really supposed to do this from an app so I don't think there's any "supported" way of doing it. However, I think all these settings are stored in the registry so you could probably do it by changing those settings and rebooting the PC.
Here's some links that might be worth looking at for changing the Keyboard layout:
Keyboard layout code
How do I configure the default keyboard layout during login?
Both those links are quite old but I think that it's likely that the same settings are still used.
If you want to change other keyboard settings than the layout, or if you want to change mouse settings, you could try googling for the name of the setting + "registry key" or something similar to find where it's stored, or maybe ask on the Superuser site.
精彩评论