Skip to content

Commit

Permalink
Add EyeControl to Microsoft.Windows.Setting.Accessibility (#127)
Browse files Browse the repository at this point in the history
  • Loading branch information
Trenly authored Nov 11, 2024
1 parent ac66685 commit 2373010
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
'TextCursor',
'StickyKeys',
'ToggleKeys',
'FilterKeys'
'FilterKeys',
'EyeControl'
)
PrivateData = @{
PSData = @{
Expand All @@ -32,7 +33,8 @@
'PSDscResource_TextCursor',
'PSDscResource_StickyKeys',
'PSDscResource_ToggleKeys',
'PSDscResource_FilterKeys'
'PSDscResource_FilterKeys',
'PSDscResource_EyeControl'
)

# Prerelease string of this module
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
$ErrorActionPreference = 'Stop'
Set-StrictMode -Version Latest

enum Ensure {
Absent
Present
}

enum TextSize {
KeepCurrentValue
Small
Expand Down Expand Up @@ -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()]
Expand Down Expand Up @@ -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 (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down Expand Up @@ -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 = ''
}

0 comments on commit 2373010

Please sign in to comment.