Skip to content

Commit 2373010

Browse files
authored
Add EyeControl to Microsoft.Windows.Setting.Accessibility (#127)
1 parent ac66685 commit 2373010

File tree

3 files changed

+66
-5
lines changed

3 files changed

+66
-5
lines changed

resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psd1

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
'TextCursor',
1919
'StickyKeys',
2020
'ToggleKeys',
21-
'FilterKeys'
21+
'FilterKeys',
22+
'EyeControl'
2223
)
2324
PrivateData = @{
2425
PSData = @{
@@ -32,7 +33,8 @@
3233
'PSDscResource_TextCursor',
3334
'PSDscResource_StickyKeys',
3435
'PSDscResource_ToggleKeys',
35-
'PSDscResource_FilterKeys'
36+
'PSDscResource_FilterKeys',
37+
'PSDscResource_EyeControl'
3638
)
3739

3840
# Prerelease string of this module

resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psm1

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
$ErrorActionPreference = 'Stop'
55
Set-StrictMode -Version Latest
66

7+
enum Ensure {
8+
Absent
9+
Present
10+
}
11+
712
enum TextSize {
813
KeepCurrentValue
914
Small
@@ -78,8 +83,9 @@ if ([string]::IsNullOrEmpty($env:TestRegistryPath)) {
7883
$global:StickyKeysRegistryPath = 'HKCU:\Control Panel\Accessibility\StickyKeys'
7984
$global:ToggleKeysRegistryPath = 'HKCU:\Control Panel\Accessibility\ToggleKeys'
8085
$global:FilterKeysRegistryPath = 'HKCU:\Control Panel\Accessibility\Keyboard Response'
86+
$global:EyeControlRegistryPath = 'HKCU:\Software\Microsoft\input\EC\'
8187
} else {
82-
$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
88+
$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
8389
}
8490

8591
[DSCResource()]
@@ -891,6 +897,37 @@ class FilterKeys {
891897
}
892898
}
893899

900+
[DscResource()]
901+
class EyeControl {
902+
[DscProperty(Key)] [Ensure] $Ensure
903+
hidden [string] $SettingsProperty = 'Enabled'
904+
905+
[EyeControl] Get() {
906+
$currentState = [EyeControl]::new()
907+
908+
if (-not(DoesRegistryKeyPropertyExist -Path $global:EyeControlRegistryPath -Name $this.SettingsProperty)) {
909+
$currentState.Ensure = [Ensure]::Absent
910+
} else {
911+
$currentState.Ensure = [int]((Get-ItemPropertyValue -Path $global:EyeControlRegistryPath -Name $this.SettingsProperty) -eq 1)
912+
}
913+
914+
return $currentState
915+
}
916+
917+
[bool] Test() {
918+
return $this.Get().Ensure -eq $this.Ensure
919+
}
920+
921+
[void] Set() {
922+
# Only make changes if changes are needed
923+
if ($this.Test()) { return }
924+
if (-not (DoesRegistryKeyPropertyExist -Path $global:EyeControlRegistryPath -Name $this.SettingsProperty)) {
925+
New-ItemProperty -Path $global:EyeControlRegistryPath -Name $this.SettingsProperty -PropertyType DWord
926+
}
927+
Set-ItemProperty -Path $global:EyeControlRegistryPath -Name $this.SettingsProperty -Value $([int]$this.Ensure)
928+
}
929+
}
930+
894931
#region Functions
895932
function DoesRegistryKeyPropertyExist {
896933
param (

tests/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.Tests.ps1

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ BeforeAll {
2626

2727
Describe 'List available DSC resources' {
2828
It 'Shows DSC Resources' {
29-
$expectedDSCResources = 'Text', 'Magnifier', 'MousePointer', 'VisualEffect', 'Audio', 'TextCursor', 'StickyKeys', 'ToggleKeys', 'FilterKeys'
29+
$expectedDSCResources = 'Text', 'Magnifier', 'MousePointer', 'VisualEffect', 'Audio', 'TextCursor', 'StickyKeys', 'ToggleKeys', 'FilterKeys', 'EyeControl'
3030
$availableDSCResources = (Get-DscResource -Module Microsoft.Windows.Setting.Accessibility).Name
31-
$availableDSCResources.length | Should -Be 9
31+
$availableDSCResources.length | Should -Be 10
3232
$availableDSCResources | Where-Object { $expectedDSCResources -notcontains $_ } | Should -BeNullOrEmpty -ErrorAction Stop
3333
}
3434
}
@@ -401,6 +401,28 @@ Describe 'FilterKeys' {
401401
}
402402
}
403403

404+
Describe 'EyeControl' {
405+
It 'Enable EyeControl.' {
406+
Invoke-DscResource -Name EyeControl -ModuleName Microsoft.Windows.Setting.Accessibility -Method Set -Property @{ Ensure = 'Absent' }
407+
408+
$initialState = Invoke-DscResource -Name EyeControl -ModuleName Microsoft.Windows.Setting.Accessibility -Method Get -Property @{}
409+
$initialState.Ensure | Should -Be 'Absent'
410+
411+
# Test enabled
412+
$parameters = @{ Ensure = 'Present' }
413+
$testResult = Invoke-DscResource -Name EyeControl -ModuleName Microsoft.Windows.Setting.Accessibility -Method Test -Property $parameters
414+
$testResult.InDesiredState | Should -Be $false
415+
416+
# Set enabled
417+
Invoke-DscResource -Name EyeControl -ModuleName Microsoft.Windows.Setting.Accessibility -Method Set -Property $parameters
418+
$finalState = Invoke-DscResource -Name EyeControl -ModuleName Microsoft.Windows.Setting.Accessibility -Method Get -Property @{}
419+
$finalState.Ensure | Should -Be 'Present'
420+
421+
$testResult2 = Invoke-DscResource -Name EyeControl -ModuleName Microsoft.Windows.Setting.Accessibility -Method Test -Property $parameters
422+
$testResult2.InDesiredState | Should -Be $true
423+
}
424+
}
425+
404426
AfterAll {
405427
$env:TestRegistryPath = ''
406428
}

0 commit comments

Comments
 (0)