├── .editorconfig ├── .gitattributes ├── .github └── workflows │ ├── ci-sample.yml │ ├── ci.yml │ └── release-nuget.yml ├── .gitignore ├── LICENSE ├── README.md ├── README_Instructions.md ├── nuget.png ├── samples ├── Plugin.Maui.KeyListener.Sample.sln └── Plugin.Maui.KeyListener.Sample │ ├── App.xaml │ ├── App.xaml.cs │ ├── AppShell.xaml │ ├── AppShell.xaml.cs │ ├── MainPage.xaml │ ├── MainPage.xaml.cs │ ├── MauiProgram.cs │ ├── Platforms │ ├── Android │ │ ├── AndroidManifest.xml │ │ ├── MainActivity.cs │ │ ├── MainApplication.cs │ │ └── Resources │ │ │ └── values │ │ │ └── colors.xml │ ├── MacCatalyst │ │ ├── AppDelegate.cs │ │ ├── Info.plist │ │ └── Program.cs │ ├── Tizen │ │ ├── Main.cs │ │ └── tizen-manifest.xml │ ├── Windows │ │ ├── App.xaml │ │ ├── App.xaml.cs │ │ ├── Package.appxmanifest │ │ └── app.manifest │ └── iOS │ │ ├── AppDelegate.cs │ │ ├── Info.plist │ │ └── Program.cs │ ├── Plugin.Maui.KeyListener.Sample.csproj │ ├── Properties │ └── launchSettings.json │ └── Resources │ ├── AppIcon │ ├── appicon.svg │ └── appiconfg.svg │ ├── Fonts │ ├── OpenSans-Regular.ttf │ └── OpenSans-Semibold.ttf │ ├── Raw │ ├── AboutAssets.txt │ ├── dotnetbot.json │ └── ukelele.mp3 │ ├── Splash │ └── splash.svg │ └── Styles │ ├── Colors.xaml │ └── Styles.xaml └── src ├── Plugin.Maui.KeyListener.sln └── Plugin.Maui.KeyListener ├── KeyPressedEventArgs.cs ├── KeyboardBehavior.Android.cs ├── KeyboardBehavior.Windows.cs ├── KeyboardBehavior.cs ├── KeyboardBehavior.iOS.cs ├── KeyboardBehaviorTrigger.Windows.cs ├── KeyboardBehaviorTrigger.cs ├── KeyboardBehaviorTrigger.iOS.cs ├── KeyboardFlags.cs ├── KeyboardKeys.cs ├── KeyboardKeysExtensions.Android.cs ├── KeyboardKeysExtensions.Windows.cs ├── KeyboardKeysExtensions.cs ├── KeyboardKeysExtensions.iOS.cs ├── KeyboardMarkupExtensions.cs ├── KeyboardModifiersExtensions.Android.cs ├── KeyboardModifiersExtensions.Windows.cs ├── KeyboardModifiersExtensions.iOS.cs ├── KeyboardPageViewController.cs ├── MauiProgramExtension.cs ├── NativeMethods.json ├── NativeMethods.txt ├── Plugin.Maui.KeyListener.csproj └── WeakReferenceExtensions.cs /.editorconfig: -------------------------------------------------------------------------------- 1 | # Suppress: EC112 2 | # top-most EditorConfig file 3 | root = true 4 | 5 | # Default settings: 6 | # A newline ending every file 7 | # Use tabs as indentation 8 | [*] 9 | insert_final_newline = false 10 | indent_style = tab 11 | indent_size = 4 12 | 13 | # Code files 14 | [*.{cs,csx,vb,vbx}] 15 | indent_style = tab 16 | indent_size = 4 17 | 18 | # Code files 19 | [*.sln] 20 | indent_size = 4 21 | 22 | # Xml project files 23 | [*.{csproj,vbproj,vcxproj,vcxproj.filters,proj,projitems,shproj}] 24 | indent_size = 2 25 | 26 | # Xml config files 27 | [*.{props,targets,ruleset,config,nuspec,resx,vsixmanifest,vsct}] 28 | indent_size = 2 29 | 30 | # JSON files 31 | [*.json] 32 | indent_size = 2 33 | 34 | # XML files 35 | [*.xml] 36 | indent_size = 2 37 | 38 | [*.cs] 39 | 40 | # Organize usings 41 | dotnet_sort_system_directives_first = true 42 | 43 | # IDE0160: Use file scoped namespace 44 | csharp_style_namespace_declarations = file_scoped:error 45 | 46 | # CS4014: Because this call is not awaited, execution of the current method continues before the call is completed 47 | dotnet_diagnostic.CS4014.severity = error 48 | 49 | # Remove explicit default access modifiers 50 | dotnet_style_require_accessibility_modifiers = omit_if_default:error 51 | 52 | # CA1063: Implement IDisposable Correctly 53 | dotnet_diagnostic.CA1063.severity = error 54 | 55 | # Add braces (IDE0011) 56 | csharp_prefer_braces = true 57 | dotnet_diagnostic.IDE0011.severity = error 58 | 59 | # Pattern matching 60 | dotnet_style_object_initializer = true:suggestion 61 | dotnet_style_collection_initializer = true:suggestion 62 | dotnet_style_coalesce_expression = true:suggestion 63 | dotnet_style_null_propagation = true:suggestion 64 | dotnet_style_explicit_tuple_names = true:suggestion 65 | dotnet_style_prefer_is_null_check_over_reference_equality_method=true:suggestion 66 | 67 | csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion 68 | csharp_style_pattern_matching_over_as_with_null_check = true:suggestion 69 | csharp_style_inlined_variable_declaration = true:suggestion 70 | csharp_style_throw_expression = true:suggestion 71 | csharp_style_conditional_delegate_call = true:suggestions 72 | 73 | # Naming rules 74 | 75 | dotnet_diagnostic.IDE1006.severity = error 76 | 77 | ## Public Fields are kept Pascal Case 78 | dotnet_naming_symbols.public_symbols.applicable_kinds = field 79 | dotnet_naming_symbols.public_symbols.applicable_accessibilities = public 80 | 81 | dotnet_naming_style.first_word_upper_case_style.capitalization = first_word_upper 82 | 83 | dotnet_naming_rule.public_members_must_be_capitalized.symbols = public_symbols 84 | dotnet_naming_rule.public_members_must_be_capitalized.style = first_word_upper_case_style 85 | dotnet_naming_rule.public_members_must_be_capitalized.severity = suggestion 86 | 87 | ## Instance fields are camelCase 88 | dotnet_naming_rule.instance_fields_should_be_camel_case.severity = error 89 | dotnet_naming_rule.instance_fields_should_be_camel_case.symbols = instance_fields 90 | dotnet_naming_rule.instance_fields_should_be_camel_case.style = instance_field_style 91 | 92 | dotnet_naming_symbols.instance_fields.applicable_kinds = field 93 | 94 | dotnet_naming_style.instance_field_style.capitalization = camel_case 95 | dotnet_naming_style.instance_field_style.required_prefix = 96 | 97 | ## Static fields are camelCase 98 | dotnet_naming_rule.static_fields_should_be_camel_case.severity = error 99 | dotnet_naming_rule.static_fields_should_be_camel_case.symbols = static_fields 100 | dotnet_naming_rule.static_fields_should_be_camel_case.style = static_field_style 101 | 102 | dotnet_naming_symbols.static_fields.applicable_kinds = field 103 | dotnet_naming_symbols.static_fields.required_modifiers = static 104 | dotnet_naming_symbols.static_fields.applicable_accessibilities = internal, private, protected, protected_internal, private_protected 105 | 106 | dotnet_naming_style.static_field_style.capitalization = camel_case 107 | dotnet_naming_style.static_field_style.required_prefix = 108 | 109 | # Modifier preferences 110 | csharp_prefer_static_local_function = true:suggestion 111 | csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async:error -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /.github/workflows/ci-sample.yml: -------------------------------------------------------------------------------- 1 | name: Build Sample App for CI 2 | 3 | on: 4 | push: 5 | branches: [ "main" ] 6 | paths-ignore: 7 | - "**.md" 8 | pull_request: 9 | branches: [ "main" ] 10 | 11 | jobs: 12 | build-sample-ci: 13 | 14 | runs-on: windows-latest 15 | 16 | steps: 17 | - uses: actions/checkout@v3 18 | - name: Setup dotnet 19 | uses: actions/setup-dotnet@v3 20 | with: 21 | dotnet-version: 9.0.x 22 | - name: Setup MAUI 23 | run: dotnet workload install maui ios android maccatalyst 24 | - name: Build 25 | run: dotnet build samples\Plugin.Maui.KeyListener.Sample.sln -c Release 26 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: Build for CI 2 | 3 | on: 4 | push: 5 | branches: [ "main" ] 6 | paths-ignore: 7 | - "**.md" 8 | pull_request: 9 | branches: [ "main" ] 10 | 11 | jobs: 12 | build-plugin-ci: 13 | 14 | runs-on: windows-latest 15 | 16 | steps: 17 | - uses: actions/checkout@v3 18 | - name: Setup dotnet 19 | uses: actions/setup-dotnet@v3 20 | with: 21 | dotnet-version: 9.0.x 22 | - name: Setup MAUI 23 | run: dotnet workload install maui ios android maccatalyst 24 | - name: Build 25 | run: dotnet build src\Plugin.Maui.KeyListener.sln -c Release 26 | -------------------------------------------------------------------------------- /.github/workflows/release-nuget.yml: -------------------------------------------------------------------------------- 1 | name: Create a (Pre)release on NuGet 2 | 3 | on: 4 | push: 5 | tags: 6 | - "v[0-9]+.[0-9]+.[0-9]+" 7 | - "v[0-9]+.[0-9]+.[0-9]+-preview[0-9]+" 8 | workflow_dispatch: 9 | jobs: 10 | release-nuget: 11 | 12 | runs-on: windows-latest 13 | 14 | steps: 15 | - uses: actions/checkout@v3 16 | - name: Verify commit exists in origin/main 17 | run: | 18 | git fetch --no-tags --prune --depth=1 origin +refs/heads/*:refs/remotes/origin/* 19 | git branch --remote --contains | grep origin/main 20 | - name: Get version information from tag 21 | id: get_version 22 | uses: battila7/get-version-action@v2 23 | - name: Setup dotnet 24 | uses: actions/setup-dotnet@v3 25 | with: 26 | dotnet-version: 9.0.x 27 | - name: Setup MAUI 28 | run: dotnet workload install maui ios android maccatalyst 29 | - name: Pack 30 | run: dotnet pack src\Plugin.Maui.KeyListener.sln -c Release -p:PackageVersion=${{ steps.get_version.outputs.version-without-v }} 31 | - name: Push 32 | run: dotnet nuget push src\Plugin.Maui.KeyListener\bin\Release\Plugin.Maui.KeyListener.${{ steps.get_version.outputs.version-without-v }}.nupkg -s https://api.nuget.org/v3/index.json -k ${{ secrets.NUGET_API_KEY }} 33 | env: 34 | GITHUB_TOKEN: ${{ secrets.NUGET_API_KEY }} 35 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Mono auto generated files 17 | mono_crash.* 18 | 19 | # Build results 20 | [Dd]ebug/ 21 | [Dd]ebugPublic/ 22 | [Rr]elease/ 23 | [Rr]eleases/ 24 | x64/ 25 | x86/ 26 | [Ww][Ii][Nn]32/ 27 | [Aa][Rr][Mm]/ 28 | [Aa][Rr][Mm]64/ 29 | bld/ 30 | [Bb]in/ 31 | [Oo]bj/ 32 | [Ll]og/ 33 | [Ll]ogs/ 34 | 35 | # Visual Studio 2015/2017 cache/options directory 36 | .vs/ 37 | # Uncomment if you have tasks that create the project's static files in wwwroot 38 | #wwwroot/ 39 | 40 | # Visual Studio 2017 auto generated files 41 | Generated\ Files/ 42 | 43 | # MSTest test Results 44 | [Tt]est[Rr]esult*/ 45 | [Bb]uild[Ll]og.* 46 | 47 | # NUnit 48 | *.VisualState.xml 49 | TestResult.xml 50 | nunit-*.xml 51 | 52 | # Build Results of an ATL Project 53 | [Dd]ebugPS/ 54 | [Rr]eleasePS/ 55 | dlldata.c 56 | 57 | # Benchmark Results 58 | BenchmarkDotNet.Artifacts/ 59 | 60 | # .NET Core 61 | project.lock.json 62 | project.fragment.lock.json 63 | artifacts/ 64 | 65 | # ASP.NET Scaffolding 66 | ScaffoldingReadMe.txt 67 | 68 | # StyleCop 69 | StyleCopReport.xml 70 | 71 | # Files built by Visual Studio 72 | *_i.c 73 | *_p.c 74 | *_h.h 75 | *.ilk 76 | *.meta 77 | *.obj 78 | *.iobj 79 | *.pch 80 | *.pdb 81 | *.ipdb 82 | *.pgc 83 | *.pgd 84 | *.rsp 85 | *.sbr 86 | *.tlb 87 | *.tli 88 | *.tlh 89 | *.tmp 90 | *.tmp_proj 91 | *_wpftmp.csproj 92 | *.log 93 | *.tlog 94 | *.vspscc 95 | *.vssscc 96 | .builds 97 | *.pidb 98 | *.svclog 99 | *.scc 100 | 101 | # Chutzpah Test files 102 | _Chutzpah* 103 | 104 | # Visual C++ cache files 105 | ipch/ 106 | *.aps 107 | *.ncb 108 | *.opendb 109 | *.opensdf 110 | *.sdf 111 | *.cachefile 112 | *.VC.db 113 | *.VC.VC.opendb 114 | 115 | # Visual Studio profiler 116 | *.psess 117 | *.vsp 118 | *.vspx 119 | *.sap 120 | 121 | # Visual Studio Trace Files 122 | *.e2e 123 | 124 | # TFS 2012 Local Workspace 125 | $tf/ 126 | 127 | # Guidance Automation Toolkit 128 | *.gpState 129 | 130 | # ReSharper is a .NET coding add-in 131 | _ReSharper*/ 132 | *.[Rr]e[Ss]harper 133 | *.DotSettings.user 134 | 135 | # TeamCity is a build add-in 136 | _TeamCity* 137 | 138 | # DotCover is a Code Coverage Tool 139 | *.dotCover 140 | 141 | # AxoCover is a Code Coverage Tool 142 | .axoCover/* 143 | !.axoCover/settings.json 144 | 145 | # Coverlet is a free, cross platform Code Coverage Tool 146 | coverage*.json 147 | coverage*.xml 148 | coverage*.info 149 | 150 | # Visual Studio code coverage results 151 | *.coverage 152 | *.coveragexml 153 | 154 | # NCrunch 155 | _NCrunch_* 156 | .*crunch*.local.xml 157 | nCrunchTemp_* 158 | 159 | # MightyMoose 160 | *.mm.* 161 | AutoTest.Net/ 162 | 163 | # Web workbench (sass) 164 | .sass-cache/ 165 | 166 | # Installshield output folder 167 | [Ee]xpress/ 168 | 169 | # DocProject is a documentation generator add-in 170 | DocProject/buildhelp/ 171 | DocProject/Help/*.HxT 172 | DocProject/Help/*.HxC 173 | DocProject/Help/*.hhc 174 | DocProject/Help/*.hhk 175 | DocProject/Help/*.hhp 176 | DocProject/Help/Html2 177 | DocProject/Help/html 178 | 179 | # Click-Once directory 180 | publish/ 181 | 182 | # Publish Web Output 183 | *.[Pp]ublish.xml 184 | *.azurePubxml 185 | # Note: Comment the next line if you want to checkin your web deploy settings, 186 | # but database connection strings (with potential passwords) will be unencrypted 187 | *.pubxml 188 | *.publishproj 189 | 190 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 191 | # checkin your Azure Web App publish settings, but sensitive information contained 192 | # in these scripts will be unencrypted 193 | PublishScripts/ 194 | 195 | # NuGet Packages 196 | *.nupkg 197 | # NuGet Symbol Packages 198 | *.snupkg 199 | # The packages folder can be ignored because of Package Restore 200 | **/[Pp]ackages/* 201 | # except build/, which is used as an MSBuild target. 202 | !**/[Pp]ackages/build/ 203 | # Uncomment if necessary however generally it will be regenerated when needed 204 | #!**/[Pp]ackages/repositories.config 205 | # NuGet v3's project.json files produces more ignorable files 206 | *.nuget.props 207 | *.nuget.targets 208 | 209 | # Microsoft Azure Build Output 210 | csx/ 211 | *.build.csdef 212 | 213 | # Microsoft Azure Emulator 214 | ecf/ 215 | rcf/ 216 | 217 | # Windows Store app package directories and files 218 | AppPackages/ 219 | BundleArtifacts/ 220 | Package.StoreAssociation.xml 221 | _pkginfo.txt 222 | *.appx 223 | *.appxbundle 224 | *.appxupload 225 | 226 | # Visual Studio cache files 227 | # files ending in .cache can be ignored 228 | *.[Cc]ache 229 | # but keep track of directories ending in .cache 230 | !?*.[Cc]ache/ 231 | 232 | # Others 233 | ClientBin/ 234 | ~$* 235 | *~ 236 | *.dbmdl 237 | *.dbproj.schemaview 238 | *.jfm 239 | *.pfx 240 | *.publishsettings 241 | orleans.codegen.cs 242 | 243 | # Including strong name files can present a security risk 244 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 245 | #*.snk 246 | 247 | # Since there are multiple workflows, uncomment next line to ignore bower_components 248 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 249 | #bower_components/ 250 | 251 | # RIA/Silverlight projects 252 | Generated_Code/ 253 | 254 | # Backup & report files from converting an old project file 255 | # to a newer Visual Studio version. Backup files are not needed, 256 | # because we have git ;-) 257 | _UpgradeReport_Files/ 258 | Backup*/ 259 | UpgradeLog*.XML 260 | UpgradeLog*.htm 261 | ServiceFabricBackup/ 262 | *.rptproj.bak 263 | 264 | # SQL Server files 265 | *.mdf 266 | *.ldf 267 | *.ndf 268 | 269 | # Business Intelligence projects 270 | *.rdl.data 271 | *.bim.layout 272 | *.bim_*.settings 273 | *.rptproj.rsuser 274 | *- [Bb]ackup.rdl 275 | *- [Bb]ackup ([0-9]).rdl 276 | *- [Bb]ackup ([0-9][0-9]).rdl 277 | 278 | # Microsoft Fakes 279 | FakesAssemblies/ 280 | 281 | # GhostDoc plugin setting file 282 | *.GhostDoc.xml 283 | 284 | # Node.js Tools for Visual Studio 285 | .ntvs_analysis.dat 286 | node_modules/ 287 | 288 | # Visual Studio 6 build log 289 | *.plg 290 | 291 | # Visual Studio 6 workspace options file 292 | *.opt 293 | 294 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 295 | *.vbw 296 | 297 | # Visual Studio 6 auto-generated project file (contains which files were open etc.) 298 | *.vbp 299 | 300 | # Visual Studio 6 workspace and project file (working project files containing files to include in project) 301 | *.dsw 302 | *.dsp 303 | 304 | # Visual Studio 6 technical files 305 | *.ncb 306 | *.aps 307 | 308 | # Visual Studio LightSwitch build output 309 | **/*.HTMLClient/GeneratedArtifacts 310 | **/*.DesktopClient/GeneratedArtifacts 311 | **/*.DesktopClient/ModelManifest.xml 312 | **/*.Server/GeneratedArtifacts 313 | **/*.Server/ModelManifest.xml 314 | _Pvt_Extensions 315 | 316 | # Paket dependency manager 317 | .paket/paket.exe 318 | paket-files/ 319 | 320 | # FAKE - F# Make 321 | .fake/ 322 | 323 | # CodeRush personal settings 324 | .cr/personal 325 | 326 | # Python Tools for Visual Studio (PTVS) 327 | __pycache__/ 328 | *.pyc 329 | 330 | # Cake - Uncomment if you are using it 331 | # tools/** 332 | # !tools/packages.config 333 | 334 | # Tabs Studio 335 | *.tss 336 | 337 | # Telerik's JustMock configuration file 338 | *.jmconfig 339 | 340 | # BizTalk build output 341 | *.btp.cs 342 | *.btm.cs 343 | *.odx.cs 344 | *.xsd.cs 345 | 346 | # OpenCover UI analysis results 347 | OpenCover/ 348 | 349 | # Azure Stream Analytics local run output 350 | ASALocalRun/ 351 | 352 | # MSBuild Binary and Structured Log 353 | *.binlog 354 | 355 | # NVidia Nsight GPU debugger configuration file 356 | *.nvuser 357 | 358 | # MFractors (Xamarin productivity tool) working folder 359 | .mfractor/ 360 | 361 | # Local History for Visual Studio 362 | .localhistory/ 363 | 364 | # Visual Studio History (VSHistory) files 365 | .vshistory/ 366 | 367 | # BeatPulse healthcheck temp database 368 | healthchecksdb 369 | 370 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 371 | MigrationBackup/ 372 | 373 | # Ionide (cross platform F# VS Code tools) working folder 374 | .ionide/ 375 | 376 | # Fody - auto-generated XML schema 377 | FodyWeavers.xsd 378 | 379 | # VS Code files for those working on multiple tools 380 | .vscode/* 381 | !.vscode/settings.json 382 | !.vscode/tasks.json 383 | !.vscode/launch.json 384 | !.vscode/extensions.json 385 | *.code-workspace 386 | 387 | # Local History for Visual Studio Code 388 | .history/ 389 | 390 | # Windows Installer files from build outputs 391 | *.cab 392 | *.msi 393 | *.msix 394 | *.msm 395 | *.msp 396 | 397 | # JetBrains Rider 398 | *.sln.iml 399 | .DS_Store 400 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 David Ortinau 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | ![](nuget.png) 3 | # Plugin.Maui.KeyListener 4 | 5 | `Plugin.Maui.KeyListener` provides `KeyboardBehavior` to listen for keyboard up (pressed) and down (released) events on any view in a .NET MAUI application. This is useful in situations where a `KeyboardAccelerator` isn't suitable. 6 | 7 | > **Current status:** I've got macOS working, and Windows via global window events. Android and iOS need some love. 8 | 9 | ## Install Plugin 10 | 11 | [![NuGet](https://img.shields.io/nuget/v/Plugin.Maui.KeyListener.svg?label=NuGet)](https://www.nuget.org/packages/Plugin.Maui.KeyListener/) 12 | 13 | Available on [NuGet](http://www.nuget.org/packages/Plugin.Maui.KeyListener). 14 | 15 | Install with the dotnet CLI: `dotnet add package Plugin.Maui.KeyListener`, or through the NuGet Package Manager in Visual Studio. 16 | 17 | ### Supported Platforms 18 | 19 | | Platform | Minimum Version Supported | 20 | |----------|---------------------------| 21 | | iOS | 11+ | 22 | | macOS | 10.15+ | 23 | | Android | 5.0 (API 21) | 24 | | Windows | 11 and 10 version 1809+ | 25 | 26 | ## Accessibility Considerations 27 | 28 | ### Windows 29 | 30 | Implementing KeyboardBehavior to manage navigation and interaction on Windows enhances accessibility because Windows accessibility features are tightly integrated with keyboard navigation. This allows users who rely on keyboard input rather than mouse interactions to navigate your application effectively. 31 | 32 | 33 | ### Mac 34 | 35 | Using KeyboardBehavior on macOS improves navigation for users who have enabled basic keyboard navigation features. However, it provides no benefits for users utilizing Full Keyboard Access mode or VoiceOver screen reader navigation. For comprehensive accessibility support on Mac (and Windows), it's recommended to implement the SemanticOrderView from the MAUI Community Toolkit alongside KeyboardBehavior. 36 | 37 | 38 | ## API Usage 39 | 40 | `Plugin.Maui.KeyListener` provides the `Feature` class that has a single property `Property` that you can get or set. 41 | 42 | You can either use it as a static class, e.g.: `Feature.Default.Property = 1` or with dependency injection: `builder.Services.AddSingleton(Feature.Default);` 43 | 44 | ### Regisgtration 45 | 46 | Before you can start using `KeyboardBehavior`, you need to register to use it in your `MauiProgram`: 47 | 48 | ```csharp 49 | public static MauiApp CreateMauiApp() 50 | { 51 | var builder = MauiApp.CreateBuilder(); 52 | builder 53 | .UseMauiApp() 54 | .UseKeyListener(); 55 | 56 | return builder.Build(); 57 | } 58 | ``` 59 | 60 | ### Listening 61 | 62 | Add the behavior to the visual element where you want to listen for keyboard events. These events will bubble up no matter where you have focus. 63 | 64 | ```csharp 65 | public class MainPage : ContentPage 66 | { 67 | KeyboardBehavior keyboardBehavior = new (); 68 | 69 | protected override void OnNavigatedTo(NavigatedToEventArgs args) 70 | { 71 | keyboardBehavior.KeyDown += OnKeyDown; 72 | keyboardBehavior.KeyUp += OnKeyUp; 73 | this.Behaviors.Add(keyboardBehavior); 74 | 75 | base.OnNavigatedTo(args); 76 | } 77 | 78 | protected override void OnNavigatedFrom(NavigatedFromEventArgs args) 79 | { 80 | keyboardBehavior.KeyDown -= OnKeyDown; 81 | keyboardBehavior.KeyUp -= OnKeyUp; 82 | this.Behaviors.Remove(keyboardBehavior); 83 | 84 | base.OnNavigatedFrom(args); 85 | } 86 | 87 | void OnKeyUp(object sender, KeyPressedEventArgs args) 88 | { 89 | // do something 90 | } 91 | 92 | void OnKeyDown(object sender, KeyPressedEventArgs args) 93 | { 94 | // do something 95 | } 96 | } 97 | ``` 98 | 99 | # Sample 100 | 101 | There is a sample project here in the repository. I've also built a little game [GuessWord](https://www.github.com/davidortinau/GuessWord) that uses this plugin. 102 | 103 | # Acknowledgements 104 | 105 | This is almost all code from @pureween, with some additions by @davidortinau and contributors! <3 106 | -------------------------------------------------------------------------------- /README_Instructions.md: -------------------------------------------------------------------------------- 1 | # Plugin.Maui.KeyListener Template 2 | 3 | The `Plugin.Maui.KeyListener` repository is a template repository that can be used to bootstrap your own .NET MAUI plugin project. You can use this project structure as a blueprint for your own work. 4 | 5 | Learn how to get started with your plugin in this [YouTube video](https://www.youtube.com/watch?v=ZCQrlGT7MhI&list=PLfbOp004UaYVgzmTBNVI0ql2qF0LhSEU1&index=27). 6 | 7 | This template contains: 8 | 9 | - A [sample .NET MAUI app](samples) where you can demonstrate how your plugin works and test your plugin with while developing 10 | - The [source](src) of the plugin 11 | - A boilerplate [README file](README_Feature.md) you can use (don't forget to rename to `README.md` and remove this one!) 12 | - [GitHub Actions for CI](.github/workflows) of the library and the sample app 13 | - [GitHub Action for releasing](.github/workflows) your package to NuGet 14 | - A [generic icon](nuget.png) for your project, feel free to adapt and be creative! 15 | - A [.editorconfig](.editorconfig) file to standardize the code syntax. Feel free to adapt or remove. 16 | - The [LICENSE](LICENSE) file with the MIT license. If you want this to be different, please change it. At the very least add your name in there! 17 | 18 | ## Getting Started 19 | 20 | 1. Create your own GitHub repository from this one by clicking the "Use this template" button and then "Create a new repository". More information in the [documentation](https://docs.github.com/repositories/creating-and-managing-repositories/creating-a-repository-from-a-template). After that, clone the repo to your local machine. 21 | 22 | 2. Replace all occurrences of `Plugin.Maui.KeyListener` with whatever your feature or functionality will be. For instance: `Plugin.Maui.ScreenBrightness` or `Plugin.Maui.Audio`. Of course the name can be anything, but to make it more discoverable it could be a great choice to stick to this naming scheme. You can easily do this with your favorite text-editor and do a replace all on all files. 23 | 24 | 2.1 Don't forget to also rename the files and folders on your filesystem. 25 | 26 | 3. In the csproj file of the plugin project (under `src`), make sure that you replace all relevant values to your project. This means the author of this project, the description of the project, the target framework (.NET 7, 8 or something else). If you don't want to or can't support a certain platform, remove that target platform altogether. 27 | 28 | 4. Delete this `README.md` file and rename `README_Feature.md` to `README.md`. Fill that README file with all the relevant details of your project. 29 | 30 | 5. Check the LICENSE file if this reflects the license that you want to distribute your project under. At the very least add your name there and the current year we live in. 31 | 32 | 6. Create a nice icon in the `nuget.png` file that will show up on nuget.org and in the NuGet manager in Visual Studio. 33 | 34 | 7. Write your plugin code (under `src`) and add samples to the .NET MAUI sample app (under `samples` folder) 35 | 36 | 8. Make super sure that your package won't show up as `Plugin.Maui.KeyListener` on NuGet! If one does, you owe me a drink! 37 | 38 | 9. Publish your package to NuGet, a nice guide to do that can be found [here](https://learn.microsoft.com/nuget/nuget-org/publish-a-package). Also see [Publish to NuGet](#publish-to-nuget) below. 39 | 40 | 10. Enjoy life as a .NET MAUI plugin author! ✨ 41 | 42 | As an example of all of this you can have a look at: 43 | 44 | - [Plugin.Maui.Audio](https://github.com/jfversluis/Plugin.Maui.Audio) 45 | - [Plugin.Maui.Pedometer](https://github.com/jfversluis/Plugin.Maui.Pedometer) 46 | - [Plugin.Maui.ScreenBrightness](https://github.com/jfversluis/Plugin.Maui.ScreenBrightness) 47 | 48 | ## Publish to NuGet 49 | 50 | If you want to publish your package to NuGet, you totally can! Included in this template are a couple of GitHub Actions. One of them goes of when you create a new tag with this pattern: `v1.0.0` or `v1.0.0-preview1`. Obviously the `1.0.0` part can be determined by you as you see fit, as long as you follow the pattern of 3 integers separated by dots. 51 | 52 | You will also want to set a secret for this repository which contains your NuGet API key. Follow the documentation on that [here](https://docs.github.com/actions/security-guides/encrypted-secrets#creating-encrypted-secrets-for-a-repository), and add a secret with the key `NUGET_API_KEY` and value of your NuGet API key. The API key should be authorized to push a NuGet package with the given identifier. 53 | 54 | From there, after [creating a GitHub release](https://docs.github.com/repositories/releasing-projects-on-github/managing-releases-in-a-repository) your plugin will be automatically released on NuGet! -------------------------------------------------------------------------------- /nuget.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidortinau/Plugin.Maui.KeyListener/fd70c26550322f64e96a2bc469274445cbe74691/nuget.png -------------------------------------------------------------------------------- /samples/Plugin.Maui.KeyListener.Sample.sln: -------------------------------------------------------------------------------- 1 | Microsoft Visual Studio Solution File, Format Version 12.00 2 | # Visual Studio Version 17 3 | VisualStudioVersion = 17.0.31611.283 4 | MinimumVisualStudioVersion = 10.0.40219.1 5 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Plugin.Maui.KeyListener.Sample", "Plugin.Maui.KeyListener.Sample\Plugin.Maui.KeyListener.Sample.csproj", "{490BB138-9606-4FFF-8AAD-841C5B1ED059}" 6 | EndProject 7 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Plugin.Maui.KeyListener", "..\src\Plugin.Maui.KeyListener\Plugin.Maui.KeyListener.csproj", "{B60F3174-E978-4F2B-B117-F6F0327594C8}" 8 | 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|Any CPU = Debug|Any CPU 13 | Release|Any CPU = Release|Any CPU 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {490BB138-9606-4FFF-8AAD-841C5B1ED059}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 17 | {490BB138-9606-4FFF-8AAD-841C5B1ED059}.Debug|Any CPU.Build.0 = Debug|Any CPU 18 | {490BB138-9606-4FFF-8AAD-841C5B1ED059}.Debug|Any CPU.Deploy.0 = Debug|Any CPU 19 | {490BB138-9606-4FFF-8AAD-841C5B1ED059}.Release|Any CPU.ActiveCfg = Release|Any CPU 20 | {490BB138-9606-4FFF-8AAD-841C5B1ED059}.Release|Any CPU.Build.0 = Release|Any CPU 21 | {490BB138-9606-4FFF-8AAD-841C5B1ED059}.Release|Any CPU.Deploy.0 = Release|Any CPU 22 | {B60F3174-E978-4F2B-B117-F6F0327594C8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 23 | {B60F3174-E978-4F2B-B117-F6F0327594C8}.Debug|Any CPU.Build.0 = Debug|Any CPU 24 | {B60F3174-E978-4F2B-B117-F6F0327594C8}.Release|Any CPU.ActiveCfg = Release|Any CPU 25 | {B60F3174-E978-4F2B-B117-F6F0327594C8}.Release|Any CPU.Build.0 = Release|Any CPU 26 | EndGlobalSection 27 | GlobalSection(SolutionProperties) = preSolution 28 | HideSolutionNode = FALSE 29 | EndGlobalSection 30 | GlobalSection(ExtensibilityGlobals) = postSolution 31 | SolutionGuid = {61F7FB11-1E47-470C-91E2-47F8143E1572} 32 | EndGlobalSection 33 | EndGlobal 34 | -------------------------------------------------------------------------------- /samples/Plugin.Maui.KeyListener.Sample/App.xaml: -------------------------------------------------------------------------------- 1 |  2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /samples/Plugin.Maui.KeyListener.Sample/App.xaml.cs: -------------------------------------------------------------------------------- 1 | namespace Plugin.Maui.KeyListener.Sample; 2 | 3 | public partial class App : Application 4 | { 5 | public App() 6 | { 7 | InitializeComponent(); 8 | 9 | } 10 | 11 | protected override Window CreateWindow(IActivationState activationState) 12 | { 13 | var shell = new AppShell(); 14 | return new Window(shell); 15 | } 16 | } -------------------------------------------------------------------------------- /samples/Plugin.Maui.KeyListener.Sample/AppShell.xaml: -------------------------------------------------------------------------------- 1 |  2 | 8 | 9 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /samples/Plugin.Maui.KeyListener.Sample/AppShell.xaml.cs: -------------------------------------------------------------------------------- 1 | namespace Plugin.Maui.KeyListener.Sample; 2 | 3 | public partial class AppShell : Shell 4 | { 5 | public AppShell() 6 | { 7 | InitializeComponent(); 8 | } 9 | } -------------------------------------------------------------------------------- /samples/Plugin.Maui.KeyListener.Sample/MainPage.xaml: -------------------------------------------------------------------------------- 1 |  2 | 6 | 7 | 8 | 9 |