Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "MouseMirror" project for mirroring mouse movement #49

Merged
merged 10 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions IntelliMouse.sln
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TailLight", "TailLight\Tail
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "flicker", "flicker\flicker.vcxproj", "{BB81C655-EEF5-434F-BB2A-4B8D1358ECE4}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MouseMirror", "MouseMirror\MouseMirror.vcxproj", "{42A4140E-4EF5-4502-BE9F-A33D6C0FC5E7}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Expand All @@ -29,6 +31,12 @@ Global
{BB81C655-EEF5-434F-BB2A-4B8D1358ECE4}.Debug|x64.Build.0 = Debug|x64
{BB81C655-EEF5-434F-BB2A-4B8D1358ECE4}.Release|x64.ActiveCfg = Release|x64
{BB81C655-EEF5-434F-BB2A-4B8D1358ECE4}.Release|x64.Build.0 = Release|x64
{42A4140E-4EF5-4502-BE9F-A33D6C0FC5E7}.Debug|x64.ActiveCfg = Debug|x64
{42A4140E-4EF5-4502-BE9F-A33D6C0FC5E7}.Debug|x64.Build.0 = Debug|x64
{42A4140E-4EF5-4502-BE9F-A33D6C0FC5E7}.Debug|x64.Deploy.0 = Debug|x64
{42A4140E-4EF5-4502-BE9F-A33D6C0FC5E7}.Release|x64.ActiveCfg = Release|x64
{42A4140E-4EF5-4502-BE9F-A33D6C0FC5E7}.Release|x64.Build.0 = Release|x64
{42A4140E-4EF5-4502-BE9F-A33D6C0FC5E7}.Release|x64.Deploy.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
17 changes: 17 additions & 0 deletions MouseMirror.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Get IntelliMouse WMI object
# HW drivers reside in the "root\wmi" namespace (https://learn.microsoft.com/en-us/windows/win32/wmicoreprov/wdm-provider)
$mouse = Get-CimInstance -Namespace root\WMI -Class MouseMirrorDeviceInformation

Write-Host("IntelliMouse device:")

Write-Host(" InstanceName: {0}" -f $mouse.InstanceName)

# check if mouse is active
Write-Host(" Active: {0}" -f $mouse.Active)

Write-Host("Enabling mirroring of mouse movement...")
$mouse.FlipLeftRight = $true
$mouse.FlipUpDown = $true

Write-Host("Storing changes...")
Set-CimInstance -CimInstance $mouse
1 change: 1 addition & 0 deletions MouseMirror/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/x64
12 changes: 12 additions & 0 deletions MouseMirror/INSTALL_MouseMirror.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
@echo off
:: Goto current directory
cd /d "%~dp0"

:: Use DevCon for installation, since it allows providing HWID
devcon /r install MouseMirror.inf "HID\VID_045E&PID_082A&MI_00&Col01"

