From aacbb2e11bdf7ca00c323ba2ca57751ece644d9b Mon Sep 17 00:00:00 2001 From: Kaleb Luedtke Date: Fri, 8 Nov 2024 18:47:38 -0600 Subject: [PATCH 1/3] Add EyeControl to Microsoft.Windows.Setting.Accessibility --- ...crosoft.Windows.Setting.Accessibility.psd1 | 6 ++- ...crosoft.Windows.Setting.Accessibility.psm1 | 39 ++++++++++++++++++- 2 files changed, 42 insertions(+), 3 deletions(-) diff --git a/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psd1 b/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psd1 index b7c18fa1..e11cea5e 100644 --- a/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psd1 +++ b/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psd1 @@ -18,7 +18,8 @@ 'TextCursor', 'StickyKeys', 'ToggleKeys', - 'FilterKeys' + 'FilterKeys', + 'EyeControl' ) PrivateData = @{ PSData = @{ @@ -32,7 +33,8 @@ 'PSDscResource_TextCursor', 'PSDscResource_StickyKeys', 'PSDscResource_ToggleKeys', - 'PSDscResource_FilterKeys' + 'PSDscResource_FilterKeys', + 'PSDscResource_EyeControl' ) # Prerelease string of this module diff --git a/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psm1 b/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psm1 index 1e98a833..e6070e27 100644 --- a/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psm1 +++ b/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psm1 @@ -4,6 +4,11 @@ $ErrorActionPreference = 'Stop' Set-StrictMode -Version Latest +enum Ensure { + Absent + Present +} + enum TextSize { KeepCurrentValue Small @@ -78,8 +83,9 @@ if ([string]::IsNullOrEmpty($env:TestRegistryPath)) { $global:StickyKeysRegistryPath = 'HKCU:\Control Panel\Accessibility\StickyKeys' $global:ToggleKeysRegistryPath = 'HKCU:\Control Panel\Accessibility\ToggleKeys' $global:FilterKeysRegistryPath = 'HKCU:\Control Panel\Accessibility\Keyboard Response' + $global:EyeControlRegistryPath = 'HKCU:\Software\Microsoft\input\EC\' } else { - $global:AccessibilityRegistryPath = $global:MagnifierRegistryPath = $global:PointerRegistryPath = $global:ControlPanelAccessibilityRegistryPath = $global:AudioRegistryPath = $global:PersonalizationRegistryPath = $global:NTAccessibilityRegistryPath = $global:CursorIndicatorAccessibilityRegistryPath = $global:ControlPanelDesktopRegistryPath = $global:StickyKeysRegistryPath = $global:ToggleKeysRegistryPath = $global:FilterKeysRegistryPath = $env:TestRegistryPath + $global:AccessibilityRegistryPath = $global:MagnifierRegistryPath = $global:PointerRegistryPath = $global:ControlPanelAccessibilityRegistryPath = $global:AudioRegistryPath = $global:PersonalizationRegistryPath = $global:NTAccessibilityRegistryPath = $global:CursorIndicatorAccessibilityRegistryPath = $global:ControlPanelDesktopRegistryPath = $global:StickyKeysRegistryPath = $global:ToggleKeysRegistryPath = $global:FilterKeysRegistryPath = $global:EyeControlRegistryPath = $env:TestRegistryPath } [DSCResource()] @@ -891,6 +897,37 @@ class FilterKeys { } } +[DscResource()] +class EyeControl { + [DscProperty(Key)] [Ensure] $Ensure + hidden [string] $SettingsProperty = 'Enabled' + + [EyeControl] Get() { + $currentState = [EyeControl]::new() + + if (-not(DoesRegistryKeyPropertyExist -Path $global:EyeControlRegistryPath -Name $this.SettingsProperty)) { + $currentState.Ensure = [Ensure]::Absent + } else { + $currentState.Ensure = [int]((Get-ItemPropertyValue -Path $global:EyeControlRegistryPath -Name $this.SettingsProperty) -eq 1) + } + + return $currentState + } + + [bool] Test() { + return $this.Get().Ensure -eq $this.Ensure + } + + [void] Set() { + # Only make changes if changes are needed + if ($this.Test()) { return } + if (-not (DoesRegistryKeyPropertyExist -Path $global:EyeControlRegistryPath -Name $this.SettingsProperty)) { + New-ItemProperty -Path $global:EyeControlRegistryPath -Name $this.SettingsProperty -PropertyType DWord + } + Set-ItemProperty -Path $global:EyeControlRegistryPath -Name $this.SettingsProperty -Value $([int]$this.Ensure) + } +} + #region Functions function DoesRegistryKeyPropertyExist { param ( From bef618510579d60db063f2126ae91dd2682d3fa4 Mon Sep 17 00:00:00 2001 From: Kaleb Luedtke Date: Fri, 8 Nov 2024 18:53:23 -0600 Subject: [PATCH 2/3] Add tests --- ...ft.Windows.Setting.Accessibility.Tests.ps1 | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.Tests.ps1 b/tests/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.Tests.ps1 index dd22de6d..5fd92a5e 100644 --- a/tests/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.Tests.ps1 +++ b/tests/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.Tests.ps1 @@ -401,6 +401,28 @@ Describe 'FilterKeys' { } } +Describe 'EyeControl' { + It 'Enable EyeControl.' { + Invoke-DscResource -Name EyeControl -ModuleName Microsoft.Windows.Setting.Accessibility -Method Set -Property @{ Ensure = 'Absent' } + + $initialState = Invoke-DscResource -Name EyeControl -ModuleName Microsoft.Windows.Setting.Accessibility -Method Get -Property @{} + $initialState.Ensure | Should -Be 'Absent' + + # Test enabled + $parameters = @{ Ensure = 'Present' } + $testResult = Invoke-DscResource -Name EyeControl -ModuleName Microsoft.Windows.Setting.Accessibility -Method Test -Property $parameters + $testResult.InDesiredState | Should -Be $false + + # Set enabled + Invoke-DscResource -Name EyeControl -ModuleName Microsoft.Windows.Setting.Accessibility -Method Set -Property $parameters + $finalState = Invoke-DscResource -Name EyeControl -ModuleName Microsoft.Windows.Setting.Accessibility -Method Get -Property @{} + $finalState.Ensure | Should -Be 'Present' + + $testResult2 = Invoke-DscResource -Name EyeControl -ModuleName Microsoft.Windows.Setting.Accessibility -Method Test -Property $parameters + $testResult2.InDesiredState | Should -Be $true + } +} + AfterAll { $env:TestRegistryPath = '' } From a67cd9ccf14b34a2b47b27ff1ffd186a410cefa6 Mon Sep 17 00:00:00 2001 From: Kaleb Luedtke Date: Fri, 8 Nov 2024 18:59:27 -0600 Subject: [PATCH 3/3] Fix test that I forgot --- .../Microsoft.Windows.Setting.Accessibility.Tests.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.Tests.ps1 b/tests/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.Tests.ps1 index 5fd92a5e..85e78709 100644 --- a/tests/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.Tests.ps1 +++ b/tests/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.Tests.ps1 @@ -26,9 +26,9 @@ BeforeAll { Describe 'List available DSC resources' { It 'Shows DSC Resources' { - $expectedDSCResources = 'Text', 'Magnifier', 'MousePointer', 'VisualEffect', 'Audio', 'TextCursor', 'StickyKeys', 'ToggleKeys', 'FilterKeys' + $expectedDSCResources = 'Text', 'Magnifier', 'MousePointer', 'VisualEffect', 'Audio', 'TextCursor', 'StickyKeys', 'ToggleKeys', 'FilterKeys', 'EyeControl' $availableDSCResources = (Get-DscResource -Module Microsoft.Windows.Setting.Accessibility).Name - $availableDSCResources.length | Should -Be 9 + $availableDSCResources.length | Should -Be 10 $availableDSCResources | Where-Object { $expectedDSCResources -notcontains $_ } | Should -BeNullOrEmpty -ErrorAction Stop } }