:: Use PnpUtil for installation (succeeds but driver isn't loaded)
::devgen /add /bus ROOT /hardwareid "HID\VID_045E&PID_082A&MI_00&Col01"
::PNPUTIL /add-driver MouseMirror.inf /install /reboot

pause
1 change: 1 addition & 0 deletions MouseMirror/MouseMirror.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#pragma once
Binary file added MouseMirror/MouseMirror.inx
Binary file not shown.
24 changes: 24 additions & 0 deletions MouseMirror/MouseMirror.mof
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#PRAGMA AUTORECOVER

// Documentation resources:
// https://learn.microsoft.com/en-us/windows/win32/wmisdk/mof-data-types
// https://learn.microsoft.com/en-us/windows-hardware/drivers/kernel/wmi-class-qualifiers
// https://learn.microsoft.com/en-us/windows-hardware/drivers/kernel/wmi-property-qualifiers


[Dynamic, Provider("WMIProv"), WMI,
Description("MouseMirror driver information"),
guid("{97754ED3-63DF-485E-A7B9-E4BDD92C8BF3}")]
class MouseMirrorDeviceInformation {
[key, read]
string InstanceName;

[read]
boolean Active;

[WmiDataId(1), read, write, Description("Horizontal mirroring of mouse cursor movement")]
boolean FlipLeftRight;

[WmiDataId(2), read, write, Description("Vertical mirroring of mouse cursor movement")]
boolean FlipUpDown;
};
123 changes: 123 additions & 0 deletions MouseMirror/MouseMirror.vcxproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{42A4140E-4EF5-4502-BE9F-A33D6C0FC5E7}</ProjectGuid>
<RootNamespace>$(MSBuildProjectName)</RootNamespace>
<KMDF_VERSION_MAJOR>1</KMDF_VERSION_MAJOR>
<Configuration Condition="'$(Configuration)' == ''">Debug</Configuration>
<Platform Condition="'$(Platform)' == ''">Win32</Platform>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Label="Configuration" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<TargetVersion>Windows10</TargetVersion>
<UseDebugLibraries>False</UseDebugLibraries>
<DriverTargetPlatform>Universal</DriverTargetPlatform>
<DriverType>KMDF</DriverType>
<PlatformToolset>WindowsKernelModeDriver10.0</PlatformToolset>
<ConfigurationType>Driver</ConfigurationType>
</PropertyGroup>
<PropertyGroup Label="Configuration" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<TargetVersion>Windows10</TargetVersion>
<UseDebugLibraries>True</UseDebugLibraries>
<DriverTargetPlatform>Universal</DriverTargetPlatform>
<DriverType>KMDF</DriverType>
<PlatformToolset>WindowsKernelModeDriver10.0</PlatformToolset>
<ConfigurationType>Driver</ConfigurationType>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" />
</ImportGroup>
<ItemGroup>
<MofComp Include="MouseMirror.mof">
<CreateBinaryMofFile>"$(IntDir)\MouseMirror.bmf"</CreateBinaryMofFile>
</MofComp>
<Wmimofck Include="$(IntDir)\MouseMirror.bmf">
<HeaderOutputFile>$(IntDir)\MouseMirrormof.h</HeaderOutputFile>
</Wmimofck>
</ItemGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Inf2CatUseLocalTime>true</Inf2CatUseLocalTime>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Inf2CatUseLocalTime>true</Inf2CatUseLocalTime>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Link>
<AdditionalDependencies>%(AdditionalDependencies);$(DDK_LIB_PATH)\hidparse.lib</AdditionalDependencies>
</Link>
<ClCompile>
<PreprocessorDefinitions>%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ExceptionHandling>
</ExceptionHandling>
</ClCompile>
<Midl>
<PreprocessorDefinitions>%(PreprocessorDefinitions)</PreprocessorDefinitions>
</Midl>
<ResourceCompile>
<PreprocessorDefinitions>%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ResourceCompile>
<DriverSign>
<FileDigestAlgorithm>sha256</FileDigestAlgorithm>
</DriverSign>
<PostBuildEvent>
<Command>copy *.bat $(PackageDir)
copy "C:\Program Files (x86)\Windows Kits\10\tools\$(WDKBuildFolder)\x64\dev*.exe" $(PackageDir)
copy ..\MouseMirror.ps1 $(OutDir)</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Link>
<AdditionalDependencies>%(AdditionalDependencies);$(DDK_LIB_PATH)\hidparse.lib</AdditionalDependencies>
</Link>
<ClCompile>
<PreprocessorDefinitions>%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ExceptionHandling>
</ExceptionHandling>
</ClCompile>
<Midl>
<PreprocessorDefinitions>%(PreprocessorDefinitions)</PreprocessorDefinitions>
</Midl>
<ResourceCompile>
<PreprocessorDefinitions>%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ResourceCompile>
<DriverSign>
<FileDigestAlgorithm>sha256</FileDigestAlgorithm>
</DriverSign>
<PostBuildEvent>
<Command>copy *.bat $(PackageDir)
copy "C:\Program Files (x86)\Windows Kits\10\tools\$(WDKBuildFolder)\x64\dev*.exe" $(PackageDir)
copy ..\MouseMirror.ps1 $(OutDir)</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="device.cpp" />
<ClCompile Include="driver.cpp" />
<ClCompile Include="wmi.cpp" />
<ResourceCompile Include="module.rc" />
</ItemGroup>
<ItemGroup>
<Inf Exclude="@(Inf)" Include="*.inx" />
<FilesToPackage Include="$(TargetPath)" Condition="'$(ConfigurationType)'=='Driver' or '$(ConfigurationType)'=='DynamicLibrary'" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="device.h" />
<ClInclude Include="driver.h" />
<ClInclude Include="MouseMirror.h" />
<ClInclude Include="wmi.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
</Project>
16 changes: 16 additions & 0 deletions MouseMirror/UNINSTALL_MouseMirror.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
@echo off
:: Goto current directory
cd /d "%~dp0"

:: delete the devnode
devcon /r remove "HID\VID_045E&PID_082A&MI_00&Col01"
:: TODO: Switch to PNPUTIL in Win11 21H2
::PNPUTIL /remove-device /deviceid "HID\VID_045E&PID_082A&MI_00&Col01"

:: uninstall driver
PNPUTIL /delete-driver MouseMirror.inf /uninstall /force /reboot

:: Delete MouseMirrorDeviceInformation WMI class security descriptor
reg delete "HKLM\SYSTEM\CurrentControlSet\Control\WMI\Security" /v "97754ED3-63DF-485E-A7B9-E4BDD92C8BF3" /f

pause
Loading