From b8854e97a12e9328066cbccc8e8639d772be5cb6 Mon Sep 17 00:00:00 2001 From: Visual-Vincent Date: Tue, 18 Jan 2022 20:23:22 +0100 Subject: [PATCH] Added support for .NET Core --- .gitattributes | 21 - .gitignore | 688 +++++---- .../InputHelper .NET 3.5/Enumerations.vb | 71 - .../EventArgs/KeyboardHookEventArgs.vb | 140 -- .../Hooks/KeyboardHook.vb | 175 --- .../InputHelper .NET 3.5/Hooks/MouseHook.vb | 252 --- .../Input Handling/Keyboard.vb | 154 -- .../InputHelper .NET 3.5.vbproj | 131 -- .../InputHelper .NET 3.5/Internal.vb | 112 -- .../InputHelper .NET 3.5/LICENSE.txt | 38 - .../My Project/Application.Designer.vb | 13 - .../My Project/Application.myapp | 10 - .../My Project/AssemblyInfo.vb | 38 - .../My Project/Resources.Designer.vb | 63 - .../My Project/Resources.resx | 117 -- .../My Project/Settings.Designer.vb | 73 - .../My Project/Settings.settings | 7 - .../InputHelper .NET 3.5/NativeMethods.vb | 508 ------ .../InputHelper .NET 4.x/Constants.vb | 69 - .../EventArgs/MouseEventArgs.vb | 152 -- .../Hooks/Enumerations.vb | 51 - .../Hooks/LocalKeyboardHook.vb | 170 --- .../Input Handling/Mouse.vb | 164 -- .../Input Handling/WindowMessages.vb | 679 -------- .../InputHelper .NET 4.x.vbproj | 131 -- .../InputHelper .NET 4.x/LICENSE.txt | 38 - .../My Project/Application.Designer.vb | 13 - .../My Project/Application.myapp | 10 - .../My Project/AssemblyInfo.vb | 38 - .../My Project/Resources.Designer.vb | 63 - .../My Project/Resources.resx | 117 -- .../My Project/Settings.Designer.vb | 73 - .../My Project/Settings.settings | 7 - InputHelper Library/InputHelper Library.sln | 26 - InputHelper.sln | 25 + InputHelper/AssemblyInfo.vb | 9 + .../Constants.vb | 138 +- .../Enumerations.vb | 140 +- .../EventArgs/KeyboardHookEventArgs.vb | 275 ++-- .../EventArgs/MouseEventArgs.vb | 300 ++-- .../Hooks/Enumerations.vb | 100 +- .../Hooks/KeyboardHook.vb | 348 ++--- .../Hooks/LocalKeyboardHook.vb | 338 ++-- .../Hooks/MouseHook.vb | 502 +++--- .../Input Handling/Keyboard.vb | 306 ++-- .../Input Handling/Mouse.vb | 326 ++-- .../Input Handling/WindowMessages.vb | 1360 +++++++++-------- InputHelper/InputHelper.vbproj | 17 + .../Internal.vb | 224 +-- .../NativeMethods.vb | 1016 ++++++------ LICENSE | 58 +- README.md | 32 +- 52 files changed, 3182 insertions(+), 6744 deletions(-) delete mode 100644 .gitattributes delete mode 100644 InputHelper Library/InputHelper .NET 3.5/Enumerations.vb delete mode 100644 InputHelper Library/InputHelper .NET 3.5/EventArgs/KeyboardHookEventArgs.vb delete mode 100644 InputHelper Library/InputHelper .NET 3.5/Hooks/KeyboardHook.vb delete mode 100644 InputHelper Library/InputHelper .NET 3.5/Hooks/MouseHook.vb delete mode 100644 InputHelper Library/InputHelper .NET 3.5/Input Handling/Keyboard.vb delete mode 100644 InputHelper Library/InputHelper .NET 3.5/InputHelper .NET 3.5.vbproj delete mode 100644 InputHelper Library/InputHelper .NET 3.5/Internal.vb delete mode 100644 InputHelper Library/InputHelper .NET 3.5/LICENSE.txt delete mode 100644 InputHelper Library/InputHelper .NET 3.5/My Project/Application.Designer.vb delete mode 100644 InputHelper Library/InputHelper .NET 3.5/My Project/Application.myapp delete mode 100644 InputHelper Library/InputHelper .NET 3.5/My Project/AssemblyInfo.vb delete mode 100644 InputHelper Library/InputHelper .NET 3.5/My Project/Resources.Designer.vb delete mode 100644 InputHelper Library/InputHelper .NET 3.5/My Project/Resources.resx delete mode 100644 InputHelper Library/InputHelper .NET 3.5/My Project/Settings.Designer.vb delete mode 100644 InputHelper Library/InputHelper .NET 3.5/My Project/Settings.settings delete mode 100644 InputHelper Library/InputHelper .NET 3.5/NativeMethods.vb delete mode 100644 InputHelper Library/InputHelper .NET 4.x/Constants.vb delete mode 100644 InputHelper Library/InputHelper .NET 4.x/EventArgs/MouseEventArgs.vb delete mode 100644 InputHelper Library/InputHelper .NET 4.x/Hooks/Enumerations.vb delete mode 100644 InputHelper Library/InputHelper .NET 4.x/Hooks/LocalKeyboardHook.vb delete mode 100644 InputHelper Library/InputHelper .NET 4.x/Input Handling/Mouse.vb delete mode 100644 InputHelper Library/InputHelper .NET 4.x/Input Handling/WindowMessages.vb delete mode 100644 InputHelper Library/InputHelper .NET 4.x/InputHelper .NET 4.x.vbproj delete mode 100644 InputHelper Library/InputHelper .NET 4.x/LICENSE.txt delete mode 100644 InputHelper Library/InputHelper .NET 4.x/My Project/Application.Designer.vb delete mode 100644 InputHelper Library/InputHelper .NET 4.x/My Project/Application.myapp delete mode 100644 InputHelper Library/InputHelper .NET 4.x/My Project/AssemblyInfo.vb delete mode 100644 InputHelper Library/InputHelper .NET 4.x/My Project/Resources.Designer.vb delete mode 100644 InputHelper Library/InputHelper .NET 4.x/My Project/Resources.resx delete mode 100644 InputHelper Library/InputHelper .NET 4.x/My Project/Settings.Designer.vb delete mode 100644 InputHelper Library/InputHelper .NET 4.x/My Project/Settings.settings delete mode 100644 InputHelper Library/InputHelper Library.sln create mode 100644 InputHelper.sln create mode 100644 InputHelper/AssemblyInfo.vb rename {InputHelper Library/InputHelper .NET 3.5 => InputHelper}/Constants.vb (96%) rename {InputHelper Library/InputHelper .NET 4.x => InputHelper}/Enumerations.vb (96%) rename {InputHelper Library/InputHelper .NET 4.x => InputHelper}/EventArgs/KeyboardHookEventArgs.vb (97%) rename {InputHelper Library/InputHelper .NET 3.5 => InputHelper}/EventArgs/MouseEventArgs.vb (97%) rename {InputHelper Library/InputHelper .NET 3.5 => InputHelper}/Hooks/Enumerations.vb (96%) rename {InputHelper Library/InputHelper .NET 4.x => InputHelper}/Hooks/KeyboardHook.vb (97%) rename {InputHelper Library/InputHelper .NET 3.5 => InputHelper}/Hooks/LocalKeyboardHook.vb (97%) rename {InputHelper Library/InputHelper .NET 4.x => InputHelper}/Hooks/MouseHook.vb (97%) rename {InputHelper Library/InputHelper .NET 4.x => InputHelper}/Input Handling/Keyboard.vb (97%) rename {InputHelper Library/InputHelper .NET 3.5 => InputHelper}/Input Handling/Mouse.vb (97%) rename {InputHelper Library/InputHelper .NET 3.5 => InputHelper}/Input Handling/WindowMessages.vb (95%) create mode 100644 InputHelper/InputHelper.vbproj rename {InputHelper Library/InputHelper .NET 4.x => InputHelper}/Internal.vb (97%) rename {InputHelper Library/InputHelper .NET 4.x => InputHelper}/NativeMethods.vb (97%) diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 7c25101..0000000 --- a/.gitattributes +++ /dev/null @@ -1,21 +0,0 @@ -# Auto detect text files and perform LF normalization -* text eol=crlf - -# Custom for Visual Studio -*.cs diff=csharp - -# Standard to msysgit -*.doc diff=astextplain -*.DOC diff=astextplain -*.docx diff=astextplain -*.DOCX diff=astextplain -*.dot diff=astextplain -*.DOT diff=astextplain -*.pdf diff=astextplain -*.PDF diff=astextplain -*.rtf diff=astextplain -*.RTF diff=astextplain - -*.md export-ignore -*.gitignore export-ignore -*.gitattributes export-ignore \ No newline at end of file diff --git a/.gitignore b/.gitignore index e667e69..a2407b2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,290 +1,398 @@ -## Ignore Visual Studio temporary files, build results, and -## files generated by popular Visual Studio add-ons. -## -## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore - -# User-specific files -*.suo -*.user -*.userosscache -*.sln.docstates - -# User-specific files (MonoDevelop/Xamarin Studio) -*.userprefs - -# Build results -[Dd]ebug/ -[Dd]ebugPublic/ -[Rr]elease/ -[Rr]eleases/ -x64/ -x86/ -bld/ -[Bb]in/ -[Oo]bj/ -[Ll]og/ - -# Visual Studio 2015 cache/options directory -.vs/ -# Uncomment if you have tasks that create the project's static files in wwwroot -#wwwroot/ - -# MSTest test Results -[Tt]est[Rr]esult*/ -[Bb]uild[Ll]og.* - -# NUNIT -*.VisualState.xml -TestResult.xml - -# Build Results of an ATL Project -[Dd]ebugPS/ -[Rr]eleasePS/ -dlldata.c - -# .NET Core -project.lock.json -project.fragment.lock.json -artifacts/ -**/Properties/launchSettings.json - -*_i.c -*_p.c -*_i.h -*.ilk -*.meta -*.obj -*.pch -*.pdb -*.pgc -*.pgd -*.rsp -*.sbr -*.tlb -*.tli -*.tlh -*.tmp -*.tmp_proj -*.log -*.vspscc -*.vssscc -.builds -*.pidb -*.svclog -*.scc - -# Chutzpah Test files -_Chutzpah* - -# Visual C++ cache files -ipch/ -*.aps -*.ncb -*.opendb -*.opensdf -*.sdf -*.cachefile -*.VC.db -*.VC.VC.opendb - -# Visual Studio profiler -*.psess -*.vsp -*.vspx -*.sap - -# TFS 2012 Local Workspace -$tf/ - -# Guidance Automation Toolkit -*.gpState - -# ReSharper is a .NET coding add-in -_ReSharper*/ -*.[Rr]e[Ss]harper -*.DotSettings.user - -# JustCode is a .NET coding add-in -.JustCode - -# TeamCity is a build add-in -_TeamCity* - -# DotCover is a Code Coverage Tool -*.dotCover - -# Visual Studio code coverage results -*.coverage -*.coveragexml - -# NCrunch -_NCrunch_* -.*crunch*.local.xml -nCrunchTemp_* - -# MightyMoose -*.mm.* -AutoTest.Net/ - -# Web workbench (sass) -.sass-cache/ - -# Installshield output folder -[Ee]xpress/ - -# DocProject is a documentation generator add-in -DocProject/buildhelp/ -DocProject/Help/*.HxT -DocProject/Help/*.HxC -DocProject/Help/*.hhc -DocProject/Help/*.hhk -DocProject/Help/*.hhp -DocProject/Help/Html2 -DocProject/Help/html - -# Click-Once directory -publish/ - -# Publish Web Output -*.[Pp]ublish.xml -*.azurePubxml -# TODO: Comment the next line if you want to checkin your web deploy settings -# but database connection strings (with potential passwords) will be unencrypted -*.pubxml -*.publishproj - -# Microsoft Azure Web App publish settings. Comment the next line if you want to -# checkin your Azure Web App publish settings, but sensitive information contained -# in these scripts will be unencrypted -PublishScripts/ - -# NuGet Packages -*.nupkg -# The packages folder can be ignored because of Package Restore -**/packages/* -# except build/, which is used as an MSBuild target. -!**/packages/build/ -# Uncomment if necessary however generally it will be regenerated when needed -#!**/packages/repositories.config -# NuGet v3's project.json files produces more ignorable files -*.nuget.props -*.nuget.targets - -# Microsoft Azure Build Output -csx/ -*.build.csdef - -# Microsoft Azure Emulator -ecf/ -rcf/ - -# Windows Store app package directories and files -AppPackages/ -BundleArtifacts/ -Package.StoreAssociation.xml -_pkginfo.txt - -# Visual Studio cache files -# files ending in .cache can be ignored -*.[Cc]ache -# but keep track of directories ending in .cache -!*.[Cc]ache/ - -# Others -ClientBin/ -~$* -*~ -*.dbmdl -*.dbproj.schemaview -*.jfm -*.pfx -*.publishsettings -orleans.codegen.cs - -# Since there are multiple workflows, uncomment next line to ignore bower_components -# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) -#bower_components/ - -# RIA/Silverlight projects -Generated_Code/ - -# Backup & report files from converting an old project file -# to a newer Visual Studio version. Backup files are not needed, -# because we have git ;-) -_UpgradeReport_Files/ -Backup*/ -UpgradeLog*.XML -UpgradeLog*.htm - -# SQL Server files -*.mdf -*.ldf -*.ndf - -# Business Intelligence projects -*.rdl.data -*.bim.layout -*.bim_*.settings - -# Microsoft Fakes -FakesAssemblies/ - -# GhostDoc plugin setting file -*.GhostDoc.xml - -# Node.js Tools for Visual Studio -.ntvs_analysis.dat -node_modules/ - -# Typescript v1 declaration files -typings/ - -# Visual Studio 6 build log -*.plg - -# Visual Studio 6 workspace options file -*.opt - -# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) -*.vbw - -# Visual Studio LightSwitch build output -**/*.HTMLClient/GeneratedArtifacts -**/*.DesktopClient/GeneratedArtifacts -**/*.DesktopClient/ModelManifest.xml -**/*.Server/GeneratedArtifacts -**/*.Server/ModelManifest.xml -_Pvt_Extensions - -# Paket dependency manager -.paket/paket.exe -paket-files/ - -# FAKE - F# Make -.fake/ - -# JetBrains Rider -.idea/ -*.sln.iml - -# CodeRush -.cr/ - -# Python Tools for Visual Studio (PTVS) -__pycache__/ -*.pyc - -# Cake - Uncomment if you are using it -# tools/** -# !tools/packages.config - -# Telerik's JustMock configuration file -*.jmconfig - -# BizTalk build output -*.btp.cs -*.btm.cs -*.odx.cs -*.xsd.cs -InputHelper Library/InputHelper Library/FileVersionAppender.exe -InputHelper Library/InputHelper Library/PreBuildAction.bat +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. +## +## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore + +# User-specific files +*.rsuser +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Mono auto generated files +mono_crash.* + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +[Ww][Ii][Nn]32/ +[Aa][Rr][Mm]/ +[Aa][Rr][Mm]64/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ +[Ll]ogs/ + +# Visual Studio 2015/2017 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# Visual Studio 2017 auto generated files +Generated\ Files/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUnit +*.VisualState.xml +TestResult.xml +nunit-*.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# Benchmark Results +BenchmarkDotNet.Artifacts/ + +# .NET Core +project.lock.json +project.fragment.lock.json +artifacts/ + +# ASP.NET Scaffolding +ScaffoldingReadMe.txt + +# StyleCop +StyleCopReport.xml + +# Files built by Visual Studio +*_i.c +*_p.c +*_h.h +*.ilk +*.meta +*.obj +*.iobj +*.pch +*.pdb +*.ipdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*_wpftmp.csproj +*.log +*.tlog +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# Visual Studio Trace Files +*.e2e + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# Coverlet is a free, cross platform Code Coverage Tool +coverage*.json +coverage*.xml +coverage*.info + +# Visual Studio code coverage results +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# Note: Comment the next line if you want to checkin your web deploy settings, +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# NuGet Symbol Packages +*.snupkg +# The packages folder can be ignored because of Package Restore +**/[Pp]ackages/* +# except build/, which is used as an MSBuild target. +!**/[Pp]ackages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/[Pp]ackages/repositories.config +# NuGet v3's project.json files produces more ignorable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt +*.appx +*.appxbundle +*.appxupload + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!?*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +orleans.codegen.cs + +# Including strong name files can present a security risk +# (https://github.com/github/gitignore/pull/2483#issue-259490424) +#*.snk + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm +ServiceFabricBackup/ +*.rptproj.bak + +# SQL Server files +*.mdf +*.ldf +*.ndf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings +*.rptproj.rsuser +*- [Bb]ackup.rdl +*- [Bb]ackup ([0-9]).rdl +*- [Bb]ackup ([0-9][0-9]).rdl + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat +node_modules/ + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio 6 auto-generated project file (contains which files were open etc.) +*.vbp + +# Visual Studio 6 workspace and project file (working project files containing files to include in project) +*.dsw +*.dsp + +# Visual Studio 6 technical files +*.ncb +*.aps + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# CodeRush personal settings +.cr/personal + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config + +# Tabs Studio +*.tss + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs + +# OpenCover UI analysis results +OpenCover/ + +# Azure Stream Analytics local run output +ASALocalRun/ + +# MSBuild Binary and Structured Log +*.binlog + +# NVidia Nsight GPU debugger configuration file +*.nvuser + +# MFractors (Xamarin productivity tool) working folder +.mfractor/ + +# Local History for Visual Studio +.localhistory/ + +# Visual Studio History (VSHistory) files +.vshistory/ + +# BeatPulse healthcheck temp database +healthchecksdb + +# Backup folder for Package Reference Convert tool in Visual Studio 2017 +MigrationBackup/ + +# Ionide (cross platform F# VS Code tools) working folder +.ionide/ + +# Fody - auto-generated XML schema +FodyWeavers.xsd + +# VS Code files for those working on multiple tools +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +*.code-workspace + +# Local History for Visual Studio Code +.history/ + +# Windows Installer files from build outputs +*.cab +*.msi +*.msix +*.msm +*.msp + +# JetBrains Rider +*.sln.iml \ No newline at end of file diff --git a/InputHelper Library/InputHelper .NET 3.5/Enumerations.vb b/InputHelper Library/InputHelper .NET 3.5/Enumerations.vb deleted file mode 100644 index a91de36..0000000 --- a/InputHelper Library/InputHelper .NET 3.5/Enumerations.vb +++ /dev/null @@ -1,71 +0,0 @@ -'+---------------------------------------------------------------------------------+' -'| === InputHelper === |' -'| |' -'| Created by Vincent "Visual Vincent" Bengtsson |' -'| Website: https://www.mydoomsite.com/ |' -'| GitHub: https://github.com/Visual-Vincent |' -'| |' -'| |' -'| === COPYRIGHT LICENSE === |' -'| |' -'| Copyright (c) 2016-2019, Vincent Bengtsson |' -'| All rights reserved. |' -'| |' -'| Redistribution and use in source and binary forms, with or without |' -'| modification, are permitted provided that the following conditions are met: |' -'| |' -'| 1. Redistributions of source code must retain the above copyright notice, this |' -'| list of conditions and the following disclaimer. |' -'| |' -'| 2. Redistributions in binary form must reproduce the above copyright notice, |' -'| this list of conditions and the following disclaimer in the documentation |' -'| and/or other materials provided with the distribution. |' -'| |' -'| 3. Neither the name of the copyright holder nor the names of its |' -'| contributors may be used to endorse or promote products derived from |' -'| this software without specific prior written permission. |' -'| |' -'| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |' -'| AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |' -'| IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |' -'| DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |' -'| FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |' -'| DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |' -'| SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |' -'| CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |' -'| OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |' -'| OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |' -'+---------------------------------------------------------------------------------+' - - _ -Public Enum ModifierKeys As Integer - ''' - ''' No modifiers specified. - ''' - ''' - None = 0 - - ''' - ''' The CTRL modifier key. - ''' - ''' - Control = 1 - - ''' - ''' The SHIFT modifier key. - ''' - ''' - Shift = 2 - - ''' - ''' The ALT modifier key. - ''' - ''' - Alt = 4 - - ''' - ''' The Windows modifier key. - ''' - ''' - Windows = 8 -End Enum \ No newline at end of file diff --git a/InputHelper Library/InputHelper .NET 3.5/EventArgs/KeyboardHookEventArgs.vb b/InputHelper Library/InputHelper .NET 3.5/EventArgs/KeyboardHookEventArgs.vb deleted file mode 100644 index 95b9305..0000000 --- a/InputHelper Library/InputHelper .NET 3.5/EventArgs/KeyboardHookEventArgs.vb +++ /dev/null @@ -1,140 +0,0 @@ -'+---------------------------------------------------------------------------------+' -'| === InputHelper === |' -'| |' -'| Created by Vincent "Visual Vincent" Bengtsson |' -'| Website: https://www.mydoomsite.com/ |' -'| GitHub: https://github.com/Visual-Vincent |' -'| |' -'| |' -'| === COPYRIGHT LICENSE === |' -'| |' -'| Copyright (c) 2016-2019, Vincent Bengtsson |' -'| All rights reserved. |' -'| |' -'| Redistribution and use in source and binary forms, with or without |' -'| modification, are permitted provided that the following conditions are met: |' -'| |' -'| 1. Redistributions of source code must retain the above copyright notice, this |' -'| list of conditions and the following disclaimer. |' -'| |' -'| 2. Redistributions in binary form must reproduce the above copyright notice, |' -'| this list of conditions and the following disclaimer in the documentation |' -'| and/or other materials provided with the distribution. |' -'| |' -'| 3. Neither the name of the copyright holder nor the names of its |' -'| contributors may be used to endorse or promote products derived from |' -'| this software without specific prior written permission. |' -'| |' -'| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |' -'| AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |' -'| IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |' -'| DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |' -'| FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |' -'| DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |' -'| SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |' -'| CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |' -'| OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |' -'| OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |' -'+---------------------------------------------------------------------------------+' - -Imports System.Drawing -Imports System.Windows.Forms -Imports System.Runtime.InteropServices -Imports System.ComponentModel -Imports InputHelper.Hooks - -Namespace EventArgs - Public Class KeyboardHookEventArgs - Inherits System.EventArgs - - Private _extended As Boolean - Private _keyCode As Keys - Private _keyState As KeyState - Private _modifiers As ModifierKeys - Private _scanCode As UInteger - - ''' - ''' Gets or sets a boolean value indicating whether the keystroke should be blocked from reaching any windows. - ''' - ''' - Public Property Block As Boolean = False - - ''' - ''' Gets a boolean value indicating whether the keystroke message originated from one of the additional keys on the enhanced keyboard - ''' (see: https://msdn.microsoft.com/en-us/library/windows/desktop/ms646267(v=vs.85).aspx#_win32_Keystroke_Message_Flags). - ''' - ''' - Public ReadOnly Property Extended As Boolean - Get - Return _extended - End Get - End Property - - ''' - ''' Gets the keyboard code of the key that generated the keystroke. - ''' - ''' - Public ReadOnly Property KeyCode As Keys - Get - Return _keyCode - End Get - End Property - - ''' - ''' Gets the current state of the key that generated the keystroke. - ''' - ''' - Public ReadOnly Property KeyState As KeyState - Get - Return _keyState - End Get - End Property - - ''' - ''' Gets the modifier keys that was pressed in combination with the keystroke. - ''' - ''' - Public ReadOnly Property Modifiers As ModifierKeys - Get - Return _modifiers - End Get - End Property - - ''' - ''' Gets the hardware scan code of the key that generated the keystroke. - ''' - ''' - Public ReadOnly Property ScanCode As UInteger - Get - Return _scanCode - End Get - End Property - - Public Overrides Function ToString() As String - Return String.Format("{{KeyCode: {0}, ScanCode: {1}, Extended: {2}, KeyState: {3}, Modifiers: {4}}}", _ - Me.KeyCode, Me.ScanCode, Me.Extended, Me.KeyState, Me.Modifiers) - End Function - - ''' - ''' Initializes a new instance of the KeyboardHookEventArgs class. - ''' - ''' The keyboard code of the key that generated the keystroke. - ''' The hardware scan code of the key that generated the keystroke. - ''' Whether the keystroke message originated from one of the additional keys on the enhanced keyboard - ''' (see: https://msdn.microsoft.com/en-us/library/windows/desktop/ms646267(v=vs.85).aspx#_win32_Keystroke_Message_Flags). - ''' The current state of the key that generated the keystroke. - ''' The modifier keys that was pressed in combination with the keystroke. - ''' - Public Sub New(ByVal KeyCode As Keys, _ - ByVal ScanCode As UInteger, _ - ByVal Extended As Boolean, _ - ByVal KeyState As KeyState, _ - ByVal Modifiers As ModifierKeys) - Me._keyCode = KeyCode - Me._scanCode = ScanCode - Me._extended = Extended - Me._keyState = KeyState - Me._modifiers = Modifiers - End Sub - End Class -End Namespace \ No newline at end of file diff --git a/InputHelper Library/InputHelper .NET 3.5/Hooks/KeyboardHook.vb b/InputHelper Library/InputHelper .NET 3.5/Hooks/KeyboardHook.vb deleted file mode 100644 index d231ec7..0000000 --- a/InputHelper Library/InputHelper .NET 3.5/Hooks/KeyboardHook.vb +++ /dev/null @@ -1,175 +0,0 @@ -'+---------------------------------------------------------------------------------+' -'| === InputHelper === |' -'| |' -'| Created by Vincent "Visual Vincent" Bengtsson |' -'| Website: https://www.mydoomsite.com/ |' -'| GitHub: https://github.com/Visual-Vincent |' -'| |' -'| |' -'| === COPYRIGHT LICENSE === |' -'| |' -'| Copyright (c) 2016-2019, Vincent Bengtsson |' -'| All rights reserved. |' -'| |' -'| Redistribution and use in source and binary forms, with or without |' -'| modification, are permitted provided that the following conditions are met: |' -'| |' -'| 1. Redistributions of source code must retain the above copyright notice, this |' -'| list of conditions and the following disclaimer. |' -'| |' -'| 2. Redistributions in binary form must reproduce the above copyright notice, |' -'| this list of conditions and the following disclaimer in the documentation |' -'| and/or other materials provided with the distribution. |' -'| |' -'| 3. Neither the name of the copyright holder nor the names of its |' -'| contributors may be used to endorse or promote products derived from |' -'| this software without specific prior written permission. |' -'| |' -'| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |' -'| AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |' -'| IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |' -'| DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |' -'| FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |' -'| DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |' -'| SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |' -'| CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |' -'| OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |' -'| OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |' -'+---------------------------------------------------------------------------------+' - -Imports System.Windows.Forms -Imports System.Runtime.InteropServices -Imports System.ComponentModel -Imports InputHelper.EventArgs - -Namespace Hooks - ''' - ''' A global low-level keyboard hook that raises events when a key is pressed or released. - ''' - ''' - Public NotInheritable Class KeyboardHook - Implements IDisposable - - ''' - ''' Occurs when a key is pressed or held down. - ''' - ''' - Public Event KeyDown As EventHandler(Of KeyboardHookEventArgs) - - ''' - ''' Occurs when a key is released. - ''' - ''' - Public Event KeyUp As EventHandler(Of KeyboardHookEventArgs) - - Private hHook As IntPtr = IntPtr.Zero - Private HookProcedureDelegate As New NativeMethods.LowLevelKeyboardProc(AddressOf HookCallback) - - Private Modifiers As ModifierKeys = ModifierKeys.None - - Private Function HookCallback(ByVal nCode As Integer, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr - Dim Block As Boolean = False - - If nCode >= NativeMethods.HookCode.HC_ACTION AndAlso _ - (wParam = NativeMethods.KeyMessage.WM_KEYDOWN OrElse _ - wParam = NativeMethods.KeyMessage.WM_KEYUP OrElse _ - wParam = NativeMethods.KeyMessage.WM_SYSKEYDOWN OrElse _ - wParam = NativeMethods.KeyMessage.WM_SYSKEYUP) Then - - Dim KeystrokeInfo As NativeMethods.KBDLLHOOKSTRUCT = _ - CType(Marshal.PtrToStructure(lParam, GetType(NativeMethods.KBDLLHOOKSTRUCT)), NativeMethods.KBDLLHOOKSTRUCT) - - Select Case wParam - - Case NativeMethods.KeyMessage.WM_KEYDOWN, NativeMethods.KeyMessage.WM_SYSKEYDOWN - Dim HookEventArgs As KeyboardHookEventArgs = Me.CreateEventArgs(True, KeystrokeInfo) - - If Internal.IsModifier(HookEventArgs.KeyCode, ModifierKeys.Control) = True Then Me.Modifiers = Me.Modifiers Or ModifierKeys.Control - If Internal.IsModifier(HookEventArgs.KeyCode, ModifierKeys.Shift) = True Then Me.Modifiers = Me.Modifiers Or ModifierKeys.Shift - If Internal.IsModifier(HookEventArgs.KeyCode, ModifierKeys.Alt) = True Then Me.Modifiers = Me.Modifiers Or ModifierKeys.Alt - If Internal.IsModifier(HookEventArgs.KeyCode, ModifierKeys.Windows) = True Then Me.Modifiers = Me.Modifiers Or ModifierKeys.Windows - - RaiseEvent KeyDown(Me, HookEventArgs) - Block = HookEventArgs.Block - - Case NativeMethods.KeyMessage.WM_KEYUP, NativeMethods.KeyMessage.WM_SYSKEYUP - Dim KeyCode As Keys = CType(KeystrokeInfo.vkCode And Integer.MaxValue, Keys) - - 'Must be done before creating the HookEventArgs during KeyUp. - If Internal.IsModifier(KeyCode, ModifierKeys.Control) = True Then Me.Modifiers = Me.Modifiers And Not ModifierKeys.Control - If Internal.IsModifier(KeyCode, ModifierKeys.Shift) = True Then Me.Modifiers = Me.Modifiers And Not ModifierKeys.Shift - If Internal.IsModifier(KeyCode, ModifierKeys.Alt) = True Then Me.Modifiers = Me.Modifiers And Not ModifierKeys.Alt - If Internal.IsModifier(KeyCode, ModifierKeys.Windows) = True Then Me.Modifiers = Me.Modifiers And Not ModifierKeys.Windows - - Dim HookEventArgs As KeyboardHookEventArgs = Me.CreateEventArgs(False, KeystrokeInfo) - - RaiseEvent KeyUp(Me, HookEventArgs) - Block = HookEventArgs.Block - - End Select - End If - - Return If(Block, New IntPtr(1), NativeMethods.CallNextHookEx(hHook, nCode, wParam, lParam)) - End Function - - Private Function CreateEventArgs(ByVal KeyDown As Boolean, ByVal KeystrokeInfo As NativeMethods.KBDLLHOOKSTRUCT) As KeyboardHookEventArgs - Dim KeyCode As Keys = CType(KeystrokeInfo.vkCode And Integer.MaxValue, Keys) - Dim ScanCode As UInteger = KeystrokeInfo.scanCode - Dim Extended As Boolean = (KeystrokeInfo.flags And NativeMethods.LowLevelKeyboardHookFlags.LLKHF_EXTENDED) = NativeMethods.LowLevelKeyboardHookFlags.LLKHF_EXTENDED - Dim AltDown As Boolean = (KeystrokeInfo.flags And NativeMethods.LowLevelKeyboardHookFlags.LLKHF_ALTDOWN) = NativeMethods.LowLevelKeyboardHookFlags.LLKHF_ALTDOWN - - If AltDown = True _ - AndAlso Internal.IsModifier(KeyCode, ModifierKeys.Alt) = False _ - AndAlso (Me.Modifiers And ModifierKeys.Alt) <> ModifierKeys.Alt Then - - Me.Modifiers = Me.Modifiers Or ModifierKeys.Alt - End If - - Return New KeyboardHookEventArgs(KeyCode, ScanCode, Extended, If(KeyDown, KeyState.Down, KeyState.Up), Me.Modifiers) - End Function - - ''' - ''' Initializes a new instance of the KeyboardHook class. - ''' - ''' - Public Sub New() - hHook = NativeMethods.SetWindowsHookEx(NativeMethods.HookType.WH_KEYBOARD_LL, HookProcedureDelegate, NativeMethods.GetModuleHandle(Nothing), 0) - If hHook = IntPtr.Zero Then - Dim Win32Error As Integer = Marshal.GetLastWin32Error() - Throw New Win32Exception(Win32Error, "Failed to create keyboard hook! (" & Win32Error & ")") - End If - End Sub - -#Region "IDisposable Support" - Private disposedValue As Boolean ' To detect redundant calls - - ' IDisposable - Protected Sub Dispose(disposing As Boolean) - If Not Me.disposedValue Then - If disposing Then - ' TODO: dispose managed state (managed objects). - End If - - ' TODO: free unmanaged resources (unmanaged objects) and override Finalize() below. - ' TODO: set large fields to null. - If hHook <> IntPtr.Zero Then NativeMethods.UnhookWindowsHookEx(hHook) - End If - Me.disposedValue = True - End Sub - - Protected Overrides Sub Finalize() - ' Do not change this code. Put cleanup code in Dispose(ByVal disposing As Boolean) above. - Dispose(False) - MyBase.Finalize() - End Sub - - ' This code added by Visual Basic to correctly implement the disposable pattern. - Public Sub Dispose() Implements IDisposable.Dispose - ' Do not change this code. Put cleanup code in Dispose(ByVal disposing As Boolean) above. - Dispose(True) - GC.SuppressFinalize(Me) - End Sub -#End Region - - End Class -End Namespace \ No newline at end of file diff --git a/InputHelper Library/InputHelper .NET 3.5/Hooks/MouseHook.vb b/InputHelper Library/InputHelper .NET 3.5/Hooks/MouseHook.vb deleted file mode 100644 index d708fb3..0000000 --- a/InputHelper Library/InputHelper .NET 3.5/Hooks/MouseHook.vb +++ /dev/null @@ -1,252 +0,0 @@ -'+---------------------------------------------------------------------------------+' -'| === InputHelper === |' -'| |' -'| Created by Vincent "Visual Vincent" Bengtsson |' -'| Website: https://www.mydoomsite.com/ |' -'| GitHub: https://github.com/Visual-Vincent |' -'| |' -'| |' -'| === COPYRIGHT LICENSE === |' -'| |' -'| Copyright (c) 2016-2019, Vincent Bengtsson |' -'| All rights reserved. |' -'| |' -'| Redistribution and use in source and binary forms, with or without |' -'| modification, are permitted provided that the following conditions are met: |' -'| |' -'| 1. Redistributions of source code must retain the above copyright notice, this |' -'| list of conditions and the following disclaimer. |' -'| |' -'| 2. Redistributions in binary form must reproduce the above copyright notice, |' -'| this list of conditions and the following disclaimer in the documentation |' -'| and/or other materials provided with the distribution. |' -'| |' -'| 3. Neither the name of the copyright holder nor the names of its |' -'| contributors may be used to endorse or promote products derived from |' -'| this software without specific prior written permission. |' -'| |' -'| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |' -'| AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |' -'| IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |' -'| DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |' -'| FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |' -'| DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |' -'| SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |' -'| CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |' -'| OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |' -'| OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |' -'+---------------------------------------------------------------------------------+' - -Imports System.Drawing -Imports System.Windows.Forms -Imports System.Runtime.InteropServices -Imports System.ComponentModel -Imports InputHelper.EventArgs - -Namespace Hooks - ''' - ''' A global low-level mouse hook that raises events when a mouse event occurs. - ''' - ''' - Public NotInheritable Class MouseHook - Implements IDisposable - - ''' - ''' Occurs when a mouse button is pressed or held down. - ''' - ''' - Public Event MouseDown As EventHandler(Of MouseHookEventArgs) - - ''' - ''' Occurs when a mouse button is released. - ''' - ''' - Public Event MouseUp As EventHandler(Of MouseHookEventArgs) - - ''' - ''' Occurs when the mouse moves. - ''' - ''' - Public Event MouseMove As EventHandler(Of MouseHookEventArgs) - - ''' - ''' Occurs when the mouse wheel is scrolled. - ''' - ''' - Public Event MouseWheel As EventHandler(Of MouseHookEventArgs) - - Private hHook As IntPtr = IntPtr.Zero - Private HookProcedureDelegate As New NativeMethods.LowLevelMouseProc(AddressOf HookCallback) - - Private LeftClickTimeStamp As Integer = 0 - Private MiddleClickTimeStamp As Integer = 0 - Private RightClickTimeStamp As Integer = 0 - Private X1ClickTimeStamp As Integer = 0 - Private X2ClickTimeStamp As Integer = 0 - - Private Function HookCallback(ByVal nCode As Integer, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr - Dim Block As Boolean = False - - If nCode >= NativeMethods.HookCode.HC_ACTION AndAlso _ - (wParam = NativeMethods.MouseMessage.WM_LBUTTONDOWN OrElse _ - wParam = NativeMethods.MouseMessage.WM_LBUTTONUP OrElse _ - wParam = NativeMethods.MouseMessage.WM_MBUTTONDOWN OrElse _ - wParam = NativeMethods.MouseMessage.WM_MBUTTONUP OrElse _ - wParam = NativeMethods.MouseMessage.WM_RBUTTONDOWN OrElse _ - wParam = NativeMethods.MouseMessage.WM_RBUTTONUP OrElse _ - wParam = NativeMethods.MouseMessage.WM_XBUTTONDOWN OrElse _ - wParam = NativeMethods.MouseMessage.WM_XBUTTONUP OrElse _ - wParam = NativeMethods.MouseMessage.WM_MOUSEWHEEL OrElse _ - wParam = NativeMethods.MouseMessage.WM_MOUSEHWHEEL OrElse _ - wParam = NativeMethods.MouseMessage.WM_MOUSEMOVE) Then - - Dim MouseEventInfo As NativeMethods.MSLLHOOKSTRUCT = _ - CType(Marshal.PtrToStructure(lParam, GetType(NativeMethods.MSLLHOOKSTRUCT)), NativeMethods.MSLLHOOKSTRUCT) - - Select Case wParam - Case NativeMethods.MouseMessage.WM_LBUTTONDOWN - Dim DoubleClick As Boolean = (Environment.TickCount - LeftClickTimeStamp) <= NativeMethods.GetDoubleClickTime() - LeftClickTimeStamp = Environment.TickCount - - Dim HookEventArgs As New MouseHookEventArgs(MouseButtons.Left, KeyState.Down, DoubleClick, _ - New Point(MouseEventInfo.pt.x, MouseEventInfo.pt.y), ScrollDirection.None, 0) - RaiseEvent MouseDown(Me, HookEventArgs) - Block = HookEventArgs.Block - - - Case NativeMethods.MouseMessage.WM_LBUTTONUP - Dim HookEventArgs As New MouseHookEventArgs(MouseButtons.Left, KeyState.Up, False, _ - New Point(MouseEventInfo.pt.x, MouseEventInfo.pt.y), ScrollDirection.None, 0) - RaiseEvent MouseUp(Me, HookEventArgs) - Block = HookEventArgs.Block - - - Case NativeMethods.MouseMessage.WM_MBUTTONDOWN - Dim DoubleClick As Boolean = (Environment.TickCount - MiddleClickTimeStamp) <= NativeMethods.GetDoubleClickTime() - MiddleClickTimeStamp = Environment.TickCount - - Dim HookEventArgs As New MouseHookEventArgs(MouseButtons.Middle, KeyState.Down, DoubleClick, _ - New Point(MouseEventInfo.pt.x, MouseEventInfo.pt.y), ScrollDirection.None, 0) - RaiseEvent MouseDown(Me, HookEventArgs) - Block = HookEventArgs.Block - - - Case NativeMethods.MouseMessage.WM_MBUTTONUP - Dim HookEventArgs As New MouseHookEventArgs(MouseButtons.Middle, KeyState.Up, False, _ - New Point(MouseEventInfo.pt.x, MouseEventInfo.pt.y), ScrollDirection.None, 0) - RaiseEvent MouseUp(Me, HookEventArgs) - Block = HookEventArgs.Block - - - Case NativeMethods.MouseMessage.WM_RBUTTONDOWN - Dim DoubleClick As Boolean = (Environment.TickCount - RightClickTimeStamp) <= NativeMethods.GetDoubleClickTime() - RightClickTimeStamp = Environment.TickCount - - Dim HookEventArgs As New MouseHookEventArgs(MouseButtons.Right, KeyState.Down, DoubleClick, _ - New Point(MouseEventInfo.pt.x, MouseEventInfo.pt.y), ScrollDirection.None, 0) - RaiseEvent MouseDown(Me, HookEventArgs) - Block = HookEventArgs.Block - - - Case NativeMethods.MouseMessage.WM_RBUTTONUP - Dim HookEventArgs As New MouseHookEventArgs(MouseButtons.Right, KeyState.Up, False, _ - New Point(MouseEventInfo.pt.x, MouseEventInfo.pt.y), ScrollDirection.None, 0) - RaiseEvent MouseUp(Me, HookEventArgs) - Block = HookEventArgs.Block - - - Case NativeMethods.MouseMessage.WM_XBUTTONDOWN - Dim IsXButton2 As Boolean = (New NativeMethods.DWORD(MouseEventInfo.mouseData).High = 2) - Dim DoubleClick As Boolean = (Environment.TickCount - If(IsXButton2, X2ClickTimeStamp, X1ClickTimeStamp)) <= NativeMethods.GetDoubleClickTime() - - If IsXButton2 = True Then X2ClickTimeStamp = Environment.TickCount _ - Else X1ClickTimeStamp = Environment.TickCount - - Dim HookEventArgs As New MouseHookEventArgs(If(IsXButton2, MouseButtons.XButton2, MouseButtons.XButton1), KeyState.Down, DoubleClick, _ - New Point(MouseEventInfo.pt.x, MouseEventInfo.pt.y), ScrollDirection.None, 0) - RaiseEvent MouseUp(Me, HookEventArgs) - Block = HookEventArgs.Block - - - Case NativeMethods.MouseMessage.WM_XBUTTONUP - Dim IsXButton2 As Boolean = (New NativeMethods.DWORD(MouseEventInfo.mouseData).High = 2) - Dim HookEventArgs As New MouseHookEventArgs(If(IsXButton2, MouseButtons.XButton2, MouseButtons.XButton1), KeyState.Up, False, _ - New Point(MouseEventInfo.pt.x, MouseEventInfo.pt.y), ScrollDirection.None, 0) - RaiseEvent MouseUp(Me, HookEventArgs) - Block = HookEventArgs.Block - - - Case NativeMethods.MouseMessage.WM_MOUSEWHEEL - Dim Delta As Integer = New NativeMethods.DWORD(MouseEventInfo.mouseData).SignedHigh - Dim HookEventArgs As New MouseHookEventArgs(MouseButtons.None, KeyState.Up, False, _ - New Point(MouseEventInfo.pt.x, MouseEventInfo.pt.y), ScrollDirection.Vertical, Delta) - RaiseEvent MouseWheel(Me, HookEventArgs) - Block = HookEventArgs.Block - - - Case NativeMethods.MouseMessage.WM_MOUSEHWHEEL - Dim Delta As Integer = New NativeMethods.DWORD(MouseEventInfo.mouseData).SignedHigh - Dim HookEventArgs As New MouseHookEventArgs(MouseButtons.None, KeyState.Up, False, _ - New Point(MouseEventInfo.pt.x, MouseEventInfo.pt.y), ScrollDirection.Horizontal, Delta) - RaiseEvent MouseWheel(Me, HookEventArgs) - Block = HookEventArgs.Block - - - Case NativeMethods.MouseMessage.WM_MOUSEMOVE - Dim HookEventArgs As New MouseHookEventArgs(MouseButtons.None, KeyState.Up, False, _ - New Point(MouseEventInfo.pt.x, MouseEventInfo.pt.y), ScrollDirection.None, 0) - RaiseEvent MouseMove(Me, HookEventArgs) - Block = HookEventArgs.Block - - - End Select - End If - - Return If(Block, New IntPtr(1), NativeMethods.CallNextHookEx(hHook, nCode, wParam, lParam)) - End Function - - ''' - ''' Initializes a new instance of the MouseHook clas. - ''' - ''' - Public Sub New() - hHook = NativeMethods.SetWindowsHookEx(NativeMethods.HookType.WH_MOUSE_LL, HookProcedureDelegate, NativeMethods.GetModuleHandle(Nothing), 0) - If hHook = IntPtr.Zero Then - Dim Win32Error As Integer = Marshal.GetLastWin32Error() - Throw New Win32Exception(Win32Error, "Failed to create mouse hook! (" & Win32Error & ")") - End If - End Sub - -#Region "IDisposable Support" - Private disposedValue As Boolean ' To detect redundant calls - - ' IDisposable - Protected Sub Dispose(disposing As Boolean) - If Not Me.disposedValue Then - If disposing Then - ' TODO: dispose managed state (managed objects). - End If - - ' TODO: free unmanaged resources (unmanaged objects) and override Finalize() below. - ' TODO: set large fields to null. - If hHook <> IntPtr.Zero Then NativeMethods.UnhookWindowsHookEx(hHook) - End If - Me.disposedValue = True - End Sub - - Protected Overrides Sub Finalize() - ' Do not change this code. Put cleanup code in Dispose(ByVal disposing As Boolean) above. - Dispose(False) - MyBase.Finalize() - End Sub - - ' This code added by Visual Basic to correctly implement the disposable pattern. - Public Sub Dispose() Implements IDisposable.Dispose - ' Do not change this code. Put cleanup code in Dispose(ByVal disposing As Boolean) above. - Dispose(True) - GC.SuppressFinalize(Me) - End Sub -#End Region - - End Class -End Namespace \ No newline at end of file diff --git a/InputHelper Library/InputHelper .NET 3.5/Input Handling/Keyboard.vb b/InputHelper Library/InputHelper .NET 3.5/Input Handling/Keyboard.vb deleted file mode 100644 index 19e80ad..0000000 --- a/InputHelper Library/InputHelper .NET 3.5/Input Handling/Keyboard.vb +++ /dev/null @@ -1,154 +0,0 @@ -'+---------------------------------------------------------------------------------+' -'| === InputHelper === |' -'| |' -'| Created by Vincent "Visual Vincent" Bengtsson |' -'| Website: https://www.mydoomsite.com/ |' -'| GitHub: https://github.com/Visual-Vincent |' -'| |' -'| |' -'| === COPYRIGHT LICENSE === |' -'| |' -'| Copyright (c) 2016-2019, Vincent Bengtsson |' -'| All rights reserved. |' -'| |' -'| Redistribution and use in source and binary forms, with or without |' -'| modification, are permitted provided that the following conditions are met: |' -'| |' -'| 1. Redistributions of source code must retain the above copyright notice, this |' -'| list of conditions and the following disclaimer. |' -'| |' -'| 2. Redistributions in binary form must reproduce the above copyright notice, |' -'| this list of conditions and the following disclaimer in the documentation |' -'| and/or other materials provided with the distribution. |' -'| |' -'| 3. Neither the name of the copyright holder nor the names of its |' -'| contributors may be used to endorse or promote products derived from |' -'| this software without specific prior written permission. |' -'| |' -'| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |' -'| AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |' -'| IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |' -'| DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |' -'| FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |' -'| DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |' -'| SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |' -'| CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |' -'| OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |' -'| OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |' -'+---------------------------------------------------------------------------------+' - -Imports System.Windows.Forms -Imports System.Runtime.InteropServices - -''' -''' A static class for handling and simulating physical keyboard input. -''' -''' -Public NotInheritable Class Keyboard - Private Sub New() - End Sub - -#Region "Public methods" - -#Region "IsKeyDown()" - ''' - ''' Checks whether the specified key is currently held down. - ''' - ''' The key to check. - ''' - Public Shared Function IsKeyDown(ByVal Key As Keys) As Boolean - Dim Modifiers As Keys() = Internal.ExtractModifiers(Key) - For Each Modifier As Keys In Modifiers - If (NativeMethods.GetAsyncKeyState(Modifier) And Constants.KeyDownBit) <> Constants.KeyDownBit Then - Return False - End If - Next - - If Key = Keys.None Then Return True 'All modifiers are held down, no more keys left to check. - - Return (NativeMethods.GetAsyncKeyState(Key) And Constants.KeyDownBit) = Constants.KeyDownBit - End Function -#End Region - -#Region "IsKeyUp()" - ''' - ''' Checks whether the specified key is currently NOT held down. - ''' - ''' The key to check. - ''' - Public Shared Function IsKeyUp(ByVal Key As Keys) As Boolean - Return Keyboard.IsKeyDown(Key) = False - End Function -#End Region - -#Region "PressKey()" - ''' - ''' Simulates a keystroke. - ''' - ''' The key to press. - ''' Whether to simulate the keystroke using its virtual key code or its hardware scan code. - ''' - Public Shared Sub PressKey(ByVal Key As Keys, Optional ByVal HardwareKey As Boolean = False) - Keyboard.SetKeyState(Key, True, HardwareKey) - Keyboard.SetKeyState(Key, False, HardwareKey) - End Sub -#End Region - -#Region "SetKeyState()" - ''' - ''' Simulates a key being pushed down or released. - ''' - ''' The key which to simulate. - ''' Whether to push down or release the key. - ''' Whether to simulate the event using the key's virtual key code or its hardware scan code. - ''' - Public Shared Sub SetKeyState(ByVal Key As Keys, ByVal KeyDown As Boolean, Optional ByVal HardwareKey As Boolean = False) - Dim InputList As New List(Of NativeMethods.INPUT) - Dim Modifiers As Keys() = Internal.ExtractModifiers(Key) - - For Each Modifier As Keys In Modifiers - InputList.Add(Keyboard.GetKeyboardInputStructure(Modifier, KeyDown, HardwareKey)) - Next - InputList.Add(Keyboard.GetKeyboardInputStructure(Key, KeyDown, HardwareKey)) - - NativeMethods.SendInput(CType(InputList.Count, UInteger), InputList.ToArray(), Marshal.SizeOf(GetType(NativeMethods.INPUT))) - End Sub -#End Region - -#End Region - -#Region "Internal methods" - -#Region "GetKeyboardInputStructure()" - ''' - ''' Constructs a native keyboard INPUT structure that can be passed to SendInput(). - ''' - ''' The key to send. - ''' Whether to send a KeyDown/KeyUp stroke. - ''' Whether to send the key's hardware scan code instead of its virtual key code. - ''' - Private Shared Function GetKeyboardInputStructure(ByVal Key As Keys, ByVal KeyDown As Boolean, ByVal HardwareKey As Boolean) As NativeMethods.INPUT - Dim KeyboardInput As New NativeMethods.KEYBDINPUT With { - .wVk = If(HardwareKey = False, (Key And UShort.MaxValue), 0), - .wScan = If(HardwareKey, - NativeMethods.MapVirtualKeyEx(CType(Key, UInteger), 0, NativeMethods.GetKeyboardLayout(0)), - 0) And UShort.MaxValue, - .time = 0, - .dwFlags = If(HardwareKey, NativeMethods.KEYEVENTF.SCANCODE, 0) Or - If(KeyDown = False, NativeMethods.KEYEVENTF.KEYUP, 0), - .dwExtraInfo = UIntPtr.Zero - } - - Dim Union As New NativeMethods.INPUTUNION With {.ki = KeyboardInput} - Dim Input As New NativeMethods.INPUT With { - .type = NativeMethods.INPUTTYPE.KEYBOARD, - .U = Union - } - - Return Input - End Function -#End Region - -#End Region - -End Class \ No newline at end of file diff --git a/InputHelper Library/InputHelper .NET 3.5/InputHelper .NET 3.5.vbproj b/InputHelper Library/InputHelper .NET 3.5/InputHelper .NET 3.5.vbproj deleted file mode 100644 index a0e0a85..0000000 --- a/InputHelper Library/InputHelper .NET 3.5/InputHelper .NET 3.5.vbproj +++ /dev/null @@ -1,131 +0,0 @@ - - - - Debug - AnyCPU - - - - - {8D0E884C-CE78-472F-916E-5CC64819FFC3} - Library - InputHelper - InputHelper .NET 3.5 - 512 - Windows - v3.5 - - - - true - full - true - true - bin\Debug\ - InputHelper .NET 3.5.xml - 42016,41999,42017,42018,42019,42032,42036,42020,42021,42022 - - - pdbonly - false - true - true - bin\Release\ - InputHelper .NET 3.5.xml - 42016,41999,42017,42018,42019,42032,42036,42020,42021,42022 - - - On - - - Binary - - - Off - - - On - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - True - Application.myapp - - - True - True - Resources.resx - - - True - Settings.settings - True - - - - - - VbMyResourcesResXFileCodeGenerator - Resources.Designer.vb - My.Resources - Designer - - - - - MyApplicationCodeGenerator - Application.Designer.vb - - - SettingsSingleFileGenerator - My - Settings.Designer.vb - - - - - PreserveNewest - - - - - \ No newline at end of file diff --git a/InputHelper Library/InputHelper .NET 3.5/Internal.vb b/InputHelper Library/InputHelper .NET 3.5/Internal.vb deleted file mode 100644 index 57d0df7..0000000 --- a/InputHelper Library/InputHelper .NET 3.5/Internal.vb +++ /dev/null @@ -1,112 +0,0 @@ -'+---------------------------------------------------------------------------------+' -'| === InputHelper === |' -'| |' -'| Created by Vincent "Visual Vincent" Bengtsson |' -'| Website: https://www.mydoomsite.com/ |' -'| GitHub: https://github.com/Visual-Vincent |' -'| |' -'| |' -'| === COPYRIGHT LICENSE === |' -'| |' -'| Copyright (c) 2016-2019, Vincent Bengtsson |' -'| All rights reserved. |' -'| |' -'| Redistribution and use in source and binary forms, with or without |' -'| modification, are permitted provided that the following conditions are met: |' -'| |' -'| 1. Redistributions of source code must retain the above copyright notice, this |' -'| list of conditions and the following disclaimer. |' -'| |' -'| 2. Redistributions in binary form must reproduce the above copyright notice, |' -'| this list of conditions and the following disclaimer in the documentation |' -'| and/or other materials provided with the distribution. |' -'| |' -'| 3. Neither the name of the copyright holder nor the names of its |' -'| contributors may be used to endorse or promote products derived from |' -'| this software without specific prior written permission. |' -'| |' -'| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |' -'| AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |' -'| IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |' -'| DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |' -'| FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |' -'| DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |' -'| SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |' -'| CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |' -'| OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |' -'| OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |' -'+---------------------------------------------------------------------------------+' - -Imports System.Windows.Forms - -''' -''' A class holding internal methods and fields related to InputHelper. -''' -''' -Friend Class Internal - -#Region "ExtractModifiers()" - ''' - ''' Extracts any .NET modifiers from the specified key combination and returns them as native virtual key code keys. - ''' - ''' The key combination to extract the modifiers from (if any). - ''' - Public Shared Function ExtractModifiers(ByRef Key As Keys) As Keys() - Dim Modifiers As New List(Of Keys) - - If (Key And Keys.Control) = Keys.Control Then - Key = Key And Not Keys.Control - Modifiers.Add(Keys.ControlKey) - End If - - If (Key And Keys.Shift) = Keys.Shift Then - Key = Key And Not Keys.Shift - Modifiers.Add(Keys.ShiftKey) - End If - - If (Key And Keys.Alt) = Keys.Alt Then - Key = Key And Not Keys.Alt - Modifiers.Add(Keys.Menu) - End If - - Return Modifiers.ToArray() - End Function -#End Region - -#Region "IsModifier()" - ''' - ''' Checks whether the specified key is any Left or Right version of the specified modifier. - ''' - ''' The key to check. - ''' The modifier to check for. - ''' - Public Shared Function IsModifier(ByVal Key As Keys, ByVal Modifier As ModifierKeys) As Boolean - Select Case Modifier - Case ModifierKeys.Control - Return _ - Key = Keys.Control OrElse _ - Key = Keys.ControlKey OrElse _ - Key = Keys.LControlKey OrElse _ - Key = Keys.RControlKey - Case ModifierKeys.Shift - Return _ - Key = Keys.Shift OrElse _ - Key = Keys.ShiftKey OrElse _ - Key = Keys.LShiftKey OrElse _ - Key = Keys.RShiftKey - Case ModifierKeys.Alt - Return _ - Key = Keys.Alt OrElse _ - Key = Keys.Menu OrElse _ - Key = Keys.LMenu OrElse _ - Key = Keys.RMenu - Case ModifierKeys.Windows - Return _ - Key = Keys.LWin OrElse _ - Key = Keys.RWin - End Select - Throw New ArgumentOutOfRangeException("Modifier", CType(Modifier, Integer) & " is not a valid modifier key!") - End Function -#End Region - -End Class diff --git a/InputHelper Library/InputHelper .NET 3.5/LICENSE.txt b/InputHelper Library/InputHelper .NET 3.5/LICENSE.txt deleted file mode 100644 index 80a909e..0000000 --- a/InputHelper Library/InputHelper .NET 3.5/LICENSE.txt +++ /dev/null @@ -1,38 +0,0 @@ -+---------------------------------------------------------------------------------+ -| === InputHelper === | -| | -| Created by Vincent "Visual Vincent" Bengtsson | -| Website: https://www.mydoomsite.com/ | -| GitHub: https://github.com/Visual-Vincent | -| | -| | -| === COPYRIGHT LICENSE === | -| | -| Copyright (c) 2016-2019, Vincent Bengtsson | -| All rights reserved. | -| | -| Redistribution and use in source and binary forms, with or without | -| modification, are permitted provided that the following conditions are met: | -| | -| 1. Redistributions of source code must retain the above copyright notice, this | -| list of conditions and the following disclaimer. | -| | -| 2. Redistributions in binary form must reproduce the above copyright notice, | -| this list of conditions and the following disclaimer in the documentation | -| and/or other materials provided with the distribution. | -| | -| 3. Neither the name of the copyright holder nor the names of its | -| contributors may be used to endorse or promote products derived from | -| this software without specific prior written permission. | -| | -| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | -| AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | -| IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | -| DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | -| FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | -| DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | -| SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | -| CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | -| OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | -| OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | -+---------------------------------------------------------------------------------+ \ No newline at end of file diff --git a/InputHelper Library/InputHelper .NET 3.5/My Project/Application.Designer.vb b/InputHelper Library/InputHelper .NET 3.5/My Project/Application.Designer.vb deleted file mode 100644 index 88dd01c..0000000 --- a/InputHelper Library/InputHelper .NET 3.5/My Project/Application.Designer.vb +++ /dev/null @@ -1,13 +0,0 @@ -'------------------------------------------------------------------------------ -' -' This code was generated by a tool. -' Runtime Version:4.0.30319.42000 -' -' Changes to this file may cause incorrect behavior and will be lost if -' the code is regenerated. -' -'------------------------------------------------------------------------------ - -Option Strict On -Option Explicit On - diff --git a/InputHelper Library/InputHelper .NET 3.5/My Project/Application.myapp b/InputHelper Library/InputHelper .NET 3.5/My Project/Application.myapp deleted file mode 100644 index 758895d..0000000 --- a/InputHelper Library/InputHelper .NET 3.5/My Project/Application.myapp +++ /dev/null @@ -1,10 +0,0 @@ - - - false - false - 0 - true - 0 - 1 - true - diff --git a/InputHelper Library/InputHelper .NET 3.5/My Project/AssemblyInfo.vb b/InputHelper Library/InputHelper .NET 3.5/My Project/AssemblyInfo.vb deleted file mode 100644 index 027f060..0000000 --- a/InputHelper Library/InputHelper .NET 3.5/My Project/AssemblyInfo.vb +++ /dev/null @@ -1,38 +0,0 @@ -Imports System.Resources - -Imports System -Imports System.Reflection -Imports System.Runtime.InteropServices - -' General Information about an assembly is controlled through the following -' set of attributes. Change these attribute values to modify the information -' associated with an assembly. - -' Review the values of the assembly attributes - - - - - - - - - - -'The following GUID is for the ID of the typelib if this project is exposed to COM - - -' Version information for an assembly consists of the following four values: -' -' Major Version -' Minor Version -' Build Number -' Revision -' -' You can specify all the values or you can default the Build and Revision Numbers -' by using the '*' as shown below: -' - - - - \ No newline at end of file diff --git a/InputHelper Library/InputHelper .NET 3.5/My Project/Resources.Designer.vb b/InputHelper Library/InputHelper .NET 3.5/My Project/Resources.Designer.vb deleted file mode 100644 index 8d4decd..0000000 --- a/InputHelper Library/InputHelper .NET 3.5/My Project/Resources.Designer.vb +++ /dev/null @@ -1,63 +0,0 @@ -'------------------------------------------------------------------------------ -' -' This code was generated by a tool. -' Runtime Version:4.0.30319.42000 -' -' Changes to this file may cause incorrect behavior and will be lost if -' the code is regenerated. -' -'------------------------------------------------------------------------------ - -Option Strict On -Option Explicit On - -Imports System - -Namespace My.Resources - - 'This class was auto-generated by the StronglyTypedResourceBuilder - 'class via a tool like ResGen or Visual Studio. - 'To add or remove a member, edit your .ResX file then rerun ResGen - 'with the /str option, or rebuild your VS project. - ''' - ''' A strongly-typed resource class, for looking up localized strings, etc. - ''' - _ - Friend Module Resources - - Private resourceMan As Global.System.Resources.ResourceManager - - Private resourceCulture As Global.System.Globalization.CultureInfo - - ''' - ''' Returns the cached ResourceManager instance used by this class. - ''' - _ - Friend ReadOnly Property ResourceManager() As Global.System.Resources.ResourceManager - Get - If Object.ReferenceEquals(resourceMan, Nothing) Then - Dim temp As Global.System.Resources.ResourceManager = New Global.System.Resources.ResourceManager("InputHelper.Resources", GetType(Resources).Assembly) - resourceMan = temp - End If - Return resourceMan - End Get - End Property - - ''' - ''' Overrides the current thread's CurrentUICulture property for all - ''' resource lookups using this strongly typed resource class. - ''' - _ - Friend Property Culture() As Global.System.Globalization.CultureInfo - Get - Return resourceCulture - End Get - Set - resourceCulture = value - End Set - End Property - End Module -End Namespace diff --git a/InputHelper Library/InputHelper .NET 3.5/My Project/Resources.resx b/InputHelper Library/InputHelper .NET 3.5/My Project/Resources.resx deleted file mode 100644 index af7dbeb..0000000 --- a/InputHelper Library/InputHelper .NET 3.5/My Project/Resources.resx +++ /dev/null @@ -1,117 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - \ No newline at end of file diff --git a/InputHelper Library/InputHelper .NET 3.5/My Project/Settings.Designer.vb b/InputHelper Library/InputHelper .NET 3.5/My Project/Settings.Designer.vb deleted file mode 100644 index 6dc7e51..0000000 --- a/InputHelper Library/InputHelper .NET 3.5/My Project/Settings.Designer.vb +++ /dev/null @@ -1,73 +0,0 @@ -'------------------------------------------------------------------------------ -' -' This code was generated by a tool. -' Runtime Version:4.0.30319.42000 -' -' Changes to this file may cause incorrect behavior and will be lost if -' the code is regenerated. -' -'------------------------------------------------------------------------------ - -Option Strict On -Option Explicit On - - -Namespace My - - _ - Partial Friend NotInheritable Class MySettings - Inherits Global.System.Configuration.ApplicationSettingsBase - - Private Shared defaultInstance As MySettings = CType(Global.System.Configuration.ApplicationSettingsBase.Synchronized(New MySettings()),MySettings) - -#Region "My.Settings Auto-Save Functionality" -#If _MyType = "WindowsForms" Then - Private Shared addedHandler As Boolean - - Private Shared addedHandlerLockObject As New Object - - _ - Private Shared Sub AutoSaveSettings(ByVal sender As Global.System.Object, ByVal e As Global.System.EventArgs) - If My.Application.SaveMySettingsOnExit Then - My.Settings.Save() - End If - End Sub -#End If -#End Region - - Public Shared ReadOnly Property [Default]() As MySettings - Get - -#If _MyType = "WindowsForms" Then - If Not addedHandler Then - SyncLock addedHandlerLockObject - If Not addedHandler Then - AddHandler My.Application.Shutdown, AddressOf AutoSaveSettings - addedHandler = True - End If - End SyncLock - End If -#End If - Return defaultInstance - End Get - End Property - End Class -End Namespace - -Namespace My - - _ - Friend Module MySettingsProperty - - _ - Friend ReadOnly Property Settings() As Global.InputHelper.My.MySettings - Get - Return Global.InputHelper.My.MySettings.Default - End Get - End Property - End Module -End Namespace diff --git a/InputHelper Library/InputHelper .NET 3.5/My Project/Settings.settings b/InputHelper Library/InputHelper .NET 3.5/My Project/Settings.settings deleted file mode 100644 index 85b890b..0000000 --- a/InputHelper Library/InputHelper .NET 3.5/My Project/Settings.settings +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - diff --git a/InputHelper Library/InputHelper .NET 3.5/NativeMethods.vb b/InputHelper Library/InputHelper .NET 3.5/NativeMethods.vb deleted file mode 100644 index 31782d4..0000000 --- a/InputHelper Library/InputHelper .NET 3.5/NativeMethods.vb +++ /dev/null @@ -1,508 +0,0 @@ -'+---------------------------------------------------------------------------------+' -'| === InputHelper === |' -'| |' -'| Created by Vincent "Visual Vincent" Bengtsson |' -'| Website: https://www.mydoomsite.com/ |' -'| GitHub: https://github.com/Visual-Vincent |' -'| |' -'| |' -'| === COPYRIGHT LICENSE === |' -'| |' -'| Copyright (c) 2016-2019, Vincent Bengtsson |' -'| All rights reserved. |' -'| |' -'| Redistribution and use in source and binary forms, with or without |' -'| modification, are permitted provided that the following conditions are met: |' -'| |' -'| 1. Redistributions of source code must retain the above copyright notice, this |' -'| list of conditions and the following disclaimer. |' -'| |' -'| 2. Redistributions in binary form must reproduce the above copyright notice, |' -'| this list of conditions and the following disclaimer in the documentation |' -'| and/or other materials provided with the distribution. |' -'| |' -'| 3. Neither the name of the copyright holder nor the names of its |' -'| contributors may be used to endorse or promote products derived from |' -'| this software without specific prior written permission. |' -'| |' -'| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |' -'| AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |' -'| IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |' -'| DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |' -'| FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |' -'| DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |' -'| SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |' -'| CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |' -'| OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |' -'| OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |' -'+---------------------------------------------------------------------------------+' - -Imports System.Windows.Forms -Imports System.Runtime.InteropServices -Imports System.Text - -''' -''' A class containing all the native WinAPI methods, structures, declarations, etc. used by InputHelper. -''' -''' -Public NotInheritable Class NativeMethods - Private Sub New() - End Sub - -#Region "Delegates" - Public Delegate Function KeyboardProc(ByVal nCode As Integer, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr - Public Delegate Function LowLevelKeyboardProc(ByVal nCode As Integer, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr - Public Delegate Function LowLevelMouseProc(ByVal nCode As Integer, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr -#End Region - -#Region "Methods" - -#Region "Hook methods" - _ - Public Shared Function SetWindowsHookEx(ByVal idHook As HookType, ByVal lpfn As KeyboardProc, ByVal hMod As IntPtr, ByVal dwThreadId As UInteger) As IntPtr - End Function - - _ - Public Shared Function SetWindowsHookEx(ByVal idHook As HookType, ByVal lpfn As LowLevelKeyboardProc, ByVal hMod As IntPtr, ByVal dwThreadId As UInteger) As IntPtr - End Function - - _ - Public Shared Function SetWindowsHookEx(ByVal idHook As HookType, ByVal lpfn As LowLevelMouseProc, ByVal hMod As IntPtr, ByVal dwThreadId As UInteger) As IntPtr - End Function - - _ - Public Shared Function UnhookWindowsHookEx(ByVal hhk As IntPtr) As Boolean - End Function - - _ - Public Shared Function CallNextHookEx(ByVal hhk As IntPtr, ByVal nCode As Integer, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr - End Function -#End Region - -#Region "Input methods" - - Public Shared Function SendInput(ByVal nInputs As UInteger, ByVal pInputs() As INPUT, ByVal cbSize As Integer) As UInteger - End Function - - _ - Public Shared Function MapVirtualKeyEx(uCode As UInteger, uMapType As UInteger, dwhkl As IntPtr) As UInteger - End Function - - _ - Public Shared Function GetKeyboardLayout(idThread As UInteger) As IntPtr - End Function - - _ - Public Shared Function GetKeyboardState( ByVal lpKeyState As Byte()) As Boolean - End Function - - _ - Public Shared Function GetAsyncKeyState(ByVal vKey As Keys) As Short - End Function - - _ - Public Shared Function ToUnicodeEx(ByVal wVirtKey As UInteger, ByVal wScanCode As UInteger, ByVal lpKeyState As Byte(), ByVal pwszBuff As StringBuilder, ByVal cchBuff As Integer, ByVal wFlags As UInteger, ByVal dwhkl As IntPtr) As Integer - End Function -#End Region - -#Region "Window and thread methods" - 'CharSet.Unicode is required for CP437 ALT codes to work! - _ - Public Shared Function SendMessage(ByVal hWnd As IntPtr, ByVal Msg As UInteger, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr - End Function - - _ - Public Shared Function PostMessage(ByVal hWnd As IntPtr, ByVal Msg As UInteger, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As Boolean - End Function - - _ - Public Shared Function GetForegroundWindow() As IntPtr - End Function - - _ - Public Shared Function GetFocus() As IntPtr - End Function - - _ - Public Shared Function AttachThreadInput(ByVal idAttach As UInteger, ByVal idAttachTo As UInteger, fAttach As Boolean) As Boolean - End Function - - _ - Public Shared Function GetCurrentThreadId() As UInteger - End Function - - _ - Public Shared Function GetWindowThreadProcessId(ByVal hWnd As IntPtr, lpdwProcessId As UIntPtr) As UInteger - End Function - - _ - Public Shared Function WindowFromPoint(ByVal p As NATIVEPOINT) As IntPtr - End Function - - _ - Public Shared Function ScreenToClient(ByVal hWnd As IntPtr, ByRef lpPoint As NATIVEPOINT) As Boolean - End Function - - - Public Shared Function GetModuleHandle(ByVal lpModuleName As String) As IntPtr - End Function -#End Region - -#Region "System information methods" - _ - Public Shared Function GetDoubleClickTime() As UInteger - End Function -#End Region - -#End Region - -#Region "Enumerations" - Public Enum HookType As Integer - WH_CALLWNDPROC = 4 - WH_CALLWNDPROCRET = 12 - WH_CBT = 5 - WH_DEBUG = 9 - WH_FOREGROUNDIDLE = 11 - WH_GETMESSAGE = 3 - WH_JOURNALPLAYBACK = 1 - WH_JOURNALRECORD = 0 - WH_KEYBOARD = 2 - WH_KEYBOARD_LL = 13 - WH_MOUSE = 7 - WH_MOUSE_LL = 14 - WH_MSGFILTER = -1 - WH_SHELL = 10 - WH_SYSMSGFILTER = 6 - End Enum - - Public Enum HookCode As Integer - HC_ACTION = 0 - HC_NOREMOVE = 3 - End Enum - - Public Enum KeyboardFlags As UInteger - KF_EXTENDED = &H100 - KF_DLGMODE = &H800 - KF_MENUMODE = &H1000 - KF_ALTDOWN = &H2000 - KF_REPEAT = &H4000 - KF_UP = &H8000 - End Enum - - Public Enum LowLevelKeyboardHookFlags As UInteger - LLKHF_EXTENDED = &H1 - LLKHF_LOWER_IL_INJECTED = &H2 - LLKHF_INJECTED = &H10 - LLKHF_ALTDOWN = &H20 - LLKHF_UP = &H80 - End Enum - - Public Enum LowLevelMouseHookFlags As UInteger - LLMHF_INJECTED = &H1 - LLMHF_LOWER_IL_INJECTED = &H2 - End Enum - - Public Enum INPUTTYPE As UInteger - MOUSE = 0 - KEYBOARD = 1 - HARDWARE = 2 - End Enum - - _ - Public Enum KEYEVENTF As UInteger - ''' - ''' If specified, the scan code was preceded by a prefix byte that has the value 0xE0 (224). - ''' - ''' - EXTENDEDKEY = &H1 - - ''' - ''' If specified, the key is being released. If not specified, the key is being pressed. - ''' - ''' - KEYUP = &H2 - - ''' - ''' If specified, wScan identifies the key and wVk is ignored. - ''' - ''' - SCANCODE = &H8 - - ''' - ''' If specified, the system synthesizes a VK_PACKET keystroke. The wVk parameter must be zero. This flag can only be combined with the KEYEVENTF_KEYUP flag. - ''' - ''' - UNICODE = &H4 - End Enum - - _ - Public Enum MOUSEEVENTF As UInteger - ''' - ''' The dx and dy members contain normalized absolute (screen) coordinates. - ''' - ''' - ABSOLUTE = &H8000 - - ''' - ''' The wheel was moved horizontally, if the mouse has a wheel. The amount of movement is specified in mouseData. - ''' - ''' - HWHEEL = &H1000 - - ''' - ''' Movement occurred. - ''' - ''' - MOVE = &H1 - - ''' - ''' The WM_MOUSEMOVE messages will not be coalesced. The default behavior is to coalesce WM_MOUSEMOVE messages. - ''' - ''' - MOVE_NOCOALESCE = &H2000 - - ''' - ''' The left button was pressed. - ''' - ''' - LEFTDOWN = &H2 - - ''' - ''' The left button was released. - ''' - ''' - LEFTUP = &H4 - - ''' - ''' The right button was pressed. - ''' - ''' - RIGHTDOWN = &H8 - - ''' - ''' The right button was released. - ''' - ''' - RIGHTUP = &H10 - - ''' - ''' The middle button was pressed. - ''' - ''' - MIDDLEDOWN = &H20 - - ''' - ''' The middle button was released. - ''' - ''' - MIDDLEUP = &H40 - - ''' - ''' Maps coordinates to the entire desktop. Must be used with MOUSEEVENTF_ABSOLUTE. - ''' - ''' - VIRTUALDESK = &H4000 - - ''' - ''' The wheel was moved, if the mouse has a wheel. The amount of movement is specified in mouseData. - ''' - ''' - WHEEL = &H800 - - ''' - ''' An X button was pressed. - ''' - ''' - XDOWN = &H80 - - ''' - ''' An X button was released. - ''' - ''' - XUP = &H100 - End Enum - - Public Enum MouseXButton As UInteger - XBUTTON1 = &H1 - XBUTTON2 = &H2 - End Enum - - Public Enum KeyMessage As UInteger - WM_KEYDOWN = &H100 - WM_KEYUP = &H101 - WM_CHAR = &H102 - WM_DEADCHAR = &H103 - WM_SYSKEYDOWN = &H104 - WM_SYSKEYUP = &H105 - WM_SYSCHAR = &H106 - WM_SYSDEADCHAR = &H107 - WM_UNICHAR = &H109 - End Enum - - Public Enum MouseMessage As Integer - WM_MOUSEMOVE = &H200 - WM_LBUTTONDOWN = &H201 - WM_LBUTTONUP = &H202 - WM_LBUTTONDBLCLK = &H203 - WM_MBUTTONDOWN = &H207 - WM_MBUTTONUP = &H208 - WM_MBUTTONDBLCLK = &H209 - WM_RBUTTONDOWN = &H204 - WM_RBUTTONUP = &H205 - WM_RBUTTONDBLCLK = &H206 - WM_MOUSEWHEEL = &H20A - WM_MOUSEHWHEEL = &H20E - WM_XBUTTONDOWN = &H20B - WM_XBUTTONUP = &H20C - WM_XBUTTONDBLCLK = &H20D - End Enum -#End Region - -#Region "Structures" - _ - Public Structure KBDLLHOOKSTRUCT - Public vkCode As UInteger - Public scanCode As UInteger - Public flags As LowLevelKeyboardHookFlags - Public time As UInteger - Public dwExtraInfo As UIntPtr - End Structure - - _ - Public Structure MSLLHOOKSTRUCT - Public pt As NATIVEPOINT - Public mouseData As UInteger - Public flags As UInteger - Public time As UInteger - Public dwExtraInfo As UIntPtr - End Structure - - - Public Structure DWORD - Public Value As UInteger - Public Low As UShort - Public High As UShort - - Public SignedValue As Integer - Public SignedLow As Short - Public SignedHigh As Short - - Public Shared Widening Operator CType(ByVal DWORD As DWORD) As IntPtr - Return New IntPtr(DWORD.SignedValue) - End Operator - - Public Shared Widening Operator CType(ByVal DWORD As DWORD) As UInteger - Return DWORD.Value - End Operator - - Public Shared Widening Operator CType(ByVal DWORD As DWORD) As Integer - Return DWORD.SignedValue - End Operator - - Public Sub New(ByVal Value As UInteger) - Me.Value = Value - End Sub - - Public Sub New(ByVal Value As Integer) - Me.SignedValue = Value - End Sub - - Public Sub New(ByVal Low As UShort, ByVal High As UShort) - Me.Low = Low - Me.High = High - End Sub - - Public Sub New(ByVal Low As Short, ByVal High As Short) - Me.SignedLow = Low - Me.SignedHigh = High - End Sub - End Structure - - - Public Structure QWORD - Public Value As ULong - Public Low As UInteger - Public High As UInteger - - Public SignedValue As Long - Public SignedLow As Integer - Public SignedHigh As Integer - - Public LowWord As DWORD - Public HighWord As DWORD - - Public Shared Widening Operator CType(ByVal QWORD As QWORD) As ULong - Return QWORD.Value - End Operator - - Public Shared Widening Operator CType(ByVal QWORD As QWORD) As Long - Return QWORD.SignedValue - End Operator - - Public Sub New(ByVal Value As ULong) - Me.Value = Value - End Sub - - Public Sub New(ByVal Value As Long) - Me.SignedValue = Value - End Sub - - Public Sub New(ByVal Low As UInteger, ByVal High As UInteger) - Me.Low = Low - Me.High = High - End Sub - - Public Sub New(ByVal Low As Integer, ByVal High As Integer) - Me.SignedLow = Low - Me.SignedHigh = High - End Sub - End Structure - - _ - Public Structure INPUTUNION - Public mi As MOUSEINPUT - Public ki As KEYBDINPUT - Public hi As HARDWAREINPUT - End Structure - - Public Structure INPUT - Public type As INPUTTYPE - Public U As INPUTUNION - End Structure - - Public Structure MOUSEINPUT - Public dx As Integer - Public dy As Integer - Public mouseData As UInteger - Public dwFlags As UInteger - Public time As UInteger - Public dwExtraInfo As UIntPtr - End Structure - - Public Structure KEYBDINPUT - Public wVk As UShort - Public wScan As UShort - Public dwFlags As UInteger - Public time As UInteger - Public dwExtraInfo As UIntPtr - End Structure - - Public Structure HARDWAREINPUT - Public uMsg As UInteger - Public wParamL As UShort - Public wParamH As UShort - End Structure - - _ - Public Structure NATIVEPOINT - Public x As Integer - Public y As Integer - - Public Sub New(ByVal X As Integer, ByVal Y As Integer) - Me.x = X - Me.y = Y - End Sub - End Structure -#End Region - -End Class diff --git a/InputHelper Library/InputHelper .NET 4.x/Constants.vb b/InputHelper Library/InputHelper .NET 4.x/Constants.vb deleted file mode 100644 index c919185..0000000 --- a/InputHelper Library/InputHelper .NET 4.x/Constants.vb +++ /dev/null @@ -1,69 +0,0 @@ -'+---------------------------------------------------------------------------------+' -'| === InputHelper === |' -'| |' -'| Created by Vincent "Visual Vincent" Bengtsson |' -'| Website: https://www.mydoomsite.com/ |' -'| GitHub: https://github.com/Visual-Vincent |' -'| |' -'| |' -'| === COPYRIGHT LICENSE === |' -'| |' -'| Copyright (c) 2016-2019, Vincent Bengtsson |' -'| All rights reserved. |' -'| |' -'| Redistribution and use in source and binary forms, with or without |' -'| modification, are permitted provided that the following conditions are met: |' -'| |' -'| 1. Redistributions of source code must retain the above copyright notice, this |' -'| list of conditions and the following disclaimer. |' -'| |' -'| 2. Redistributions in binary form must reproduce the above copyright notice, |' -'| this list of conditions and the following disclaimer in the documentation |' -'| and/or other materials provided with the distribution. |' -'| |' -'| 3. Neither the name of the copyright holder nor the names of its |' -'| contributors may be used to endorse or promote products derived from |' -'| this software without specific prior written permission. |' -'| |' -'| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |' -'| AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |' -'| IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |' -'| DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |' -'| FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |' -'| DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |' -'| SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |' -'| CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |' -'| OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |' -'| OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |' -'+---------------------------------------------------------------------------------+' - -Imports System.Text -Imports System.Windows.Forms - -''' -''' A class holding various InputHelper constants. -''' -''' -Public NotInheritable Class Constants - Private Sub New() - End Sub - - ''' - ''' The Alt Gr key. - ''' - ''' - Public Const AltGr As Keys = Keys.Control Or Keys.Alt - - ''' - ''' The bit value used to check if a key is held down (masked with the return value from GetAsyncKeyState()). - ''' - ''' - Public Const KeyDownBit As Integer = &H8000 - - ''' - ''' Windows-1252 encoding. - ''' - ''' - Public Shared ReadOnly Windows1252 As Encoding = Encoding.GetEncoding("windows-1252") - -End Class diff --git a/InputHelper Library/InputHelper .NET 4.x/EventArgs/MouseEventArgs.vb b/InputHelper Library/InputHelper .NET 4.x/EventArgs/MouseEventArgs.vb deleted file mode 100644 index f08ac6d..0000000 --- a/InputHelper Library/InputHelper .NET 4.x/EventArgs/MouseEventArgs.vb +++ /dev/null @@ -1,152 +0,0 @@ -'+---------------------------------------------------------------------------------+' -'| === InputHelper === |' -'| |' -'| Created by Vincent "Visual Vincent" Bengtsson |' -'| Website: https://www.mydoomsite.com/ |' -'| GitHub: https://github.com/Visual-Vincent |' -'| |' -'| |' -'| === COPYRIGHT LICENSE === |' -'| |' -'| Copyright (c) 2016-2019, Vincent Bengtsson |' -'| All rights reserved. |' -'| |' -'| Redistribution and use in source and binary forms, with or without |' -'| modification, are permitted provided that the following conditions are met: |' -'| |' -'| 1. Redistributions of source code must retain the above copyright notice, this |' -'| list of conditions and the following disclaimer. |' -'| |' -'| 2. Redistributions in binary form must reproduce the above copyright notice, |' -'| this list of conditions and the following disclaimer in the documentation |' -'| and/or other materials provided with the distribution. |' -'| |' -'| 3. Neither the name of the copyright holder nor the names of its |' -'| contributors may be used to endorse or promote products derived from |' -'| this software without specific prior written permission. |' -'| |' -'| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |' -'| AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |' -'| IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |' -'| DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |' -'| FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |' -'| DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |' -'| SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |' -'| CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |' -'| OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |' -'| OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |' -'+---------------------------------------------------------------------------------+' - -Imports System.Drawing -Imports System.Windows.Forms -Imports System.Runtime.InteropServices -Imports System.ComponentModel -Imports InputHelper.Hooks - -Namespace EventArgs - Public Class MouseHookEventArgs - Inherits System.EventArgs - - Private _button As MouseButtons - Private _buttonState As KeyState - Private _delta As Integer - Private _doubleClick As Boolean - Private _location As Point - Private _scrollDirection As ScrollDirection - - ''' - ''' Gets or sets a boolean value indicating whether the mouse event should be blocked from reaching any windows. - ''' - ''' - Public Property Block As Boolean = False - - ''' - ''' Gets which mouse button was pressed or released. - ''' - ''' - Public ReadOnly Property Button As MouseButtons - Get - Return _button - End Get - End Property - - ''' - ''' Gets the current state of the button that generated the mouse event. - ''' - ''' - Public ReadOnly Property ButtonState As KeyState - Get - Return _buttonState - End Get - End Property - - ''' - ''' Gets a signed count of the number of detents the mouse wheel has rotated. A detent is one notch of the mouse wheel. - ''' - ''' - Public ReadOnly Property Delta As Integer - Get - Return _delta - End Get - End Property - - ''' - ''' Gets a boolean value indicating whether the event was caused by a double click. - ''' - ''' - Public ReadOnly Property DoubleClick As Boolean - Get - Return _doubleClick - End Get - End Property - - ''' - ''' Gets the location of the mouse (in screen coordinates). - ''' - ''' - Public ReadOnly Property Location As Point - Get - Return _location - End Get - End Property - - ''' - ''' Gets which direction the mouse wheel was scrolled in. - ''' - ''' - Public ReadOnly Property ScrollDirection As ScrollDirection - Get - Return _scrollDirection - End Get - End Property - - Public Overrides Function ToString() As String - Return String.Format("{{Button: {0}, State: {1}, DoubleClick: {2}, Location: {3}, Scroll: {4}, Delta: {5}}}", _ - Me.Button, Me.ButtonState, Me.DoubleClick, Me.Location, Me.ScrollDirection, Me.Delta) - End Function - - ''' - ''' Initializes a new instance of the MouseHookEventArgs class. - ''' - ''' Which mouse button was pressed or released. - ''' The current state of the button that generated the mouse event. - ''' Whether the event was caused by a double click. - ''' The location of the mouse (in screen coordinates). - ''' Which direction the mouse wheel was scrolled in. - ''' A signed count of the number of detents the mouse wheel has rotated. - ''' - Public Sub New(ByVal Button As MouseButtons, _ - ByVal ButtonState As KeyState, _ - ByVal DoubleClick As Boolean, _ - ByVal Location As Point, _ - ByVal ScrollDirection As ScrollDirection, _ - ByVal Delta As Integer) - Me._button = Button - Me._buttonState = ButtonState - Me._doubleClick = DoubleClick - Me._location = Location - Me._scrollDirection = ScrollDirection - Me._delta = Delta - End Sub - End Class -End Namespace \ No newline at end of file diff --git a/InputHelper Library/InputHelper .NET 4.x/Hooks/Enumerations.vb b/InputHelper Library/InputHelper .NET 4.x/Hooks/Enumerations.vb deleted file mode 100644 index 7277629..0000000 --- a/InputHelper Library/InputHelper .NET 4.x/Hooks/Enumerations.vb +++ /dev/null @@ -1,51 +0,0 @@ -'+---------------------------------------------------------------------------------+' -'| === InputHelper === |' -'| |' -'| Created by Vincent "Visual Vincent" Bengtsson |' -'| Website: https://www.mydoomsite.com/ |' -'| GitHub: https://github.com/Visual-Vincent |' -'| |' -'| |' -'| === COPYRIGHT LICENSE === |' -'| |' -'| Copyright (c) 2016-2019, Vincent Bengtsson |' -'| All rights reserved. |' -'| |' -'| Redistribution and use in source and binary forms, with or without |' -'| modification, are permitted provided that the following conditions are met: |' -'| |' -'| 1. Redistributions of source code must retain the above copyright notice, this |' -'| list of conditions and the following disclaimer. |' -'| |' -'| 2. Redistributions in binary form must reproduce the above copyright notice, |' -'| this list of conditions and the following disclaimer in the documentation |' -'| and/or other materials provided with the distribution. |' -'| |' -'| 3. Neither the name of the copyright holder nor the names of its |' -'| contributors may be used to endorse or promote products derived from |' -'| this software without specific prior written permission. |' -'| |' -'| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |' -'| AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |' -'| IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |' -'| DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |' -'| FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |' -'| DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |' -'| SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |' -'| CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |' -'| OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |' -'| OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |' -'+---------------------------------------------------------------------------------+' - -Namespace Hooks - Public Enum KeyState As Integer - Up = 0 - Down = 1 - End Enum - - Public Enum ScrollDirection As Integer - None = 0 - Vertical = 1 - Horizontal = 2 - End Enum -End Namespace \ No newline at end of file diff --git a/InputHelper Library/InputHelper .NET 4.x/Hooks/LocalKeyboardHook.vb b/InputHelper Library/InputHelper .NET 4.x/Hooks/LocalKeyboardHook.vb deleted file mode 100644 index 46cbe04..0000000 --- a/InputHelper Library/InputHelper .NET 4.x/Hooks/LocalKeyboardHook.vb +++ /dev/null @@ -1,170 +0,0 @@ -'+---------------------------------------------------------------------------------+' -'| === InputHelper === |' -'| |' -'| Created by Vincent "Visual Vincent" Bengtsson |' -'| Website: https://www.mydoomsite.com/ |' -'| GitHub: https://github.com/Visual-Vincent |' -'| |' -'| |' -'| === COPYRIGHT LICENSE === |' -'| |' -'| Copyright (c) 2016-2019, Vincent Bengtsson |' -'| All rights reserved. |' -'| |' -'| Redistribution and use in source and binary forms, with or without |' -'| modification, are permitted provided that the following conditions are met: |' -'| |' -'| 1. Redistributions of source code must retain the above copyright notice, this |' -'| list of conditions and the following disclaimer. |' -'| |' -'| 2. Redistributions in binary form must reproduce the above copyright notice, |' -'| this list of conditions and the following disclaimer in the documentation |' -'| and/or other materials provided with the distribution. |' -'| |' -'| 3. Neither the name of the copyright holder nor the names of its |' -'| contributors may be used to endorse or promote products derived from |' -'| this software without specific prior written permission. |' -'| |' -'| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |' -'| AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |' -'| IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |' -'| DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |' -'| FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |' -'| DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |' -'| SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |' -'| CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |' -'| OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |' -'| OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |' -'+---------------------------------------------------------------------------------+' - -Imports System.Windows.Forms -Imports System.Runtime.InteropServices -Imports System.ComponentModel -Imports InputHelper.EventArgs - -Namespace Hooks - ''' - ''' A local keyboard hook that raises events when a key is pressed or released in a specific thread. - ''' - ''' - Public NotInheritable Class LocalKeyboardHook - Implements IDisposable - - ''' - ''' Occurs when a key is pressed or held down. - ''' - ''' - Public Event KeyDown As EventHandler(Of KeyboardHookEventArgs) - - ''' - ''' Occurs when a key is released. - ''' - ''' - Public Event KeyUp As EventHandler(Of KeyboardHookEventArgs) - - Private hHook As IntPtr = IntPtr.Zero - Private HookProcedureDelegate As New NativeMethods.KeyboardProc(AddressOf HookCallback) - - Private Modifiers As ModifierKeys = ModifierKeys.None - - Private Function HookCallback(ByVal nCode As Integer, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr - Dim Block As Boolean = False - - If nCode >= NativeMethods.HookCode.HC_ACTION Then - Dim KeyCode As Keys = CType(wParam.ToInt32(), Keys) - Dim KeyFlags As New NativeMethods.QWORD(lParam.ToInt64()) - Dim ScanCode As Byte = BitConverter.GetBytes(KeyFlags)(2) 'The scan code is the third byte in the integer (bits 16-23). - Dim Extended As Boolean = (KeyFlags.LowWord.High And NativeMethods.KeyboardFlags.KF_EXTENDED) = NativeMethods.KeyboardFlags.KF_EXTENDED - Dim AltDown As Boolean = (KeyFlags.LowWord.High And NativeMethods.KeyboardFlags.KF_ALTDOWN) = NativeMethods.KeyboardFlags.KF_ALTDOWN - Dim KeyUp As Boolean = (KeyFlags.LowWord.High And NativeMethods.KeyboardFlags.KF_UP) = NativeMethods.KeyboardFlags.KF_UP - - 'Set the ALT modifier if the KF_ALTDOWN flag is set. - If AltDown = True _ - AndAlso Internal.IsModifier(KeyCode, ModifierKeys.Alt) = False _ - AndAlso (Me.Modifiers And ModifierKeys.Alt) <> ModifierKeys.Alt Then - - Me.Modifiers = Me.Modifiers Or ModifierKeys.Alt - End If - - 'Raise KeyDown/KeyUp event. - If KeyUp = False Then - Dim HookEventArgs As New KeyboardHookEventArgs(KeyCode, ScanCode, Extended, KeyState.Down, Me.Modifiers) - - If Internal.IsModifier(KeyCode, ModifierKeys.Control) = True Then Me.Modifiers = Me.Modifiers Or ModifierKeys.Control - If Internal.IsModifier(KeyCode, ModifierKeys.Shift) = True Then Me.Modifiers = Me.Modifiers Or ModifierKeys.Shift - If Internal.IsModifier(KeyCode, ModifierKeys.Alt) = True Then Me.Modifiers = Me.Modifiers Or ModifierKeys.Alt - If Internal.IsModifier(KeyCode, ModifierKeys.Windows) = True Then Me.Modifiers = Me.Modifiers Or ModifierKeys.Windows - - RaiseEvent KeyDown(Me, HookEventArgs) - Block = HookEventArgs.Block - Else - 'Must be done before creating the HookEventArgs during KeyUp. - If Internal.IsModifier(KeyCode, ModifierKeys.Control) = True Then Me.Modifiers = Me.Modifiers And Not ModifierKeys.Control - If Internal.IsModifier(KeyCode, ModifierKeys.Shift) = True Then Me.Modifiers = Me.Modifiers And Not ModifierKeys.Shift - If Internal.IsModifier(KeyCode, ModifierKeys.Alt) = True Then Me.Modifiers = Me.Modifiers And Not ModifierKeys.Alt - If Internal.IsModifier(KeyCode, ModifierKeys.Windows) = True Then Me.Modifiers = Me.Modifiers And Not ModifierKeys.Windows - - Dim HookEventArgs As New KeyboardHookEventArgs(KeyCode, ScanCode, Extended, KeyState.Up, Me.Modifiers) - - RaiseEvent KeyUp(Me, HookEventArgs) - Block = HookEventArgs.Block - End If - End If - - Return If(Block, New IntPtr(1), NativeMethods.CallNextHookEx(hHook, nCode, wParam, lParam)) - End Function - - ''' - ''' Initializes a new instance of the LocalKeyboardHook class attached to the current thread. - ''' - ''' - Public Sub New() - Me.New(NativeMethods.GetCurrentThreadId()) - End Sub - - ''' - ''' Initializes a new instance of the LocalKeyboardHook class attached to the specified thread. - ''' - ''' The thread to attach the hook to. - ''' - Public Sub New(ByVal ThreadID As UInteger) - hHook = NativeMethods.SetWindowsHookEx(NativeMethods.HookType.WH_KEYBOARD, HookProcedureDelegate, IntPtr.Zero, ThreadID) - If hHook = IntPtr.Zero Then - Dim Win32Error As Integer = Marshal.GetLastWin32Error() - Throw New Win32Exception(Win32Error, "Failed to create local keyboard hook! (" & Win32Error & ")") - End If - End Sub - -#Region "IDisposable Support" - Private disposedValue As Boolean ' To detect redundant calls - - ' IDisposable - Protected Sub Dispose(disposing As Boolean) - If Not Me.disposedValue Then - If disposing Then - ' TODO: dispose managed state (managed objects). - End If - - ' TODO: free unmanaged resources (unmanaged objects) and override Finalize() below. - ' TODO: set large fields to null. - If hHook <> IntPtr.Zero Then NativeMethods.UnhookWindowsHookEx(hHook) - End If - Me.disposedValue = True - End Sub - - Protected Overrides Sub Finalize() - ' Do not change this code. Put cleanup code in Dispose(ByVal disposing As Boolean) above. - Dispose(False) - MyBase.Finalize() - End Sub - - ' This code added by Visual Basic to correctly implement the disposable pattern. - Public Sub Dispose() Implements IDisposable.Dispose - ' Do not change this code. Put cleanup code in Dispose(ByVal disposing As Boolean) above. - Dispose(True) - GC.SuppressFinalize(Me) - End Sub -#End Region - - End Class -End Namespace \ No newline at end of file diff --git a/InputHelper Library/InputHelper .NET 4.x/Input Handling/Mouse.vb b/InputHelper Library/InputHelper .NET 4.x/Input Handling/Mouse.vb deleted file mode 100644 index 7101995..0000000 --- a/InputHelper Library/InputHelper .NET 4.x/Input Handling/Mouse.vb +++ /dev/null @@ -1,164 +0,0 @@ -'+---------------------------------------------------------------------------------+' -'| === InputHelper === |' -'| |' -'| Created by Vincent "Visual Vincent" Bengtsson |' -'| Website: https://www.mydoomsite.com/ |' -'| GitHub: https://github.com/Visual-Vincent |' -'| |' -'| |' -'| === COPYRIGHT LICENSE === |' -'| |' -'| Copyright (c) 2016-2019, Vincent Bengtsson |' -'| All rights reserved. |' -'| |' -'| Redistribution and use in source and binary forms, with or without |' -'| modification, are permitted provided that the following conditions are met: |' -'| |' -'| 1. Redistributions of source code must retain the above copyright notice, this |' -'| list of conditions and the following disclaimer. |' -'| |' -'| 2. Redistributions in binary form must reproduce the above copyright notice, |' -'| this list of conditions and the following disclaimer in the documentation |' -'| and/or other materials provided with the distribution. |' -'| |' -'| 3. Neither the name of the copyright holder nor the names of its |' -'| contributors may be used to endorse or promote products derived from |' -'| this software without specific prior written permission. |' -'| |' -'| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |' -'| AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |' -'| IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |' -'| DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |' -'| FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |' -'| DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |' -'| SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |' -'| CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |' -'| OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |' -'| OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |' -'+---------------------------------------------------------------------------------+' - -Imports System.Drawing -Imports System.Windows.Forms -Imports System.Runtime.InteropServices - -''' -''' A static class for handling and simulating physical mouse input. -''' -''' -Public NotInheritable Class Mouse - Private Sub New() - End Sub - -#Region "Public methods" - -#Region "IsButtonDown()" - ''' - ''' Checks whether the specified mouse button is currently held down. - ''' - ''' The mouse button to check. - ''' - Public Shared Function IsButtonDown(ByVal Button As MouseButtons) As Boolean - Dim Key As Keys = Keys.None - Select Case Button - Case MouseButtons.Left : Key = Keys.LButton - Case MouseButtons.Middle : Key = Keys.MButton - Case MouseButtons.Right : Key = Keys.RButton - Case MouseButtons.XButton1 : Key = Keys.XButton1 - Case MouseButtons.XButton2 : Key = Keys.XButton2 - Case Else - Throw New ArgumentException("Invalid mouse button " & Button.ToString() & "!", "Button") - End Select - - Return Keyboard.IsKeyDown(Key) - End Function -#End Region - -#Region "IsButtonUp()" - ''' - ''' Checks whether the specified mouse button is currently NOT held down. - ''' - ''' The mouse button to check. - ''' - Public Shared Function IsButtonUp(ByVal Button As MouseButtons) As Boolean - Return Mouse.IsButtonDown(Button) = False - End Function -#End Region - -#Region "PressButton()" - ''' - ''' Simulates a mouse button click. - ''' - ''' The button to press. - ''' - Public Shared Sub PressButton(ByVal Button As MouseButtons) - Mouse.SetButtonState(Button, True) - Mouse.SetButtonState(Button, False) - End Sub -#End Region - -#Region "SetButtonState()" - ''' - ''' Simulates a mouse button being pushed down or released. - ''' - ''' The button which to simulate. - ''' Whether to push down or release the mouse button. - ''' - Public Shared Sub SetButtonState(ByVal Button As MouseButtons, ByVal MouseDown As Boolean) - Dim InputList As NativeMethods.INPUT() = _ - New NativeMethods.INPUT(1 - 1) {Mouse.GetMouseClickInputStructure(Button, MouseDown)} - NativeMethods.SendInput(CType(InputList.Length, UInteger), InputList, Marshal.SizeOf(GetType(NativeMethods.INPUT))) - End Sub -#End Region - -#End Region - -#Region "Internal methods" - -#Region "GetMouseClickInputStructure()" - ''' - ''' Constructs a native mouse INPUT structure for click events that can be passed to SendInput(). - ''' - ''' The button of the event. - ''' Whether to push down or release the mouse button. - ''' - Private Shared Function GetMouseClickInputStructure(ByVal Button As MouseButtons, ByVal MouseDown As Boolean) As NativeMethods.INPUT - Dim Position As Point = Cursor.Position - Dim MouseFlags As NativeMethods.MOUSEEVENTF - Dim MouseData As UInteger = 0 - - Select Case Button - Case MouseButtons.Left : MouseFlags = If(MouseDown, NativeMethods.MOUSEEVENTF.LEFTDOWN, NativeMethods.MOUSEEVENTF.LEFTUP) - Case MouseButtons.Middle : MouseFlags = If(MouseDown, NativeMethods.MOUSEEVENTF.MIDDLEDOWN, NativeMethods.MOUSEEVENTF.MIDDLEUP) - Case MouseButtons.Right : MouseFlags = If(MouseDown, NativeMethods.MOUSEEVENTF.RIGHTDOWN, NativeMethods.MOUSEEVENTF.RIGHTUP) - Case MouseButtons.XButton1 - MouseFlags = If(MouseDown, NativeMethods.MOUSEEVENTF.XDOWN, NativeMethods.MOUSEEVENTF.XUP) - MouseData = NativeMethods.MouseXButton.XBUTTON1 - Case MouseButtons.XButton2 - MouseFlags = If(MouseDown, NativeMethods.MOUSEEVENTF.XDOWN, NativeMethods.MOUSEEVENTF.XUP) - MouseData = NativeMethods.MouseXButton.XBUTTON2 - Case Else - Throw New ArgumentException("Invalid mouse button " & Button.ToString() & "!", "Button") - End Select - - Dim MouseInput As New NativeMethods.MOUSEINPUT With { - .dx = Position.X, - .dy = Position.Y, - .mouseData = MouseData, - .dwFlags = MouseFlags, - .time = 0, - .dwExtraInfo = UIntPtr.Zero - } - - Dim Union As New NativeMethods.INPUTUNION With {.mi = MouseInput} - Dim Input As New NativeMethods.INPUT With { - .type = NativeMethods.INPUTTYPE.MOUSE, - .U = Union - } - - Return Input - End Function -#End Region - -#End Region - -End Class \ No newline at end of file diff --git a/InputHelper Library/InputHelper .NET 4.x/Input Handling/WindowMessages.vb b/InputHelper Library/InputHelper .NET 4.x/Input Handling/WindowMessages.vb deleted file mode 100644 index 05a1c2a..0000000 --- a/InputHelper Library/InputHelper .NET 4.x/Input Handling/WindowMessages.vb +++ /dev/null @@ -1,679 +0,0 @@ -'+---------------------------------------------------------------------------------+' -'| === InputHelper === |' -'| |' -'| Created by Vincent "Visual Vincent" Bengtsson |' -'| Website: https://www.mydoomsite.com/ |' -'| GitHub: https://github.com/Visual-Vincent |' -'| |' -'| |' -'| === COPYRIGHT LICENSE === |' -'| |' -'| Copyright (c) 2016-2019, Vincent Bengtsson |' -'| All rights reserved. |' -'| |' -'| Redistribution and use in source and binary forms, with or without |' -'| modification, are permitted provided that the following conditions are met: |' -'| |' -'| 1. Redistributions of source code must retain the above copyright notice, this |' -'| list of conditions and the following disclaimer. |' -'| |' -'| 2. Redistributions in binary form must reproduce the above copyright notice, |' -'| this list of conditions and the following disclaimer in the documentation |' -'| and/or other materials provided with the distribution. |' -'| |' -'| 3. Neither the name of the copyright holder nor the names of its |' -'| contributors may be used to endorse or promote products derived from |' -'| this software without specific prior written permission. |' -'| |' -'| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |' -'| AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |' -'| IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |' -'| DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |' -'| FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |' -'| DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |' -'| SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |' -'| CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |' -'| OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |' -'| OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |' -'+---------------------------------------------------------------------------------+' - -Imports System.Drawing -Imports System.Windows.Forms -Imports System.Runtime.InteropServices -Imports System.Text - -''' -''' A static class for handling and simulating input via Window Messages. -''' -''' -Public NotInheritable Class WindowMessages - Private Sub New() - End Sub - -#Region "Fields" - ''' - ''' An array holding all keys' current states (down/up). - ''' - ''' - Private Shared KeyboardState As Byte() = New Byte(256 - 1) {} - - ''' - ''' Indicates whether we are currently in an ALT+numpad combination (ALT code). - ''' - ''' - Private Shared IsAltCodeCombination As Boolean = False - - ''' - ''' A list holding the keys pressed during an ALT+numpad combination. - ''' - ''' - Private Shared AltCode As New List(Of Keys) - - ''' - ''' Whether the current alt code is a Codepage 437 code. - ''' - ''' - Private Shared IsAltCodeCP437 As Boolean = False - - ''' - ''' Lookup table for Codepage 437-to-Unicode character codes. - ''' - ''' - Private Shared ReadOnly CP437LookupTable As Integer() = _ - New Integer(256 - 1) { _ - 0, 9786, 9787, 9829, 9830, 9827, 9824, _ - 8226, 9688, 9675, 9689, 9794, 9792, 9834, 9835, _ - 9788, 9658, 9668, 8597, 8252, 182, 167, 9644, _ - 8616, 8593, 8595, 8594, 8592, 8735, 8596, 9650, _ - 9660, 32, 33, 34, 35, 36, 37, 38, _ - 39, 40, 41, 42, 43, 44, 45, 46, _ - 47, 48, 49, 50, 51, 52, 53, 54, _ - 55, 56, 57, 58, 59, 60, 61, 62, _ - 63, 64, 65, 66, 67, 68, 69, 70, _ - 71, 72, 73, 74, 75, 76, 77, 78, _ - 79, 80, 81, 82, 83, 84, 85, 86, _ - 87, 88, 89, 90, 91, 92, 93, 94, _ - 95, 96, 97, 98, 99, 100, 101, 102, _ - 103, 104, 105, 106, 107, 108, 109, 110, _ - 111, 112, 113, 114, 115, 116, 117, 118, _ - 119, 120, 121, 122, 123, 124, 125, 126, _ - 8962, 199, 252, 233, 226, 228, 224, 229, _ - 231, 234, 235, 232, 239, 238, 236, 196, _ - 197, 201, 230, 198, 244, 246, 242, 251, _ - 249, 255, 214, 220, 162, 163, 165, 8359, _ - 402, 225, 237, 243, 250, 241, 209, 170, _ - 186, 191, 8976, 172, 189, 188, 161, 171, _ - 187, 9617, 9618, 9619, 9474, 9508, 9569, 9570, _ - 9558, 9557, 9571, 9553, 9559, 9565, 9564, 9563, _ - 9488, 9492, 9524, 9516, 9500, 9472, 9532, 9566, _ - 9567, 9562, 9556, 9577, 9574, 9568, 9552, 9580, _ - 9575, 9576, 9572, 9573, 9561, 9560, 9554, 9555, _ - 9579, 9578, 9496, 9484, 9608, 9604, 9612, 9616, _ - 9600, 945, 223, 915, 960, 931, 963, 181, _ - 964, 934, 920, 937, 948, 8734, 966, 949, _ - 8745, 8801, 177, 8805, 8804, 8992, 8993, 247, _ - 8776, 176, 8729, 183, 8730, 8319, 178, 9632, _ - 160 _ - } -#End Region - -#Region "Public methods" - -#Region "Keyboard" - -#Region "IsKeyDown()" - ''' - ''' Checks whether a specific key is down in InputHelper's internal keyboard state (not related to the physical keyboard!). - ''' - ''' The key to check. - ''' - Public Shared Function IsKeyDown(ByVal Key As Keys) As Boolean - If Internal.ExtractModifiers(Key).Length > 0 Then _ - Throw New ArgumentOutOfRangeException("Key", "Keys.Control, Keys.Shift and Keys.Alt is not valid in this context." & Environment.NewLine & _ - "Use Keys.ControlKey, Keys.ShiftKey and Keys.Menu instead.") - Return (WindowMessages.KeyboardState(CType(Key, Integer) And 255) And (1 << 7)) = (1 << 7) - End Function -#End Region - -#Region "IsKeyToggled()" - ''' - ''' Checks whether a specific key is toggled or not in InputHelper's internal keyboard state (not related to the physical keyboard!). - ''' - ''' The key to check (e.g. Keys.CapsLock, Keys.NumLock, etc.). - ''' - Public Shared Function IsKeyToggled(ByVal Key As Keys) As Boolean - If Internal.ExtractModifiers(Key).Length > 0 Then _ - Throw New ArgumentOutOfRangeException("Key", "Keys.Control, Keys.Shift and Keys.Alt is not valid in this context." & Environment.NewLine & _ - "Use Keys.ControlKey, Keys.ShiftKey and Keys.Menu instead.") - Return (WindowMessages.KeyboardState(CType(Key, Integer) And 255) And (1 << 0)) = (1 << 0) - End Function -#End Region - -#Region "IsModifierDown()" - ''' - ''' Checks whether any Left or Right version of a modifier is down in InputHelper's internal keyboard state (not related to the physical keyboard!). - ''' - ''' The modifier to check. - ''' - Public Shared Function IsModifierDown(ByVal Modifier As ModifierKeys) As Boolean - Select Case Modifier - Case ModifierKeys.Control - Return WindowMessages.IsKeyDown(Keys.ControlKey) OrElse _ - WindowMessages.IsKeyDown(Keys.LControlKey) OrElse _ - WindowMessages.IsKeyDown(Keys.RControlKey) - Case ModifierKeys.Shift - Return WindowMessages.IsKeyDown(Keys.ShiftKey) OrElse _ - WindowMessages.IsKeyDown(Keys.LShiftKey) OrElse _ - WindowMessages.IsKeyDown(Keys.RShiftKey) - Case ModifierKeys.Alt - Return WindowMessages.IsKeyDown(Keys.Menu) OrElse _ - WindowMessages.IsKeyDown(Keys.LMenu) OrElse _ - WindowMessages.IsKeyDown(Keys.RMenu) - Case ModifierKeys.Windows - Return WindowMessages.IsKeyDown(Keys.LWin) OrElse _ - WindowMessages.IsKeyDown(Keys.RWin) - End Select - Throw New ArgumentOutOfRangeException("Modifier", CType(Modifier, Integer) & " is not a valid modifier key!") - End Function -#End Region - -#Region "SendAltCode()" - ''' - ''' Sends an ALT code message to the active window. - ''' - ''' The numpad combination to send. - ''' - Public Shared Sub SendAltCode(ByVal NumpadKeys As Keys()) - Dim ActiveWindow As IntPtr = WindowMessages.GetAbsoluteActiveWindow() - WindowMessages.SendAltCode(ActiveWindow, NumpadKeys) - End Sub - - ''' - ''' Sends an ALT code message to a window. - ''' - ''' The handle of the window to send the ALT code message to. - ''' The numpad combination to send. - ''' - Public Shared Sub SendAltCode(ByVal WindowHandle As IntPtr, ByVal NumpadKeys As Keys()) - If NumpadKeys.Any(Function(k As Keys) k < Keys.NumPad0 OrElse k > Keys.NumPad9) = True Then _ - Throw New ArgumentOutOfRangeException("NumpadKeys", "Only Keys.NumPad0 through Keys.NumPad9 are allowed to be passed to this method.") - - Dim LoopTo As Integer = If(NumpadKeys.Length > 4, 4, NumpadKeys.Length) - 1 - - If NumpadKeys(0) = Keys.NumPad0 Then 'Windows-1252 ALT code. - - WindowMessages.SendKey(WindowHandle, Keys.Alt, True) - For x = 0 To LoopTo - WindowMessages.SendKeyPress(WindowHandle, NumpadKeys(x)) - Next - WindowMessages.SendKey(WindowHandle, Keys.Alt, False) - - Else 'Codepage 437 ALT code. - - WindowMessages.SendKey(WindowHandle, Keys.Alt, True) - For x = 0 To LoopTo - WindowMessages.SendKey(WindowHandle, NumpadKeys(x), True) - If x = LoopTo Then - WindowMessages.SendKey(WindowHandle, Keys.Alt, False) 'Release ALT before sending KeyUp of the last key. - End If - WindowMessages.SendKey(WindowHandle, NumpadKeys(x), False) - Next - - End If - End Sub -#End Region - -#Region "SendKey()" - ''' - ''' Sends a KeyDown/KeyUp message to the active window. - ''' - ''' The key to send. - ''' Whether to send a KeyDown or KeyUp message. - ''' Whether to send the hardware scan code along with the virtual key code (recommended to be 'True'!). - ''' Whether or not to wait for the window to handle the message before continuing. - ''' - Public Shared Sub SendKey(ByVal Key As Keys, ByVal KeyDown As Boolean, Optional ByVal HardwareKey As Boolean = True, Optional ByVal SendAsynchronously As Boolean = False) - Dim ActiveWindow As IntPtr = InputHelper.WindowMessages.GetAbsoluteActiveWindow() - WindowMessages.SendKey(ActiveWindow, Key, KeyDown, HardwareKey, SendAsynchronously) - End Sub - - ''' - ''' Sends a KeyDown/KeyUp message to a window. - ''' - ''' The handle of the window to send the key message to. - ''' The key to send. - ''' Whether to send a KeyDown or KeyUp message. - ''' Whether to send the hardware scan code along with the virtual key code (recommended to be 'True'!). - ''' Whether or not to wait for the window to handle the message before continuing. - ''' - Public Shared Sub SendKey(ByVal WindowHandle As IntPtr, ByVal Key As Keys, ByVal KeyDown As Boolean, Optional ByVal HardwareKey As Boolean = True, Optional ByVal SendAsynchronously As Boolean = False) - Dim Modifiers As Keys() = Internal.ExtractModifiers(Key) - - 'Send the modifiers first. - For Each Modifier As Keys In Modifiers - WindowMessages.InternalSendKey(WindowHandle, Modifier, KeyDown, HardwareKey, SendAsynchronously) - Next - - If Key = Keys.None Then Return 'We only sent modifiers. - - WindowMessages.InternalSendKey(WindowHandle, Key, KeyDown, HardwareKey, SendAsynchronously) - End Sub -#End Region - -#Region "SendKeyPress()" - ''' - ''' Sends a keystroke message to the active window. - ''' - ''' The key to send. - ''' Whether to send the hardware scan code along with the virtual key code (recommended to be 'True'!). - ''' Whether or not to wait for the window to handle the message before continuing. - ''' - Public Shared Sub SendKeyPress(ByVal Key As Keys, Optional ByVal HardwareKey As Boolean = True, Optional ByVal SendAsynchronously As Boolean = False) - WindowMessages.SendKey(Key, True, HardwareKey, SendAsynchronously) - WindowMessages.SendKey(Key, False, HardwareKey, SendAsynchronously) - End Sub - - ''' - ''' Sends a keystroke message to a window. - ''' - ''' The handle of the window to send the keystroke message to. - ''' The key to send. - ''' Whether to send the hardware scan code along with the virtual key code (recommended to be 'True'!). - ''' Whether or not to wait for the window to handle the message before continuing. - ''' - Public Shared Sub SendKeyPress(ByVal WindowHandle As IntPtr, ByVal Key As Keys, Optional ByVal HardwareKey As Boolean = True, Optional ByVal SendAsynchronously As Boolean = False) - WindowMessages.SendKey(WindowHandle, Key, True, HardwareKey, SendAsynchronously) - WindowMessages.SendKey(WindowHandle, Key, False, HardwareKey, SendAsynchronously) - End Sub -#End Region - -#Region "ToggleKey()" - ''' - ''' Toggles a specific key in InputHelper's internal keyboard state (not related to the physical keyboard!). Use only with toggleable keys! - ''' - ''' The key to toggle (e.g. Keys.CapsLock, Keys.NumLock, etc.). - ''' Whether to mark the key as toggled or untoggled (Nothing/Null = toggle automatically). - ''' - Public Shared Sub ToggleKey(ByVal Key As Keys, Optional ByVal SetToggled As Nullable(Of Boolean) = Nothing) - Dim Modifiers As Keys() = Internal.ExtractModifiers(Key) - - If SetToggled Is Nothing Then 'Toggle the key. - For Each Modifier As Keys In Modifiers - Dim ModifierIndex As Integer = CType(Modifier, Integer) And 255 'Cap index between 0-255. - WindowMessages.KeyboardState(ModifierIndex) = WindowMessages.KeyboardState(ModifierIndex) Xor (1 << 0) 'Toggle the least significant bit. - Next - - If Key = Keys.None Then Return 'We toggled modifiers only. - - Dim Index As Integer = CType(Key, Integer) And 255 'Cap index between 0-255. - WindowMessages.KeyboardState(Index) = WindowMessages.KeyboardState(Index) Xor (1 << 0) 'Toggle the least significant bit. - - Else 'Set the key to a specific value (toggled/untoggled) - For Each Modifier As Keys In Modifiers - Dim ModifierIndex As Integer = CType(Modifier, Integer) And 255 'Cap index between 0-255. - If SetToggled = True Then - WindowMessages.KeyboardState(ModifierIndex) = WindowMessages.KeyboardState(ModifierIndex) Or (1 << 0) 'Set the least significant bit. - Else - WindowMessages.KeyboardState(ModifierIndex) = WindowMessages.KeyboardState(ModifierIndex) And Not (1 << 0) 'Unset the least significant bit. - End If - Next - - If Key = Keys.None Then Return 'We set modifiers only. - - Dim Index As Integer = CType(Key, Integer) And 255 'Cap index between 0-255. - If SetToggled = True Then - WindowMessages.KeyboardState(Index) = WindowMessages.KeyboardState(Index) Or (1 << 0) 'Set the least significant bit. - Else - WindowMessages.KeyboardState(Index) = WindowMessages.KeyboardState(Index) And Not (1 << 0) 'Unset the least significant bit. - End If - - End If - End Sub -#End Region - -#End Region - -#Region "Mouse" - -#Region "SendMouseClick()" - ''' - ''' Sends a Window Message-based mouse click to the window located at the specified coordinates of the screen. - ''' The coordinates are automatically translated to client coordinates and the click occurs in that specific point of the window. - ''' - ''' The button to press. - ''' The position where to send the click (in screen coordinates). - ''' - Public Shared Sub SendMouseClick(ByVal Button As MouseButtons, ByVal Location As Point) - WindowMessages.SendMouseClick(Button, Location, True, False) - WindowMessages.SendMouseClick(Button, Location, False, False) - End Sub - - ''' - ''' Sends a Window Message-based mouse click to the window located at the specified coordinates of the screen. - ''' The coordinates are automatically translated to client coordinates and the click occurs in that specific point of the window. - ''' - ''' The button to press. - ''' The position where to send the click (in screen coordinates). - ''' Whether to push down or release the mouse button. - ''' Whether or not to wait for the window to handle the message before continuing. - ''' - Public Shared Sub SendMouseClick(ByVal Button As MouseButtons, ByVal Location As Point, ByVal MouseDown As Boolean, Optional ByVal SendAsynchronously As Boolean = False) - Dim hWnd As IntPtr = NativeMethods.WindowFromPoint(New NativeMethods.NATIVEPOINT(Location.X, Location.Y)) 'Get the window at the specified click point. - Dim ButtonMessage As NativeMethods.MouseMessage 'A variable holding which Window Message to use. - - Select Case Button 'Set the appropriate mouse button Window Message. - Case MouseButtons.Left : ButtonMessage = If(MouseDown, NativeMethods.MouseMessage.WM_LBUTTONDOWN, NativeMethods.MouseMessage.WM_LBUTTONUP) - Case MouseButtons.Right : ButtonMessage = If(MouseDown, NativeMethods.MouseMessage.WM_RBUTTONDOWN, NativeMethods.MouseMessage.WM_RBUTTONUP) - Case MouseButtons.Middle : ButtonMessage = If(MouseDown, NativeMethods.MouseMessage.WM_MBUTTONDOWN, NativeMethods.MouseMessage.WM_MBUTTONUP) - Case MouseButtons.XButton1, MouseButtons.XButton2 - ButtonMessage = NativeMethods.MouseMessage.WM_XBUTTONDOWN - Case Else - Throw New ArgumentException("Invalid mouse button " & Button.ToString() & "!", "Button") - End Select - - Dim ClickPoint As New NativeMethods.NATIVEPOINT(Location.X, Location.Y) 'Create a native point. - - If NativeMethods.ScreenToClient(hWnd, ClickPoint) = False Then 'Convert the click point to client coordinates relative to the window. - Throw New Exception("Unable to convert screen coordinates to client coordinates! Win32Err: " & _ - Marshal.GetLastWin32Error()) - End If - - Dim wParam As IntPtr = IntPtr.Zero 'Used to specify which X button was clicked (if any). - Dim lParam As IntPtr = New NativeMethods.DWORD(CType(ClickPoint.x And Short.MaxValue, Short), CType(ClickPoint.y And Short.MaxValue, Short)) 'Click point. - - If Button = MouseButtons.XButton1 OrElse _ - Button = MouseButtons.XButton2 Then - wParam = New NativeMethods.DWORD(0US, CType(Button / MouseButtons.XButton1, UShort)) 'Set the correct XButton. - End If - - InputHelper.WindowMessages.SendMessage(hWnd, ButtonMessage, wParam, lParam, SendAsynchronously) - End Sub -#End Region - -#End Region - -#Region "Miscellaneous" - -#Region "GetActiveWindow()" - ''' - ''' Gets the active top-level window. - ''' - ''' - Public Shared Function GetActiveWindow() As IntPtr - Return NativeMethods.GetForegroundWindow() - End Function -#End Region - -#Region "GetAbsoluteActiveWindow()" - ''' - ''' Gets the (absolute) active top-level window or child window (apart from GetActiveWindow() which will only get the active top-level window). - ''' - ''' - Public Shared Function GetAbsoluteActiveWindow() As IntPtr - Dim CurrentThreadID As UInteger = NativeMethods.GetCurrentThreadId() - Dim ActiveWindow As IntPtr = NativeMethods.GetForegroundWindow() - Dim ActiveThread As UInteger = NativeMethods.GetWindowThreadProcessId(ActiveWindow, Nothing) - - If ActiveThread = 0 Then _ - Return ActiveWindow - - If NativeMethods.AttachThreadInput(CurrentThreadID, ActiveThread, True) = False Then _ - Return ActiveWindow - - Dim AbsoluteActiveWindow As IntPtr = NativeMethods.GetFocus() - Dim DetachAttempts As Integer = 0 - - While NativeMethods.AttachThreadInput(CurrentThreadID, ActiveThread, False) = False - DetachAttempts += 1 - If DetachAttempts >= 10 Then Exit While - Threading.Thread.Sleep(1) - End While - - Return AbsoluteActiveWindow - End Function -#End Region - -#End Region - -#End Region - -#Region "Internal methods" - -#Region "GetKeyWindowMessage()" - ''' - ''' Gets the window message type of the specified key. - ''' - ''' The key to use for the message. - ''' Whether this is a KeyDown or KeyUp message. - ''' - Private Shared Function GetKeyWindowMessage(ByVal Key As Keys, ByVal KeyDown As Boolean) As NativeMethods.KeyMessage - Dim IsAlt As Boolean = ( _ - (Key And Keys.Alt) = Keys.Alt _ - OrElse Key = Keys.Menu _ - OrElse Key = Keys.LMenu _ - OrElse Key = Keys.RMenu _ - ) - - Dim SystemKey As Boolean = ( _ - ( _ - IsAlt _ - OrElse Key = Keys.F10 _ - OrElse WindowMessages.IsKeyDown(Keys.Menu) _ - OrElse WindowMessages.IsKeyDown(Keys.LMenu) _ - OrElse WindowMessages.IsKeyDown(Keys.RMenu) _ - ) _ - AndAlso Not (IsAlt = True AndAlso KeyDown = False) - ) - - If SystemKey = True Then _ - Return If(KeyDown, NativeMethods.KeyMessage.WM_SYSKEYDOWN, NativeMethods.KeyMessage.WM_SYSKEYUP) - - Return If(KeyDown, NativeMethods.KeyMessage.WM_KEYDOWN, NativeMethods.KeyMessage.WM_KEYUP) - End Function -#End Region - -#Region "InternalSendKey()" - ''' - ''' Internal method for sending KeyDown/KeyUp messages to a specific window (DOES NOT HANDLE MODIFIERS! USE 'SendKey()' INSTEAD!). - ''' - ''' The handle to the window to send the keystrokes to. - ''' The key to send. - ''' Whether to send a KeyDown or KeyUp message. - ''' Whether to send the hardware scan code along with the virtual key code (recommended to be 'True'!). - ''' Whether or not to wait for the window to handle the message before continuing. - ''' - Private Shared Sub InternalSendKey(ByVal WindowHandle As IntPtr, ByVal Key As Keys, ByVal KeyDown As Boolean, ByVal HardwareKey As Boolean, ByVal SendAsynchronously As Boolean) - Dim KeyboardLayout As IntPtr = NativeMethods.GetKeyboardLayout(0) - Dim Message As NativeMethods.KeyMessage = WindowMessages.GetKeyWindowMessage(Key, KeyDown) - Dim lParam As IntPtr = WindowMessages.MakeKeyLParam(Key, KeyDown, HardwareKey) - Dim KeyCode As UInteger = CType(Key And UInteger.MaxValue, UInteger) - Dim ScanCode As UInteger = If(HardwareKey, NativeMethods.MapVirtualKeyEx(KeyCode, 0, KeyboardLayout), 0) - - Dim CharBuffer As New StringBuilder(16) - Dim CharCode As UInteger = NativeMethods.MapVirtualKeyEx(KeyCode, 2, KeyboardLayout) - Dim CharacterConversionResult As Integer = -1 - - Dim IsDeadChar As Boolean = (CharCode And (1 << 31)) = (CType(1, UInteger) << 31) 'If the most significant bit is set the key is a dead char. - Dim IsAltDown As Boolean = WindowMessages.IsModifierDown(ModifierKeys.Alt) - Dim IsAlt As Boolean = Internal.IsModifier(Key, ModifierKeys.Alt) - Dim AltUp As Boolean = (IsAlt = True AndAlso IsAltDown = True AndAlso KeyDown = False) - Dim IsNumpadNumber As Boolean = (KeyCode >= CType(Keys.NumPad0, UInteger) AndAlso KeyCode <= CType(Keys.NumPad9, UInteger)) - - 'Is this an ALT+numpad combination? - If WindowMessages.IsAltCodeCombination = False AndAlso IsAltDown = True AndAlso IsNumpadNumber = True Then - WindowMessages.IsAltCodeCombination = True 'Begin an ALT+numpad combination. - End If - - 'Check the key's state. - If KeyDown = True Then - WindowMessages.KeyboardState(CType(Key, Integer)) = (1 << 7) 'Set the most significant bit if the key is down. - Else - WindowMessages.KeyboardState(CType(Key, Integer)) = 0 'Unset value if key is up. - End If - - 'Must be done AFTER the key state has been changed. - If KeyDown = True AndAlso WindowMessages.IsAltCodeCombination = False Then - CharacterConversionResult = _ - NativeMethods.ToUnicodeEx(KeyCode, ScanCode, WindowMessages.KeyboardState, CharBuffer, CharBuffer.Capacity, 0, KeyboardLayout) - End If - - 'Verify conversion result. - If CharacterConversionResult = 0 Then 'Conversion failed. Try MapVirtualKeyEx() instead. - CharBuffer.Clear() - - Dim MappedCharCode As UInteger = NativeMethods.MapVirtualKeyEx(KeyCode, 2, KeyboardLayout) And Not (1 << 31) - If MappedCharCode <> 0 Then CharBuffer.Append(Convert.ToChar(MappedCharCode)) - - ElseIf CharacterConversionResult > 0 Then 'Conversion succeded. - CharBuffer.Remove(CharacterConversionResult, CharBuffer.Length - CharacterConversionResult) 'Truncate CharBuffer to the amount of chars we want. - - End If - - 'Send the actual key press. - WindowMessages.SendMessage(WindowHandle, Message, New IntPtr(Key), lParam, SendAsynchronously) - - - - 'Is this the end of an ALT+numpad combination? - If KeyDown = False AndAlso IsAlt = True AndAlso WindowMessages.IsAltCodeCombination = True AndAlso AltCode.Count > 0 Then - WindowMessages.IsAltCodeCombination = False 'ALT is being released, end ALT+numpad combination. - - Dim NumberString As String = "" - For x = 0 To WindowMessages.AltCode.Count - 1 - If WindowMessages.AltCode(x) = Keys.NumPad0 AndAlso x = 0 Then Continue For 'Skip the first key if it's a zero. - NumberString &= Convert.ToChar(NativeMethods.MapVirtualKeyEx(WindowMessages.AltCode(x), 2, KeyboardLayout)) 'Convert each key into a digit character. - Next - - Dim AltCodeNumber As Byte = 0 'The ALT code can only range from 0-255. - - If Byte.TryParse(NumberString, AltCodeNumber) = True Then - - If WindowMessages.AltCode(0) = Keys.NumPad0 Then 'Windows-1252 ALT codes start with zero. - Dim DecodedBytes As Byte() = Encoding.Convert(Constants.Windows1252, Encoding.UTF8, New Byte() {AltCodeNumber}) - Dim DecodedChars As Char() = Encoding.UTF8.GetChars(DecodedBytes) - - If DecodedChars.Length >= 1 Then 'Send the resulting char. - WindowMessages.SendMessage(WindowHandle, NativeMethods.KeyMessage.WM_CHAR, New IntPtr(Convert.ToInt32(DecodedChars(0))), lParam, SendAsynchronously) - End If - - Else 'Codepage 437 ALT code. - WindowMessages.SendMessage(WindowHandle, NativeMethods.KeyMessage.WM_CHAR, New IntPtr(WindowMessages.CP437LookupTable(AltCodeNumber)), lParam, SendAsynchronously) - End If - - End If - - AltCode.Clear() 'Clear the combination list. - End If - - - - 'Shall we send a WM_CHAR/WM_DEADCHAR message or is this an ALT+numpad combination? - If KeyDown = True AndAlso WindowMessages.IsAltCodeCombination = False Then - If IsDeadChar = False Then - Dim CharMessage As NativeMethods.KeyMessage = If(IsAltDown, NativeMethods.KeyMessage.WM_SYSCHAR, NativeMethods.KeyMessage.WM_CHAR) - - 'Send WM_CHAR or WM_SYSCHAR. - For Each c As Char In CharBuffer.ToString() - WindowMessages.SendMessage(WindowHandle, CharMessage, New IntPtr(Convert.ToInt32(c)), lParam, SendAsynchronously) - Next - Else - Dim CharMessage As NativeMethods.KeyMessage = If(IsAltDown, NativeMethods.KeyMessage.WM_SYSDEADCHAR, NativeMethods.KeyMessage.WM_DEADCHAR) - - 'Send WM_DEADCHAR or WM_SYSDEADCHAR for dead characters (ex: `, ´, ^, ¨, ~, etc.). - WindowMessages.SendMessage(WindowHandle, NativeMethods.KeyMessage.WM_DEADCHAR, New IntPtr(CharCode And Not (1 << 31)), lParam, SendAsynchronously) - End If - - ElseIf KeyDown = True AndAlso WindowMessages.IsAltCodeCombination = True Then - If IsNumpadNumber = True Then - WindowMessages.AltCode.Add(Key) 'Add numpad number to ALT+numpad combination. - Else - WindowMessages.AltCode.Clear() 'Invalid char, reset combination. - End If - - End If - End Sub -#End Region - -#Region "MakeKeyLParam()" - ''' - ''' Constructs the lParam parameter of a key message. - ''' - ''' The key of the message. - ''' Whether this is a KeyDown or KeyUp message. - ''' Whether to include the key's hardware scan code in the lParam parameter (recommended to be 'True'!). - ''' - Private Shared Function MakeKeyLParam(ByVal Key As Keys, ByVal KeyDown As Boolean, ByVal HardwareKey As Boolean) As IntPtr - Dim ScanCode As UInteger = NativeMethods.MapVirtualKeyEx(CType(Key And UInteger.MaxValue, UInteger), 0, NativeMethods.GetKeyboardLayout(0)) - Dim lParam As Integer = (1 << 0) Or If(HardwareKey, (ScanCode And Integer.MaxValue), 0) << 16 'Set bit 16-23 to the Scan code if HardwareKey = True. - - Dim IsAlt As Boolean = ( _ - (Key And Keys.Alt) = Keys.Alt _ - OrElse Key = Keys.Menu _ - OrElse Key = Keys.LMenu _ - OrElse Key = Keys.RMenu _ - ) - - Dim SystemKey As Boolean = ( _ - ( _ - IsAlt _ - OrElse Key = Keys.F10 _ - OrElse WindowMessages.IsKeyDown(Keys.Menu) _ - OrElse WindowMessages.IsKeyDown(Keys.LMenu) _ - OrElse WindowMessages.IsKeyDown(Keys.RMenu) _ - ) _ - AndAlso Not (IsAlt = True AndAlso KeyDown = False) _ - ) - - Dim IsExtendedKey As Boolean = ( _ - Key = Keys.LControlKey OrElse _ - Key = Keys.RControlKey OrElse _ - Key = Keys.LShiftKey OrElse _ - Key = Keys.RShiftKey OrElse _ - Key = Keys.LMenu OrElse _ - Key = Keys.RMenu _ - ) - - If KeyDown = False Then - 'Set bit 30 and 31 to '1' when sending WM_KEYUP or WM_SYSKEYUP: - 'https://msdn.microsoft.com/en-us/library/windows/desktop/ms646281(v=vs.85).aspx - lParam = (lParam Or (1 << 30)) Or (1 << 31) - End If - - If SystemKey = True Then - 'Set bit 29 to '1', indicates that ALT is held down: - 'https://msdn.microsoft.com/en-us/library/windows/desktop/ms646286(v=vs.85).aspx - lParam = lParam Or (1 << 29) - End If - - If IsExtendedKey = True Then - 'Set bit 24 to '1' if this is an extended key: - 'https://msdn.microsoft.com/en-us/library/windows/desktop/ms646280(v=vs.85).aspx - lParam = lParam Or (1 << 24) - End If - - Return New IntPtr(lParam) - End Function -#End Region - -#Region "SendMessage()" - ''' - ''' Sends or posts a message to a window's message queue. - ''' - ''' The handle of the window to send the message to. - ''' The window message to send. - ''' The wParam of the message. - ''' The lParam of the message. - ''' Whether to post or send the message to the window's message queue. - ''' - Private Shared Sub SendMessage(ByVal hWnd As IntPtr, ByVal Msg As UInteger, ByVal wParam As IntPtr, ByVal lParam As IntPtr, ByVal Asynchronous As Boolean) - If Asynchronous = True Then - NativeMethods.PostMessage(hWnd, Msg, wParam, lParam) - Else - NativeMethods.SendMessage(hWnd, Msg, wParam, lParam) - End If - End Sub -#End Region - -#End Region - -End Class \ No newline at end of file diff --git a/InputHelper Library/InputHelper .NET 4.x/InputHelper .NET 4.x.vbproj b/InputHelper Library/InputHelper .NET 4.x/InputHelper .NET 4.x.vbproj deleted file mode 100644 index a3d82db..0000000 --- a/InputHelper Library/InputHelper .NET 4.x/InputHelper .NET 4.x.vbproj +++ /dev/null @@ -1,131 +0,0 @@ - - - - Debug - AnyCPU - - - - - {98BAEFE8-002F-42B9-ADA2-F0E0B888499D} - Library - InputHelper - InputHelper - 512 - Windows - v4.0 - - - true - full - true - true - bin\Debug\ - InputHelper.xml - 42016,41999,42017,42018,42019,42032,42036,42020,42021,42022 - - - pdbonly - false - true - true - bin\Release\ - InputHelper.xml - 42016,41999,42017,42018,42019,42032,42036,42020,42021,42022 - - - On - - - Binary - - - Off - - - On - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - True - Application.myapp - - - - True - True - Resources.resx - - - True - Settings.settings - True - - - - - - VbMyResourcesResXFileCodeGenerator - Resources.Designer.vb - My.Resources - Designer - - - - - MyApplicationCodeGenerator - Application.Designer.vb - - - SettingsSingleFileGenerator - My - Settings.Designer.vb - - - - - PreserveNewest - - - - - - \ No newline at end of file diff --git a/InputHelper Library/InputHelper .NET 4.x/LICENSE.txt b/InputHelper Library/InputHelper .NET 4.x/LICENSE.txt deleted file mode 100644 index 80a909e..0000000 --- a/InputHelper Library/InputHelper .NET 4.x/LICENSE.txt +++ /dev/null @@ -1,38 +0,0 @@ -+---------------------------------------------------------------------------------+ -| === InputHelper === | -| | -| Created by Vincent "Visual Vincent" Bengtsson | -| Website: https://www.mydoomsite.com/ | -| GitHub: https://github.com/Visual-Vincent | -| | -| | -| === COPYRIGHT LICENSE === | -| | -| Copyright (c) 2016-2019, Vincent Bengtsson | -| All rights reserved. | -| | -| Redistribution and use in source and binary forms, with or without | -| modification, are permitted provided that the following conditions are met: | -| | -| 1. Redistributions of source code must retain the above copyright notice, this | -| list of conditions and the following disclaimer. | -| | -| 2. Redistributions in binary form must reproduce the above copyright notice, | -| this list of conditions and the following disclaimer in the documentation | -| and/or other materials provided with the distribution. | -| | -| 3. Neither the name of the copyright holder nor the names of its | -| contributors may be used to endorse or promote products derived from | -| this software without specific prior written permission. | -| | -| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | -| AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | -| IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | -| DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | -| FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | -| DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | -| SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | -| CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | -| OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | -| OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | -+---------------------------------------------------------------------------------+ \ No newline at end of file diff --git a/InputHelper Library/InputHelper .NET 4.x/My Project/Application.Designer.vb b/InputHelper Library/InputHelper .NET 4.x/My Project/Application.Designer.vb deleted file mode 100644 index 88dd01c..0000000 --- a/InputHelper Library/InputHelper .NET 4.x/My Project/Application.Designer.vb +++ /dev/null @@ -1,13 +0,0 @@ -'------------------------------------------------------------------------------ -' -' This code was generated by a tool. -' Runtime Version:4.0.30319.42000 -' -' Changes to this file may cause incorrect behavior and will be lost if -' the code is regenerated. -' -'------------------------------------------------------------------------------ - -Option Strict On -Option Explicit On - diff --git a/InputHelper Library/InputHelper .NET 4.x/My Project/Application.myapp b/InputHelper Library/InputHelper .NET 4.x/My Project/Application.myapp deleted file mode 100644 index 758895d..0000000 --- a/InputHelper Library/InputHelper .NET 4.x/My Project/Application.myapp +++ /dev/null @@ -1,10 +0,0 @@ - - - false - false - 0 - true - 0 - 1 - true - diff --git a/InputHelper Library/InputHelper .NET 4.x/My Project/AssemblyInfo.vb b/InputHelper Library/InputHelper .NET 4.x/My Project/AssemblyInfo.vb deleted file mode 100644 index c925707..0000000 --- a/InputHelper Library/InputHelper .NET 4.x/My Project/AssemblyInfo.vb +++ /dev/null @@ -1,38 +0,0 @@ -Imports System.Resources - -Imports System -Imports System.Reflection -Imports System.Runtime.InteropServices - -' General Information about an assembly is controlled through the following -' set of attributes. Change these attribute values to modify the information -' associated with an assembly. - -' Review the values of the assembly attributes - - - - - - - - - - -'The following GUID is for the ID of the typelib if this project is exposed to COM - - -' Version information for an assembly consists of the following four values: -' -' Major Version -' Minor Version -' Build Number -' Revision -' -' You can specify all the values or you can default the Build and Revision Numbers -' by using the '*' as shown below: -' - - - - \ No newline at end of file diff --git a/InputHelper Library/InputHelper .NET 4.x/My Project/Resources.Designer.vb b/InputHelper Library/InputHelper .NET 4.x/My Project/Resources.Designer.vb deleted file mode 100644 index 8d4decd..0000000 --- a/InputHelper Library/InputHelper .NET 4.x/My Project/Resources.Designer.vb +++ /dev/null @@ -1,63 +0,0 @@ -'------------------------------------------------------------------------------ -' -' This code was generated by a tool. -' Runtime Version:4.0.30319.42000 -' -' Changes to this file may cause incorrect behavior and will be lost if -' the code is regenerated. -' -'------------------------------------------------------------------------------ - -Option Strict On -Option Explicit On - -Imports System - -Namespace My.Resources - - 'This class was auto-generated by the StronglyTypedResourceBuilder - 'class via a tool like ResGen or Visual Studio. - 'To add or remove a member, edit your .ResX file then rerun ResGen - 'with the /str option, or rebuild your VS project. - ''' - ''' A strongly-typed resource class, for looking up localized strings, etc. - ''' - _ - Friend Module Resources - - Private resourceMan As Global.System.Resources.ResourceManager - - Private resourceCulture As Global.System.Globalization.CultureInfo - - ''' - ''' Returns the cached ResourceManager instance used by this class. - ''' - _ - Friend ReadOnly Property ResourceManager() As Global.System.Resources.ResourceManager - Get - If Object.ReferenceEquals(resourceMan, Nothing) Then - Dim temp As Global.System.Resources.ResourceManager = New Global.System.Resources.ResourceManager("InputHelper.Resources", GetType(Resources).Assembly) - resourceMan = temp - End If - Return resourceMan - End Get - End Property - - ''' - ''' Overrides the current thread's CurrentUICulture property for all - ''' resource lookups using this strongly typed resource class. - ''' - _ - Friend Property Culture() As Global.System.Globalization.CultureInfo - Get - Return resourceCulture - End Get - Set - resourceCulture = value - End Set - End Property - End Module -End Namespace diff --git a/InputHelper Library/InputHelper .NET 4.x/My Project/Resources.resx b/InputHelper Library/InputHelper .NET 4.x/My Project/Resources.resx deleted file mode 100644 index af7dbeb..0000000 --- a/InputHelper Library/InputHelper .NET 4.x/My Project/Resources.resx +++ /dev/null @@ -1,117 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - \ No newline at end of file diff --git a/InputHelper Library/InputHelper .NET 4.x/My Project/Settings.Designer.vb b/InputHelper Library/InputHelper .NET 4.x/My Project/Settings.Designer.vb deleted file mode 100644 index 6dc7e51..0000000 --- a/InputHelper Library/InputHelper .NET 4.x/My Project/Settings.Designer.vb +++ /dev/null @@ -1,73 +0,0 @@ -'------------------------------------------------------------------------------ -' -' This code was generated by a tool. -' Runtime Version:4.0.30319.42000 -' -' Changes to this file may cause incorrect behavior and will be lost if -' the code is regenerated. -' -'------------------------------------------------------------------------------ - -Option Strict On -Option Explicit On - - -Namespace My - - _ - Partial Friend NotInheritable Class MySettings - Inherits Global.System.Configuration.ApplicationSettingsBase - - Private Shared defaultInstance As MySettings = CType(Global.System.Configuration.ApplicationSettingsBase.Synchronized(New MySettings()),MySettings) - -#Region "My.Settings Auto-Save Functionality" -#If _MyType = "WindowsForms" Then - Private Shared addedHandler As Boolean - - Private Shared addedHandlerLockObject As New Object - - _ - Private Shared Sub AutoSaveSettings(ByVal sender As Global.System.Object, ByVal e As Global.System.EventArgs) - If My.Application.SaveMySettingsOnExit Then - My.Settings.Save() - End If - End Sub -#End If -#End Region - - Public Shared ReadOnly Property [Default]() As MySettings - Get - -#If _MyType = "WindowsForms" Then - If Not addedHandler Then - SyncLock addedHandlerLockObject - If Not addedHandler Then - AddHandler My.Application.Shutdown, AddressOf AutoSaveSettings - addedHandler = True - End If - End SyncLock - End If -#End If - Return defaultInstance - End Get - End Property - End Class -End Namespace - -Namespace My - - _ - Friend Module MySettingsProperty - - _ - Friend ReadOnly Property Settings() As Global.InputHelper.My.MySettings - Get - Return Global.InputHelper.My.MySettings.Default - End Get - End Property - End Module -End Namespace diff --git a/InputHelper Library/InputHelper .NET 4.x/My Project/Settings.settings b/InputHelper Library/InputHelper .NET 4.x/My Project/Settings.settings deleted file mode 100644 index 85b890b..0000000 --- a/InputHelper Library/InputHelper .NET 4.x/My Project/Settings.settings +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - diff --git a/InputHelper Library/InputHelper Library.sln b/InputHelper Library/InputHelper Library.sln deleted file mode 100644 index ea72931..0000000 --- a/InputHelper Library/InputHelper Library.sln +++ /dev/null @@ -1,26 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 11.00 -# Visual Studio 2010 -Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "InputHelper .NET 4.x", "InputHelper .NET 4.x\InputHelper .NET 4.x.vbproj", "{98BAEFE8-002F-42B9-ADA2-F0E0B888499D}" -EndProject -Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "InputHelper .NET 3.5", "InputHelper .NET 3.5\InputHelper .NET 3.5.vbproj", "{8D0E884C-CE78-472F-916E-5CC64819FFC3}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {98BAEFE8-002F-42B9-ADA2-F0E0B888499D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {98BAEFE8-002F-42B9-ADA2-F0E0B888499D}.Debug|Any CPU.Build.0 = Debug|Any CPU - {98BAEFE8-002F-42B9-ADA2-F0E0B888499D}.Release|Any CPU.ActiveCfg = Release|Any CPU - {98BAEFE8-002F-42B9-ADA2-F0E0B888499D}.Release|Any CPU.Build.0 = Release|Any CPU - {8D0E884C-CE78-472F-916E-5CC64819FFC3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {8D0E884C-CE78-472F-916E-5CC64819FFC3}.Debug|Any CPU.Build.0 = Debug|Any CPU - {8D0E884C-CE78-472F-916E-5CC64819FFC3}.Release|Any CPU.ActiveCfg = Release|Any CPU - {8D0E884C-CE78-472F-916E-5CC64819FFC3}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal diff --git a/InputHelper.sln b/InputHelper.sln new file mode 100644 index 0000000..bf6310b --- /dev/null +++ b/InputHelper.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.31515.178 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "InputHelper", "InputHelper\InputHelper.vbproj", "{89989202-F6F9-48F2-B1D8-3B8DAF634047}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {89989202-F6F9-48F2-B1D8-3B8DAF634047}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {89989202-F6F9-48F2-B1D8-3B8DAF634047}.Debug|Any CPU.Build.0 = Debug|Any CPU + {89989202-F6F9-48F2-B1D8-3B8DAF634047}.Release|Any CPU.ActiveCfg = Release|Any CPU + {89989202-F6F9-48F2-B1D8-3B8DAF634047}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {8191D97A-FB65-44F9-9EEE-E4E3055A60B0} + EndGlobalSection +EndGlobal diff --git a/InputHelper/AssemblyInfo.vb b/InputHelper/AssemblyInfo.vb new file mode 100644 index 0000000..99016ef --- /dev/null +++ b/InputHelper/AssemblyInfo.vb @@ -0,0 +1,9 @@ +Imports System.Reflection +Imports System.Resources + + + + + + + \ No newline at end of file diff --git a/InputHelper Library/InputHelper .NET 3.5/Constants.vb b/InputHelper/Constants.vb similarity index 96% rename from InputHelper Library/InputHelper .NET 3.5/Constants.vb rename to InputHelper/Constants.vb index c919185..a99da44 100644 --- a/InputHelper Library/InputHelper .NET 3.5/Constants.vb +++ b/InputHelper/Constants.vb @@ -1,69 +1,69 @@ -'+---------------------------------------------------------------------------------+' -'| === InputHelper === |' -'| |' -'| Created by Vincent "Visual Vincent" Bengtsson |' -'| Website: https://www.mydoomsite.com/ |' -'| GitHub: https://github.com/Visual-Vincent |' -'| |' -'| |' -'| === COPYRIGHT LICENSE === |' -'| |' -'| Copyright (c) 2016-2019, Vincent Bengtsson |' -'| All rights reserved. |' -'| |' -'| Redistribution and use in source and binary forms, with or without |' -'| modification, are permitted provided that the following conditions are met: |' -'| |' -'| 1. Redistributions of source code must retain the above copyright notice, this |' -'| list of conditions and the following disclaimer. |' -'| |' -'| 2. Redistributions in binary form must reproduce the above copyright notice, |' -'| this list of conditions and the following disclaimer in the documentation |' -'| and/or other materials provided with the distribution. |' -'| |' -'| 3. Neither the name of the copyright holder nor the names of its |' -'| contributors may be used to endorse or promote products derived from |' -'| this software without specific prior written permission. |' -'| |' -'| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |' -'| AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |' -'| IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |' -'| DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |' -'| FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |' -'| DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |' -'| SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |' -'| CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |' -'| OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |' -'| OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |' -'+---------------------------------------------------------------------------------+' - -Imports System.Text -Imports System.Windows.Forms - -''' -''' A class holding various InputHelper constants. -''' -''' -Public NotInheritable Class Constants - Private Sub New() - End Sub - - ''' - ''' The Alt Gr key. - ''' - ''' - Public Const AltGr As Keys = Keys.Control Or Keys.Alt - - ''' - ''' The bit value used to check if a key is held down (masked with the return value from GetAsyncKeyState()). - ''' - ''' - Public Const KeyDownBit As Integer = &H8000 - - ''' - ''' Windows-1252 encoding. - ''' - ''' - Public Shared ReadOnly Windows1252 As Encoding = Encoding.GetEncoding("windows-1252") - -End Class +'+---------------------------------------------------------------------------------+' +'| === InputHelper === |' +'| |' +'| Created by Vincent "Visual Vincent" Bengtsson |' +'| Website: https://www.mydoomsite.com/ |' +'| GitHub: https://github.com/Visual-Vincent |' +'| |' +'| |' +'| === COPYRIGHT LICENSE === |' +'| |' +'| Copyright (c) 2016-2022, Vincent Bengtsson |' +'| All rights reserved. |' +'| |' +'| Redistribution and use in source and binary forms, with or without |' +'| modification, are permitted provided that the following conditions are met: |' +'| |' +'| 1. Redistributions of source code must retain the above copyright notice, this |' +'| list of conditions and the following disclaimer. |' +'| |' +'| 2. Redistributions in binary form must reproduce the above copyright notice, |' +'| this list of conditions and the following disclaimer in the documentation |' +'| and/or other materials provided with the distribution. |' +'| |' +'| 3. Neither the name of the copyright holder nor the names of its |' +'| contributors may be used to endorse or promote products derived from |' +'| this software without specific prior written permission. |' +'| |' +'| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |' +'| AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |' +'| IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |' +'| DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |' +'| FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |' +'| DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |' +'| SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |' +'| CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |' +'| OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |' +'| OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |' +'+---------------------------------------------------------------------------------+' + +Imports System.Text +Imports System.Windows.Forms + +''' +''' A class holding various InputHelper constants. +''' +''' +Public NotInheritable Class Constants + Private Sub New() + End Sub + + ''' + ''' The Alt Gr key. + ''' + ''' + Public Const AltGr As Keys = Keys.Control Or Keys.Alt + + ''' + ''' The bit value used to check if a key is held down (masked with the return value from GetAsyncKeyState()). + ''' + ''' + Public Const KeyDownBit As Integer = &H8000 + + ''' + ''' Windows-1252 encoding. + ''' + ''' + Public Shared ReadOnly Windows1252 As Encoding = Encoding.GetEncoding("windows-1252") + +End Class diff --git a/InputHelper Library/InputHelper .NET 4.x/Enumerations.vb b/InputHelper/Enumerations.vb similarity index 96% rename from InputHelper Library/InputHelper .NET 4.x/Enumerations.vb rename to InputHelper/Enumerations.vb index a91de36..72920c2 100644 --- a/InputHelper Library/InputHelper .NET 4.x/Enumerations.vb +++ b/InputHelper/Enumerations.vb @@ -1,71 +1,71 @@ -'+---------------------------------------------------------------------------------+' -'| === InputHelper === |' -'| |' -'| Created by Vincent "Visual Vincent" Bengtsson |' -'| Website: https://www.mydoomsite.com/ |' -'| GitHub: https://github.com/Visual-Vincent |' -'| |' -'| |' -'| === COPYRIGHT LICENSE === |' -'| |' -'| Copyright (c) 2016-2019, Vincent Bengtsson |' -'| All rights reserved. |' -'| |' -'| Redistribution and use in source and binary forms, with or without |' -'| modification, are permitted provided that the following conditions are met: |' -'| |' -'| 1. Redistributions of source code must retain the above copyright notice, this |' -'| list of conditions and the following disclaimer. |' -'| |' -'| 2. Redistributions in binary form must reproduce the above copyright notice, |' -'| this list of conditions and the following disclaimer in the documentation |' -'| and/or other materials provided with the distribution. |' -'| |' -'| 3. Neither the name of the copyright holder nor the names of its |' -'| contributors may be used to endorse or promote products derived from |' -'| this software without specific prior written permission. |' -'| |' -'| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |' -'| AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |' -'| IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |' -'| DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |' -'| FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |' -'| DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |' -'| SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |' -'| CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |' -'| OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |' -'| OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |' -'+---------------------------------------------------------------------------------+' - - _ -Public Enum ModifierKeys As Integer - ''' - ''' No modifiers specified. - ''' - ''' - None = 0 - - ''' - ''' The CTRL modifier key. - ''' - ''' - Control = 1 - - ''' - ''' The SHIFT modifier key. - ''' - ''' - Shift = 2 - - ''' - ''' The ALT modifier key. - ''' - ''' - Alt = 4 - - ''' - ''' The Windows modifier key. - ''' - ''' - Windows = 8 +'+---------------------------------------------------------------------------------+' +'| === InputHelper === |' +'| |' +'| Created by Vincent "Visual Vincent" Bengtsson |' +'| Website: https://www.mydoomsite.com/ |' +'| GitHub: https://github.com/Visual-Vincent |' +'| |' +'| |' +'| === COPYRIGHT LICENSE === |' +'| |' +'| Copyright (c) 2016-2022, Vincent Bengtsson |' +'| All rights reserved. |' +'| |' +'| Redistribution and use in source and binary forms, with or without |' +'| modification, are permitted provided that the following conditions are met: |' +'| |' +'| 1. Redistributions of source code must retain the above copyright notice, this |' +'| list of conditions and the following disclaimer. |' +'| |' +'| 2. Redistributions in binary form must reproduce the above copyright notice, |' +'| this list of conditions and the following disclaimer in the documentation |' +'| and/or other materials provided with the distribution. |' +'| |' +'| 3. Neither the name of the copyright holder nor the names of its |' +'| contributors may be used to endorse or promote products derived from |' +'| this software without specific prior written permission. |' +'| |' +'| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |' +'| AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |' +'| IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |' +'| DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |' +'| FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |' +'| DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |' +'| SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |' +'| CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |' +'| OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |' +'| OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |' +'+---------------------------------------------------------------------------------+' + + _ +Public Enum ModifierKeys As Integer + ''' + ''' No modifiers specified. + ''' + ''' + None = 0 + + ''' + ''' The CTRL modifier key. + ''' + ''' + Control = 1 + + ''' + ''' The SHIFT modifier key. + ''' + ''' + Shift = 2 + + ''' + ''' The ALT modifier key. + ''' + ''' + Alt = 4 + + ''' + ''' The Windows modifier key. + ''' + ''' + Windows = 8 End Enum \ No newline at end of file diff --git a/InputHelper Library/InputHelper .NET 4.x/EventArgs/KeyboardHookEventArgs.vb b/InputHelper/EventArgs/KeyboardHookEventArgs.vb similarity index 97% rename from InputHelper Library/InputHelper .NET 4.x/EventArgs/KeyboardHookEventArgs.vb rename to InputHelper/EventArgs/KeyboardHookEventArgs.vb index 95b9305..252b221 100644 --- a/InputHelper Library/InputHelper .NET 4.x/EventArgs/KeyboardHookEventArgs.vb +++ b/InputHelper/EventArgs/KeyboardHookEventArgs.vb @@ -1,140 +1,137 @@ -'+---------------------------------------------------------------------------------+' -'| === InputHelper === |' -'| |' -'| Created by Vincent "Visual Vincent" Bengtsson |' -'| Website: https://www.mydoomsite.com/ |' -'| GitHub: https://github.com/Visual-Vincent |' -'| |' -'| |' -'| === COPYRIGHT LICENSE === |' -'| |' -'| Copyright (c) 2016-2019, Vincent Bengtsson |' -'| All rights reserved. |' -'| |' -'| Redistribution and use in source and binary forms, with or without |' -'| modification, are permitted provided that the following conditions are met: |' -'| |' -'| 1. Redistributions of source code must retain the above copyright notice, this |' -'| list of conditions and the following disclaimer. |' -'| |' -'| 2. Redistributions in binary form must reproduce the above copyright notice, |' -'| this list of conditions and the following disclaimer in the documentation |' -'| and/or other materials provided with the distribution. |' -'| |' -'| 3. Neither the name of the copyright holder nor the names of its |' -'| contributors may be used to endorse or promote products derived from |' -'| this software without specific prior written permission. |' -'| |' -'| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |' -'| AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |' -'| IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |' -'| DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |' -'| FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |' -'| DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |' -'| SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |' -'| CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |' -'| OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |' -'| OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |' -'+---------------------------------------------------------------------------------+' - -Imports System.Drawing -Imports System.Windows.Forms -Imports System.Runtime.InteropServices -Imports System.ComponentModel -Imports InputHelper.Hooks - -Namespace EventArgs - Public Class KeyboardHookEventArgs - Inherits System.EventArgs - - Private _extended As Boolean - Private _keyCode As Keys - Private _keyState As KeyState - Private _modifiers As ModifierKeys - Private _scanCode As UInteger - - ''' - ''' Gets or sets a boolean value indicating whether the keystroke should be blocked from reaching any windows. - ''' - ''' - Public Property Block As Boolean = False - - ''' - ''' Gets a boolean value indicating whether the keystroke message originated from one of the additional keys on the enhanced keyboard - ''' (see: https://msdn.microsoft.com/en-us/library/windows/desktop/ms646267(v=vs.85).aspx#_win32_Keystroke_Message_Flags). - ''' - ''' - Public ReadOnly Property Extended As Boolean - Get - Return _extended - End Get - End Property - - ''' - ''' Gets the keyboard code of the key that generated the keystroke. - ''' - ''' - Public ReadOnly Property KeyCode As Keys - Get - Return _keyCode - End Get - End Property - - ''' - ''' Gets the current state of the key that generated the keystroke. - ''' - ''' - Public ReadOnly Property KeyState As KeyState - Get - Return _keyState - End Get - End Property - - ''' - ''' Gets the modifier keys that was pressed in combination with the keystroke. - ''' - ''' - Public ReadOnly Property Modifiers As ModifierKeys - Get - Return _modifiers - End Get - End Property - - ''' - ''' Gets the hardware scan code of the key that generated the keystroke. - ''' - ''' - Public ReadOnly Property ScanCode As UInteger - Get - Return _scanCode - End Get - End Property - - Public Overrides Function ToString() As String - Return String.Format("{{KeyCode: {0}, ScanCode: {1}, Extended: {2}, KeyState: {3}, Modifiers: {4}}}", _ - Me.KeyCode, Me.ScanCode, Me.Extended, Me.KeyState, Me.Modifiers) - End Function - - ''' - ''' Initializes a new instance of the KeyboardHookEventArgs class. - ''' - ''' The keyboard code of the key that generated the keystroke. - ''' The hardware scan code of the key that generated the keystroke. - ''' Whether the keystroke message originated from one of the additional keys on the enhanced keyboard - ''' (see: https://msdn.microsoft.com/en-us/library/windows/desktop/ms646267(v=vs.85).aspx#_win32_Keystroke_Message_Flags). - ''' The current state of the key that generated the keystroke. - ''' The modifier keys that was pressed in combination with the keystroke. - ''' - Public Sub New(ByVal KeyCode As Keys, _ - ByVal ScanCode As UInteger, _ - ByVal Extended As Boolean, _ - ByVal KeyState As KeyState, _ - ByVal Modifiers As ModifierKeys) - Me._keyCode = KeyCode - Me._scanCode = ScanCode - Me._extended = Extended - Me._keyState = KeyState - Me._modifiers = Modifiers - End Sub - End Class +'+---------------------------------------------------------------------------------+' +'| === InputHelper === |' +'| |' +'| Created by Vincent "Visual Vincent" Bengtsson |' +'| Website: https://www.mydoomsite.com/ |' +'| GitHub: https://github.com/Visual-Vincent |' +'| |' +'| |' +'| === COPYRIGHT LICENSE === |' +'| |' +'| Copyright (c) 2016-2022, Vincent Bengtsson |' +'| All rights reserved. |' +'| |' +'| Redistribution and use in source and binary forms, with or without |' +'| modification, are permitted provided that the following conditions are met: |' +'| |' +'| 1. Redistributions of source code must retain the above copyright notice, this |' +'| list of conditions and the following disclaimer. |' +'| |' +'| 2. Redistributions in binary form must reproduce the above copyright notice, |' +'| this list of conditions and the following disclaimer in the documentation |' +'| and/or other materials provided with the distribution. |' +'| |' +'| 3. Neither the name of the copyright holder nor the names of its |' +'| contributors may be used to endorse or promote products derived from |' +'| this software without specific prior written permission. |' +'| |' +'| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |' +'| AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |' +'| IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |' +'| DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |' +'| FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |' +'| DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |' +'| SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |' +'| CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |' +'| OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |' +'| OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |' +'+---------------------------------------------------------------------------------+' + +Imports System.Windows.Forms +Imports InputHelper.Hooks + +Namespace EventArgs + Public Class KeyboardHookEventArgs + Inherits System.EventArgs + + Private _extended As Boolean + Private _keyCode As Keys + Private _keyState As KeyState + Private _modifiers As ModifierKeys + Private _scanCode As UInteger + + ''' + ''' Gets or sets a boolean value indicating whether the keystroke should be blocked from reaching any windows. + ''' + ''' + Public Property Block As Boolean = False + + ''' + ''' Gets a boolean value indicating whether the keystroke message originated from one of the additional keys on the enhanced keyboard + ''' (see: https://msdn.microsoft.com/en-us/library/windows/desktop/ms646267(v=vs.85).aspx#_win32_Keystroke_Message_Flags). + ''' + ''' + Public ReadOnly Property Extended As Boolean + Get + Return _extended + End Get + End Property + + ''' + ''' Gets the keyboard code of the key that generated the keystroke. + ''' + ''' + Public ReadOnly Property KeyCode As Keys + Get + Return _keyCode + End Get + End Property + + ''' + ''' Gets the current state of the key that generated the keystroke. + ''' + ''' + Public ReadOnly Property KeyState As KeyState + Get + Return _keyState + End Get + End Property + + ''' + ''' Gets the modifier keys that was pressed in combination with the keystroke. + ''' + ''' + Public ReadOnly Property Modifiers As ModifierKeys + Get + Return _modifiers + End Get + End Property + + ''' + ''' Gets the hardware scan code of the key that generated the keystroke. + ''' + ''' + Public ReadOnly Property ScanCode As UInteger + Get + Return _scanCode + End Get + End Property + + Public Overrides Function ToString() As String + Return String.Format("{{KeyCode: {0}, ScanCode: {1}, Extended: {2}, KeyState: {3}, Modifiers: {4}}}", _ + Me.KeyCode, Me.ScanCode, Me.Extended, Me.KeyState, Me.Modifiers) + End Function + + ''' + ''' Initializes a new instance of the KeyboardHookEventArgs class. + ''' + ''' The keyboard code of the key that generated the keystroke. + ''' The hardware scan code of the key that generated the keystroke. + ''' Whether the keystroke message originated from one of the additional keys on the enhanced keyboard + ''' (see: https://msdn.microsoft.com/en-us/library/windows/desktop/ms646267(v=vs.85).aspx#_win32_Keystroke_Message_Flags). + ''' The current state of the key that generated the keystroke. + ''' The modifier keys that was pressed in combination with the keystroke. + ''' + Public Sub New(ByVal KeyCode As Keys, _ + ByVal ScanCode As UInteger, _ + ByVal Extended As Boolean, _ + ByVal KeyState As KeyState, _ + ByVal Modifiers As ModifierKeys) + Me._keyCode = KeyCode + Me._scanCode = ScanCode + Me._extended = Extended + Me._keyState = KeyState + Me._modifiers = Modifiers + End Sub + End Class End Namespace \ No newline at end of file diff --git a/InputHelper Library/InputHelper .NET 3.5/EventArgs/MouseEventArgs.vb b/InputHelper/EventArgs/MouseEventArgs.vb similarity index 97% rename from InputHelper Library/InputHelper .NET 3.5/EventArgs/MouseEventArgs.vb rename to InputHelper/EventArgs/MouseEventArgs.vb index f08ac6d..bf109f8 100644 --- a/InputHelper Library/InputHelper .NET 3.5/EventArgs/MouseEventArgs.vb +++ b/InputHelper/EventArgs/MouseEventArgs.vb @@ -1,152 +1,150 @@ -'+---------------------------------------------------------------------------------+' -'| === InputHelper === |' -'| |' -'| Created by Vincent "Visual Vincent" Bengtsson |' -'| Website: https://www.mydoomsite.com/ |' -'| GitHub: https://github.com/Visual-Vincent |' -'| |' -'| |' -'| === COPYRIGHT LICENSE === |' -'| |' -'| Copyright (c) 2016-2019, Vincent Bengtsson |' -'| All rights reserved. |' -'| |' -'| Redistribution and use in source and binary forms, with or without |' -'| modification, are permitted provided that the following conditions are met: |' -'| |' -'| 1. Redistributions of source code must retain the above copyright notice, this |' -'| list of conditions and the following disclaimer. |' -'| |' -'| 2. Redistributions in binary form must reproduce the above copyright notice, |' -'| this list of conditions and the following disclaimer in the documentation |' -'| and/or other materials provided with the distribution. |' -'| |' -'| 3. Neither the name of the copyright holder nor the names of its |' -'| contributors may be used to endorse or promote products derived from |' -'| this software without specific prior written permission. |' -'| |' -'| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |' -'| AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |' -'| IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |' -'| DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |' -'| FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |' -'| DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |' -'| SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |' -'| CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |' -'| OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |' -'| OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |' -'+---------------------------------------------------------------------------------+' - -Imports System.Drawing -Imports System.Windows.Forms -Imports System.Runtime.InteropServices -Imports System.ComponentModel -Imports InputHelper.Hooks - -Namespace EventArgs - Public Class MouseHookEventArgs - Inherits System.EventArgs - - Private _button As MouseButtons - Private _buttonState As KeyState - Private _delta As Integer - Private _doubleClick As Boolean - Private _location As Point - Private _scrollDirection As ScrollDirection - - ''' - ''' Gets or sets a boolean value indicating whether the mouse event should be blocked from reaching any windows. - ''' - ''' - Public Property Block As Boolean = False - - ''' - ''' Gets which mouse button was pressed or released. - ''' - ''' - Public ReadOnly Property Button As MouseButtons - Get - Return _button - End Get - End Property - - ''' - ''' Gets the current state of the button that generated the mouse event. - ''' - ''' - Public ReadOnly Property ButtonState As KeyState - Get - Return _buttonState - End Get - End Property - - ''' - ''' Gets a signed count of the number of detents the mouse wheel has rotated. A detent is one notch of the mouse wheel. - ''' - ''' - Public ReadOnly Property Delta As Integer - Get - Return _delta - End Get - End Property - - ''' - ''' Gets a boolean value indicating whether the event was caused by a double click. - ''' - ''' - Public ReadOnly Property DoubleClick As Boolean - Get - Return _doubleClick - End Get - End Property - - ''' - ''' Gets the location of the mouse (in screen coordinates). - ''' - ''' - Public ReadOnly Property Location As Point - Get - Return _location - End Get - End Property - - ''' - ''' Gets which direction the mouse wheel was scrolled in. - ''' - ''' - Public ReadOnly Property ScrollDirection As ScrollDirection - Get - Return _scrollDirection - End Get - End Property - - Public Overrides Function ToString() As String - Return String.Format("{{Button: {0}, State: {1}, DoubleClick: {2}, Location: {3}, Scroll: {4}, Delta: {5}}}", _ - Me.Button, Me.ButtonState, Me.DoubleClick, Me.Location, Me.ScrollDirection, Me.Delta) - End Function - - ''' - ''' Initializes a new instance of the MouseHookEventArgs class. - ''' - ''' Which mouse button was pressed or released. - ''' The current state of the button that generated the mouse event. - ''' Whether the event was caused by a double click. - ''' The location of the mouse (in screen coordinates). - ''' Which direction the mouse wheel was scrolled in. - ''' A signed count of the number of detents the mouse wheel has rotated. - ''' - Public Sub New(ByVal Button As MouseButtons, _ - ByVal ButtonState As KeyState, _ - ByVal DoubleClick As Boolean, _ - ByVal Location As Point, _ - ByVal ScrollDirection As ScrollDirection, _ - ByVal Delta As Integer) - Me._button = Button - Me._buttonState = ButtonState - Me._doubleClick = DoubleClick - Me._location = Location - Me._scrollDirection = ScrollDirection - Me._delta = Delta - End Sub - End Class +'+---------------------------------------------------------------------------------+' +'| === InputHelper === |' +'| |' +'| Created by Vincent "Visual Vincent" Bengtsson |' +'| Website: https://www.mydoomsite.com/ |' +'| GitHub: https://github.com/Visual-Vincent |' +'| |' +'| |' +'| === COPYRIGHT LICENSE === |' +'| |' +'| Copyright (c) 2016-2022, Vincent Bengtsson |' +'| All rights reserved. |' +'| |' +'| Redistribution and use in source and binary forms, with or without |' +'| modification, are permitted provided that the following conditions are met: |' +'| |' +'| 1. Redistributions of source code must retain the above copyright notice, this |' +'| list of conditions and the following disclaimer. |' +'| |' +'| 2. Redistributions in binary form must reproduce the above copyright notice, |' +'| this list of conditions and the following disclaimer in the documentation |' +'| and/or other materials provided with the distribution. |' +'| |' +'| 3. Neither the name of the copyright holder nor the names of its |' +'| contributors may be used to endorse or promote products derived from |' +'| this software without specific prior written permission. |' +'| |' +'| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |' +'| AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |' +'| IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |' +'| DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |' +'| FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |' +'| DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |' +'| SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |' +'| CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |' +'| OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |' +'| OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |' +'+---------------------------------------------------------------------------------+' + +Imports System.Drawing +Imports System.Windows.Forms +Imports InputHelper.Hooks + +Namespace EventArgs + Public Class MouseHookEventArgs + Inherits System.EventArgs + + Private _button As MouseButtons + Private _buttonState As KeyState + Private _delta As Integer + Private _doubleClick As Boolean + Private _location As Point + Private _scrollDirection As ScrollDirection + + ''' + ''' Gets or sets a boolean value indicating whether the mouse event should be blocked from reaching any windows. + ''' + ''' + Public Property Block As Boolean = False + + ''' + ''' Gets which mouse button was pressed or released. + ''' + ''' + Public ReadOnly Property Button As MouseButtons + Get + Return _button + End Get + End Property + + ''' + ''' Gets the current state of the button that generated the mouse event. + ''' + ''' + Public ReadOnly Property ButtonState As KeyState + Get + Return _buttonState + End Get + End Property + + ''' + ''' Gets a signed count of the number of detents the mouse wheel has rotated. A detent is one notch of the mouse wheel. + ''' + ''' + Public ReadOnly Property Delta As Integer + Get + Return _delta + End Get + End Property + + ''' + ''' Gets a boolean value indicating whether the event was caused by a double click. + ''' + ''' + Public ReadOnly Property DoubleClick As Boolean + Get + Return _doubleClick + End Get + End Property + + ''' + ''' Gets the location of the mouse (in screen coordinates). + ''' + ''' + Public ReadOnly Property Location As Point + Get + Return _location + End Get + End Property + + ''' + ''' Gets which direction the mouse wheel was scrolled in. + ''' + ''' + Public ReadOnly Property ScrollDirection As ScrollDirection + Get + Return _scrollDirection + End Get + End Property + + Public Overrides Function ToString() As String + Return String.Format("{{Button: {0}, State: {1}, DoubleClick: {2}, Location: {3}, Scroll: {4}, Delta: {5}}}", _ + Me.Button, Me.ButtonState, Me.DoubleClick, Me.Location, Me.ScrollDirection, Me.Delta) + End Function + + ''' + ''' Initializes a new instance of the MouseHookEventArgs class. + ''' + ''' Which mouse button was pressed or released. + ''' The current state of the button that generated the mouse event. + ''' Whether the event was caused by a double click. + ''' The location of the mouse (in screen coordinates). + ''' Which direction the mouse wheel was scrolled in. + ''' A signed count of the number of detents the mouse wheel has rotated. + ''' + Public Sub New(ByVal Button As MouseButtons, _ + ByVal ButtonState As KeyState, _ + ByVal DoubleClick As Boolean, _ + ByVal Location As Point, _ + ByVal ScrollDirection As ScrollDirection, _ + ByVal Delta As Integer) + Me._button = Button + Me._buttonState = ButtonState + Me._doubleClick = DoubleClick + Me._location = Location + Me._scrollDirection = ScrollDirection + Me._delta = Delta + End Sub + End Class End Namespace \ No newline at end of file diff --git a/InputHelper Library/InputHelper .NET 3.5/Hooks/Enumerations.vb b/InputHelper/Hooks/Enumerations.vb similarity index 96% rename from InputHelper Library/InputHelper .NET 3.5/Hooks/Enumerations.vb rename to InputHelper/Hooks/Enumerations.vb index 7277629..8d5e6fe 100644 --- a/InputHelper Library/InputHelper .NET 3.5/Hooks/Enumerations.vb +++ b/InputHelper/Hooks/Enumerations.vb @@ -1,51 +1,51 @@ -'+---------------------------------------------------------------------------------+' -'| === InputHelper === |' -'| |' -'| Created by Vincent "Visual Vincent" Bengtsson |' -'| Website: https://www.mydoomsite.com/ |' -'| GitHub: https://github.com/Visual-Vincent |' -'| |' -'| |' -'| === COPYRIGHT LICENSE === |' -'| |' -'| Copyright (c) 2016-2019, Vincent Bengtsson |' -'| All rights reserved. |' -'| |' -'| Redistribution and use in source and binary forms, with or without |' -'| modification, are permitted provided that the following conditions are met: |' -'| |' -'| 1. Redistributions of source code must retain the above copyright notice, this |' -'| list of conditions and the following disclaimer. |' -'| |' -'| 2. Redistributions in binary form must reproduce the above copyright notice, |' -'| this list of conditions and the following disclaimer in the documentation |' -'| and/or other materials provided with the distribution. |' -'| |' -'| 3. Neither the name of the copyright holder nor the names of its |' -'| contributors may be used to endorse or promote products derived from |' -'| this software without specific prior written permission. |' -'| |' -'| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |' -'| AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |' -'| IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |' -'| DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |' -'| FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |' -'| DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |' -'| SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |' -'| CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |' -'| OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |' -'| OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |' -'+---------------------------------------------------------------------------------+' - -Namespace Hooks - Public Enum KeyState As Integer - Up = 0 - Down = 1 - End Enum - - Public Enum ScrollDirection As Integer - None = 0 - Vertical = 1 - Horizontal = 2 - End Enum +'+---------------------------------------------------------------------------------+' +'| === InputHelper === |' +'| |' +'| Created by Vincent "Visual Vincent" Bengtsson |' +'| Website: https://www.mydoomsite.com/ |' +'| GitHub: https://github.com/Visual-Vincent |' +'| |' +'| |' +'| === COPYRIGHT LICENSE === |' +'| |' +'| Copyright (c) 2016-2022, Vincent Bengtsson |' +'| All rights reserved. |' +'| |' +'| Redistribution and use in source and binary forms, with or without |' +'| modification, are permitted provided that the following conditions are met: |' +'| |' +'| 1. Redistributions of source code must retain the above copyright notice, this |' +'| list of conditions and the following disclaimer. |' +'| |' +'| 2. Redistributions in binary form must reproduce the above copyright notice, |' +'| this list of conditions and the following disclaimer in the documentation |' +'| and/or other materials provided with the distribution. |' +'| |' +'| 3. Neither the name of the copyright holder nor the names of its |' +'| contributors may be used to endorse or promote products derived from |' +'| this software without specific prior written permission. |' +'| |' +'| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |' +'| AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |' +'| IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |' +'| DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |' +'| FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |' +'| DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |' +'| SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |' +'| CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |' +'| OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |' +'| OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |' +'+---------------------------------------------------------------------------------+' + +Namespace Hooks + Public Enum KeyState As Integer + Up = 0 + Down = 1 + End Enum + + Public Enum ScrollDirection As Integer + None = 0 + Vertical = 1 + Horizontal = 2 + End Enum End Namespace \ No newline at end of file diff --git a/InputHelper Library/InputHelper .NET 4.x/Hooks/KeyboardHook.vb b/InputHelper/Hooks/KeyboardHook.vb similarity index 97% rename from InputHelper Library/InputHelper .NET 4.x/Hooks/KeyboardHook.vb rename to InputHelper/Hooks/KeyboardHook.vb index d231ec7..82743e7 100644 --- a/InputHelper Library/InputHelper .NET 4.x/Hooks/KeyboardHook.vb +++ b/InputHelper/Hooks/KeyboardHook.vb @@ -1,175 +1,175 @@ -'+---------------------------------------------------------------------------------+' -'| === InputHelper === |' -'| |' -'| Created by Vincent "Visual Vincent" Bengtsson |' -'| Website: https://www.mydoomsite.com/ |' -'| GitHub: https://github.com/Visual-Vincent |' -'| |' -'| |' -'| === COPYRIGHT LICENSE === |' -'| |' -'| Copyright (c) 2016-2019, Vincent Bengtsson |' -'| All rights reserved. |' -'| |' -'| Redistribution and use in source and binary forms, with or without |' -'| modification, are permitted provided that the following conditions are met: |' -'| |' -'| 1. Redistributions of source code must retain the above copyright notice, this |' -'| list of conditions and the following disclaimer. |' -'| |' -'| 2. Redistributions in binary form must reproduce the above copyright notice, |' -'| this list of conditions and the following disclaimer in the documentation |' -'| and/or other materials provided with the distribution. |' -'| |' -'| 3. Neither the name of the copyright holder nor the names of its |' -'| contributors may be used to endorse or promote products derived from |' -'| this software without specific prior written permission. |' -'| |' -'| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |' -'| AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |' -'| IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |' -'| DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |' -'| FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |' -'| DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |' -'| SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |' -'| CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |' -'| OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |' -'| OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |' -'+---------------------------------------------------------------------------------+' - -Imports System.Windows.Forms -Imports System.Runtime.InteropServices -Imports System.ComponentModel -Imports InputHelper.EventArgs - -Namespace Hooks - ''' - ''' A global low-level keyboard hook that raises events when a key is pressed or released. - ''' - ''' - Public NotInheritable Class KeyboardHook - Implements IDisposable - - ''' - ''' Occurs when a key is pressed or held down. - ''' - ''' - Public Event KeyDown As EventHandler(Of KeyboardHookEventArgs) - - ''' - ''' Occurs when a key is released. - ''' - ''' - Public Event KeyUp As EventHandler(Of KeyboardHookEventArgs) - - Private hHook As IntPtr = IntPtr.Zero - Private HookProcedureDelegate As New NativeMethods.LowLevelKeyboardProc(AddressOf HookCallback) - - Private Modifiers As ModifierKeys = ModifierKeys.None - - Private Function HookCallback(ByVal nCode As Integer, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr - Dim Block As Boolean = False - - If nCode >= NativeMethods.HookCode.HC_ACTION AndAlso _ - (wParam = NativeMethods.KeyMessage.WM_KEYDOWN OrElse _ - wParam = NativeMethods.KeyMessage.WM_KEYUP OrElse _ - wParam = NativeMethods.KeyMessage.WM_SYSKEYDOWN OrElse _ - wParam = NativeMethods.KeyMessage.WM_SYSKEYUP) Then - - Dim KeystrokeInfo As NativeMethods.KBDLLHOOKSTRUCT = _ - CType(Marshal.PtrToStructure(lParam, GetType(NativeMethods.KBDLLHOOKSTRUCT)), NativeMethods.KBDLLHOOKSTRUCT) - - Select Case wParam - - Case NativeMethods.KeyMessage.WM_KEYDOWN, NativeMethods.KeyMessage.WM_SYSKEYDOWN - Dim HookEventArgs As KeyboardHookEventArgs = Me.CreateEventArgs(True, KeystrokeInfo) - - If Internal.IsModifier(HookEventArgs.KeyCode, ModifierKeys.Control) = True Then Me.Modifiers = Me.Modifiers Or ModifierKeys.Control - If Internal.IsModifier(HookEventArgs.KeyCode, ModifierKeys.Shift) = True Then Me.Modifiers = Me.Modifiers Or ModifierKeys.Shift - If Internal.IsModifier(HookEventArgs.KeyCode, ModifierKeys.Alt) = True Then Me.Modifiers = Me.Modifiers Or ModifierKeys.Alt - If Internal.IsModifier(HookEventArgs.KeyCode, ModifierKeys.Windows) = True Then Me.Modifiers = Me.Modifiers Or ModifierKeys.Windows - - RaiseEvent KeyDown(Me, HookEventArgs) - Block = HookEventArgs.Block - - Case NativeMethods.KeyMessage.WM_KEYUP, NativeMethods.KeyMessage.WM_SYSKEYUP - Dim KeyCode As Keys = CType(KeystrokeInfo.vkCode And Integer.MaxValue, Keys) - - 'Must be done before creating the HookEventArgs during KeyUp. - If Internal.IsModifier(KeyCode, ModifierKeys.Control) = True Then Me.Modifiers = Me.Modifiers And Not ModifierKeys.Control - If Internal.IsModifier(KeyCode, ModifierKeys.Shift) = True Then Me.Modifiers = Me.Modifiers And Not ModifierKeys.Shift - If Internal.IsModifier(KeyCode, ModifierKeys.Alt) = True Then Me.Modifiers = Me.Modifiers And Not ModifierKeys.Alt - If Internal.IsModifier(KeyCode, ModifierKeys.Windows) = True Then Me.Modifiers = Me.Modifiers And Not ModifierKeys.Windows - - Dim HookEventArgs As KeyboardHookEventArgs = Me.CreateEventArgs(False, KeystrokeInfo) - - RaiseEvent KeyUp(Me, HookEventArgs) - Block = HookEventArgs.Block - - End Select - End If - - Return If(Block, New IntPtr(1), NativeMethods.CallNextHookEx(hHook, nCode, wParam, lParam)) - End Function - - Private Function CreateEventArgs(ByVal KeyDown As Boolean, ByVal KeystrokeInfo As NativeMethods.KBDLLHOOKSTRUCT) As KeyboardHookEventArgs - Dim KeyCode As Keys = CType(KeystrokeInfo.vkCode And Integer.MaxValue, Keys) - Dim ScanCode As UInteger = KeystrokeInfo.scanCode - Dim Extended As Boolean = (KeystrokeInfo.flags And NativeMethods.LowLevelKeyboardHookFlags.LLKHF_EXTENDED) = NativeMethods.LowLevelKeyboardHookFlags.LLKHF_EXTENDED - Dim AltDown As Boolean = (KeystrokeInfo.flags And NativeMethods.LowLevelKeyboardHookFlags.LLKHF_ALTDOWN) = NativeMethods.LowLevelKeyboardHookFlags.LLKHF_ALTDOWN - - If AltDown = True _ - AndAlso Internal.IsModifier(KeyCode, ModifierKeys.Alt) = False _ - AndAlso (Me.Modifiers And ModifierKeys.Alt) <> ModifierKeys.Alt Then - - Me.Modifiers = Me.Modifiers Or ModifierKeys.Alt - End If - - Return New KeyboardHookEventArgs(KeyCode, ScanCode, Extended, If(KeyDown, KeyState.Down, KeyState.Up), Me.Modifiers) - End Function - - ''' - ''' Initializes a new instance of the KeyboardHook class. - ''' - ''' - Public Sub New() - hHook = NativeMethods.SetWindowsHookEx(NativeMethods.HookType.WH_KEYBOARD_LL, HookProcedureDelegate, NativeMethods.GetModuleHandle(Nothing), 0) - If hHook = IntPtr.Zero Then - Dim Win32Error As Integer = Marshal.GetLastWin32Error() - Throw New Win32Exception(Win32Error, "Failed to create keyboard hook! (" & Win32Error & ")") - End If - End Sub - -#Region "IDisposable Support" - Private disposedValue As Boolean ' To detect redundant calls - - ' IDisposable - Protected Sub Dispose(disposing As Boolean) - If Not Me.disposedValue Then - If disposing Then - ' TODO: dispose managed state (managed objects). - End If - - ' TODO: free unmanaged resources (unmanaged objects) and override Finalize() below. - ' TODO: set large fields to null. - If hHook <> IntPtr.Zero Then NativeMethods.UnhookWindowsHookEx(hHook) - End If - Me.disposedValue = True - End Sub - - Protected Overrides Sub Finalize() - ' Do not change this code. Put cleanup code in Dispose(ByVal disposing As Boolean) above. - Dispose(False) - MyBase.Finalize() - End Sub - - ' This code added by Visual Basic to correctly implement the disposable pattern. - Public Sub Dispose() Implements IDisposable.Dispose - ' Do not change this code. Put cleanup code in Dispose(ByVal disposing As Boolean) above. - Dispose(True) - GC.SuppressFinalize(Me) - End Sub -#End Region - - End Class +'+---------------------------------------------------------------------------------+' +'| === InputHelper === |' +'| |' +'| Created by Vincent "Visual Vincent" Bengtsson |' +'| Website: https://www.mydoomsite.com/ |' +'| GitHub: https://github.com/Visual-Vincent |' +'| |' +'| |' +'| === COPYRIGHT LICENSE === |' +'| |' +'| Copyright (c) 2016-2022, Vincent Bengtsson |' +'| All rights reserved. |' +'| |' +'| Redistribution and use in source and binary forms, with or without |' +'| modification, are permitted provided that the following conditions are met: |' +'| |' +'| 1. Redistributions of source code must retain the above copyright notice, this |' +'| list of conditions and the following disclaimer. |' +'| |' +'| 2. Redistributions in binary form must reproduce the above copyright notice, |' +'| this list of conditions and the following disclaimer in the documentation |' +'| and/or other materials provided with the distribution. |' +'| |' +'| 3. Neither the name of the copyright holder nor the names of its |' +'| contributors may be used to endorse or promote products derived from |' +'| this software without specific prior written permission. |' +'| |' +'| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |' +'| AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |' +'| IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |' +'| DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |' +'| FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |' +'| DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |' +'| SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |' +'| CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |' +'| OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |' +'| OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |' +'+---------------------------------------------------------------------------------+' + +Imports System.Windows.Forms +Imports System.Runtime.InteropServices +Imports System.ComponentModel +Imports InputHelper.EventArgs + +Namespace Hooks + ''' + ''' A global low-level keyboard hook that raises events when a key is pressed or released. + ''' + ''' + Public NotInheritable Class KeyboardHook + Implements IDisposable + + ''' + ''' Occurs when a key is pressed or held down. + ''' + ''' + Public Event KeyDown As EventHandler(Of KeyboardHookEventArgs) + + ''' + ''' Occurs when a key is released. + ''' + ''' + Public Event KeyUp As EventHandler(Of KeyboardHookEventArgs) + + Private hHook As IntPtr = IntPtr.Zero + Private HookProcedureDelegate As New NativeMethods.LowLevelKeyboardProc(AddressOf HookCallback) + + Private Modifiers As ModifierKeys = ModifierKeys.None + + Private Function HookCallback(ByVal nCode As Integer, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr + Dim Block As Boolean = False + + If nCode >= NativeMethods.HookCode.HC_ACTION AndAlso _ + (wParam = NativeMethods.KeyMessage.WM_KEYDOWN OrElse _ + wParam = NativeMethods.KeyMessage.WM_KEYUP OrElse _ + wParam = NativeMethods.KeyMessage.WM_SYSKEYDOWN OrElse _ + wParam = NativeMethods.KeyMessage.WM_SYSKEYUP) Then + + Dim KeystrokeInfo As NativeMethods.KBDLLHOOKSTRUCT = _ + CType(Marshal.PtrToStructure(lParam, GetType(NativeMethods.KBDLLHOOKSTRUCT)), NativeMethods.KBDLLHOOKSTRUCT) + + Select Case wParam + + Case NativeMethods.KeyMessage.WM_KEYDOWN, NativeMethods.KeyMessage.WM_SYSKEYDOWN + Dim HookEventArgs As KeyboardHookEventArgs = Me.CreateEventArgs(True, KeystrokeInfo) + + If Internal.IsModifier(HookEventArgs.KeyCode, ModifierKeys.Control) = True Then Me.Modifiers = Me.Modifiers Or ModifierKeys.Control + If Internal.IsModifier(HookEventArgs.KeyCode, ModifierKeys.Shift) = True Then Me.Modifiers = Me.Modifiers Or ModifierKeys.Shift + If Internal.IsModifier(HookEventArgs.KeyCode, ModifierKeys.Alt) = True Then Me.Modifiers = Me.Modifiers Or ModifierKeys.Alt + If Internal.IsModifier(HookEventArgs.KeyCode, ModifierKeys.Windows) = True Then Me.Modifiers = Me.Modifiers Or ModifierKeys.Windows + + RaiseEvent KeyDown(Me, HookEventArgs) + Block = HookEventArgs.Block + + Case NativeMethods.KeyMessage.WM_KEYUP, NativeMethods.KeyMessage.WM_SYSKEYUP + Dim KeyCode As Keys = CType(KeystrokeInfo.vkCode And Integer.MaxValue, Keys) + + 'Must be done before creating the HookEventArgs during KeyUp. + If Internal.IsModifier(KeyCode, ModifierKeys.Control) = True Then Me.Modifiers = Me.Modifiers And Not ModifierKeys.Control + If Internal.IsModifier(KeyCode, ModifierKeys.Shift) = True Then Me.Modifiers = Me.Modifiers And Not ModifierKeys.Shift + If Internal.IsModifier(KeyCode, ModifierKeys.Alt) = True Then Me.Modifiers = Me.Modifiers And Not ModifierKeys.Alt + If Internal.IsModifier(KeyCode, ModifierKeys.Windows) = True Then Me.Modifiers = Me.Modifiers And Not ModifierKeys.Windows + + Dim HookEventArgs As KeyboardHookEventArgs = Me.CreateEventArgs(False, KeystrokeInfo) + + RaiseEvent KeyUp(Me, HookEventArgs) + Block = HookEventArgs.Block + + End Select + End If + + Return If(Block, New IntPtr(1), NativeMethods.CallNextHookEx(hHook, nCode, wParam, lParam)) + End Function + + Private Function CreateEventArgs(ByVal KeyDown As Boolean, ByVal KeystrokeInfo As NativeMethods.KBDLLHOOKSTRUCT) As KeyboardHookEventArgs + Dim KeyCode As Keys = CType(KeystrokeInfo.vkCode And Integer.MaxValue, Keys) + Dim ScanCode As UInteger = KeystrokeInfo.scanCode + Dim Extended As Boolean = (KeystrokeInfo.flags And NativeMethods.LowLevelKeyboardHookFlags.LLKHF_EXTENDED) = NativeMethods.LowLevelKeyboardHookFlags.LLKHF_EXTENDED + Dim AltDown As Boolean = (KeystrokeInfo.flags And NativeMethods.LowLevelKeyboardHookFlags.LLKHF_ALTDOWN) = NativeMethods.LowLevelKeyboardHookFlags.LLKHF_ALTDOWN + + If AltDown = True _ + AndAlso Internal.IsModifier(KeyCode, ModifierKeys.Alt) = False _ + AndAlso (Me.Modifiers And ModifierKeys.Alt) <> ModifierKeys.Alt Then + + Me.Modifiers = Me.Modifiers Or ModifierKeys.Alt + End If + + Return New KeyboardHookEventArgs(KeyCode, ScanCode, Extended, If(KeyDown, KeyState.Down, KeyState.Up), Me.Modifiers) + End Function + + ''' + ''' Initializes a new instance of the KeyboardHook class. + ''' + ''' + Public Sub New() + hHook = NativeMethods.SetWindowsHookEx(NativeMethods.HookType.WH_KEYBOARD_LL, HookProcedureDelegate, NativeMethods.GetModuleHandle(Nothing), 0) + If hHook = IntPtr.Zero Then + Dim Win32Error As Integer = Marshal.GetLastWin32Error() + Throw New Win32Exception(Win32Error, "Failed to create keyboard hook! (" & Win32Error & ")") + End If + End Sub + +#Region "IDisposable Support" + Private disposedValue As Boolean ' To detect redundant calls + + ' IDisposable + Protected Sub Dispose(disposing As Boolean) + If Not Me.disposedValue Then + If disposing Then + ' TODO: dispose managed state (managed objects). + End If + + ' TODO: free unmanaged resources (unmanaged objects) and override Finalize() below. + ' TODO: set large fields to null. + If hHook <> IntPtr.Zero Then NativeMethods.UnhookWindowsHookEx(hHook) + End If + Me.disposedValue = True + End Sub + + Protected Overrides Sub Finalize() + ' Do not change this code. Put cleanup code in Dispose(ByVal disposing As Boolean) above. + Dispose(False) + MyBase.Finalize() + End Sub + + ' This code added by Visual Basic to correctly implement the disposable pattern. + Public Sub Dispose() Implements IDisposable.Dispose + ' Do not change this code. Put cleanup code in Dispose(ByVal disposing As Boolean) above. + Dispose(True) + GC.SuppressFinalize(Me) + End Sub +#End Region + + End Class End Namespace \ No newline at end of file diff --git a/InputHelper Library/InputHelper .NET 3.5/Hooks/LocalKeyboardHook.vb b/InputHelper/Hooks/LocalKeyboardHook.vb similarity index 97% rename from InputHelper Library/InputHelper .NET 3.5/Hooks/LocalKeyboardHook.vb rename to InputHelper/Hooks/LocalKeyboardHook.vb index 46cbe04..444d4bd 100644 --- a/InputHelper Library/InputHelper .NET 3.5/Hooks/LocalKeyboardHook.vb +++ b/InputHelper/Hooks/LocalKeyboardHook.vb @@ -1,170 +1,170 @@ -'+---------------------------------------------------------------------------------+' -'| === InputHelper === |' -'| |' -'| Created by Vincent "Visual Vincent" Bengtsson |' -'| Website: https://www.mydoomsite.com/ |' -'| GitHub: https://github.com/Visual-Vincent |' -'| |' -'| |' -'| === COPYRIGHT LICENSE === |' -'| |' -'| Copyright (c) 2016-2019, Vincent Bengtsson |' -'| All rights reserved. |' -'| |' -'| Redistribution and use in source and binary forms, with or without |' -'| modification, are permitted provided that the following conditions are met: |' -'| |' -'| 1. Redistributions of source code must retain the above copyright notice, this |' -'| list of conditions and the following disclaimer. |' -'| |' -'| 2. Redistributions in binary form must reproduce the above copyright notice, |' -'| this list of conditions and the following disclaimer in the documentation |' -'| and/or other materials provided with the distribution. |' -'| |' -'| 3. Neither the name of the copyright holder nor the names of its |' -'| contributors may be used to endorse or promote products derived from |' -'| this software without specific prior written permission. |' -'| |' -'| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |' -'| AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |' -'| IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |' -'| DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |' -'| FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |' -'| DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |' -'| SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |' -'| CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |' -'| OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |' -'| OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |' -'+---------------------------------------------------------------------------------+' - -Imports System.Windows.Forms -Imports System.Runtime.InteropServices -Imports System.ComponentModel -Imports InputHelper.EventArgs - -Namespace Hooks - ''' - ''' A local keyboard hook that raises events when a key is pressed or released in a specific thread. - ''' - ''' - Public NotInheritable Class LocalKeyboardHook - Implements IDisposable - - ''' - ''' Occurs when a key is pressed or held down. - ''' - ''' - Public Event KeyDown As EventHandler(Of KeyboardHookEventArgs) - - ''' - ''' Occurs when a key is released. - ''' - ''' - Public Event KeyUp As EventHandler(Of KeyboardHookEventArgs) - - Private hHook As IntPtr = IntPtr.Zero - Private HookProcedureDelegate As New NativeMethods.KeyboardProc(AddressOf HookCallback) - - Private Modifiers As ModifierKeys = ModifierKeys.None - - Private Function HookCallback(ByVal nCode As Integer, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr - Dim Block As Boolean = False - - If nCode >= NativeMethods.HookCode.HC_ACTION Then - Dim KeyCode As Keys = CType(wParam.ToInt32(), Keys) - Dim KeyFlags As New NativeMethods.QWORD(lParam.ToInt64()) - Dim ScanCode As Byte = BitConverter.GetBytes(KeyFlags)(2) 'The scan code is the third byte in the integer (bits 16-23). - Dim Extended As Boolean = (KeyFlags.LowWord.High And NativeMethods.KeyboardFlags.KF_EXTENDED) = NativeMethods.KeyboardFlags.KF_EXTENDED - Dim AltDown As Boolean = (KeyFlags.LowWord.High And NativeMethods.KeyboardFlags.KF_ALTDOWN) = NativeMethods.KeyboardFlags.KF_ALTDOWN - Dim KeyUp As Boolean = (KeyFlags.LowWord.High And NativeMethods.KeyboardFlags.KF_UP) = NativeMethods.KeyboardFlags.KF_UP - - 'Set the ALT modifier if the KF_ALTDOWN flag is set. - If AltDown = True _ - AndAlso Internal.IsModifier(KeyCode, ModifierKeys.Alt) = False _ - AndAlso (Me.Modifiers And ModifierKeys.Alt) <> ModifierKeys.Alt Then - - Me.Modifiers = Me.Modifiers Or ModifierKeys.Alt - End If - - 'Raise KeyDown/KeyUp event. - If KeyUp = False Then - Dim HookEventArgs As New KeyboardHookEventArgs(KeyCode, ScanCode, Extended, KeyState.Down, Me.Modifiers) - - If Internal.IsModifier(KeyCode, ModifierKeys.Control) = True Then Me.Modifiers = Me.Modifiers Or ModifierKeys.Control - If Internal.IsModifier(KeyCode, ModifierKeys.Shift) = True Then Me.Modifiers = Me.Modifiers Or ModifierKeys.Shift - If Internal.IsModifier(KeyCode, ModifierKeys.Alt) = True Then Me.Modifiers = Me.Modifiers Or ModifierKeys.Alt - If Internal.IsModifier(KeyCode, ModifierKeys.Windows) = True Then Me.Modifiers = Me.Modifiers Or ModifierKeys.Windows - - RaiseEvent KeyDown(Me, HookEventArgs) - Block = HookEventArgs.Block - Else - 'Must be done before creating the HookEventArgs during KeyUp. - If Internal.IsModifier(KeyCode, ModifierKeys.Control) = True Then Me.Modifiers = Me.Modifiers And Not ModifierKeys.Control - If Internal.IsModifier(KeyCode, ModifierKeys.Shift) = True Then Me.Modifiers = Me.Modifiers And Not ModifierKeys.Shift - If Internal.IsModifier(KeyCode, ModifierKeys.Alt) = True Then Me.Modifiers = Me.Modifiers And Not ModifierKeys.Alt - If Internal.IsModifier(KeyCode, ModifierKeys.Windows) = True Then Me.Modifiers = Me.Modifiers And Not ModifierKeys.Windows - - Dim HookEventArgs As New KeyboardHookEventArgs(KeyCode, ScanCode, Extended, KeyState.Up, Me.Modifiers) - - RaiseEvent KeyUp(Me, HookEventArgs) - Block = HookEventArgs.Block - End If - End If - - Return If(Block, New IntPtr(1), NativeMethods.CallNextHookEx(hHook, nCode, wParam, lParam)) - End Function - - ''' - ''' Initializes a new instance of the LocalKeyboardHook class attached to the current thread. - ''' - ''' - Public Sub New() - Me.New(NativeMethods.GetCurrentThreadId()) - End Sub - - ''' - ''' Initializes a new instance of the LocalKeyboardHook class attached to the specified thread. - ''' - ''' The thread to attach the hook to. - ''' - Public Sub New(ByVal ThreadID As UInteger) - hHook = NativeMethods.SetWindowsHookEx(NativeMethods.HookType.WH_KEYBOARD, HookProcedureDelegate, IntPtr.Zero, ThreadID) - If hHook = IntPtr.Zero Then - Dim Win32Error As Integer = Marshal.GetLastWin32Error() - Throw New Win32Exception(Win32Error, "Failed to create local keyboard hook! (" & Win32Error & ")") - End If - End Sub - -#Region "IDisposable Support" - Private disposedValue As Boolean ' To detect redundant calls - - ' IDisposable - Protected Sub Dispose(disposing As Boolean) - If Not Me.disposedValue Then - If disposing Then - ' TODO: dispose managed state (managed objects). - End If - - ' TODO: free unmanaged resources (unmanaged objects) and override Finalize() below. - ' TODO: set large fields to null. - If hHook <> IntPtr.Zero Then NativeMethods.UnhookWindowsHookEx(hHook) - End If - Me.disposedValue = True - End Sub - - Protected Overrides Sub Finalize() - ' Do not change this code. Put cleanup code in Dispose(ByVal disposing As Boolean) above. - Dispose(False) - MyBase.Finalize() - End Sub - - ' This code added by Visual Basic to correctly implement the disposable pattern. - Public Sub Dispose() Implements IDisposable.Dispose - ' Do not change this code. Put cleanup code in Dispose(ByVal disposing As Boolean) above. - Dispose(True) - GC.SuppressFinalize(Me) - End Sub -#End Region - - End Class +'+---------------------------------------------------------------------------------+' +'| === InputHelper === |' +'| |' +'| Created by Vincent "Visual Vincent" Bengtsson |' +'| Website: https://www.mydoomsite.com/ |' +'| GitHub: https://github.com/Visual-Vincent |' +'| |' +'| |' +'| === COPYRIGHT LICENSE === |' +'| |' +'| Copyright (c) 2016-2022, Vincent Bengtsson |' +'| All rights reserved. |' +'| |' +'| Redistribution and use in source and binary forms, with or without |' +'| modification, are permitted provided that the following conditions are met: |' +'| |' +'| 1. Redistributions of source code must retain the above copyright notice, this |' +'| list of conditions and the following disclaimer. |' +'| |' +'| 2. Redistributions in binary form must reproduce the above copyright notice, |' +'| this list of conditions and the following disclaimer in the documentation |' +'| and/or other materials provided with the distribution. |' +'| |' +'| 3. Neither the name of the copyright holder nor the names of its |' +'| contributors may be used to endorse or promote products derived from |' +'| this software without specific prior written permission. |' +'| |' +'| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |' +'| AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |' +'| IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |' +'| DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |' +'| FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |' +'| DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |' +'| SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |' +'| CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |' +'| OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |' +'| OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |' +'+---------------------------------------------------------------------------------+' + +Imports System.Windows.Forms +Imports System.Runtime.InteropServices +Imports System.ComponentModel +Imports InputHelper.EventArgs + +Namespace Hooks + ''' + ''' A local keyboard hook that raises events when a key is pressed or released in a specific thread. + ''' + ''' + Public NotInheritable Class LocalKeyboardHook + Implements IDisposable + + ''' + ''' Occurs when a key is pressed or held down. + ''' + ''' + Public Event KeyDown As EventHandler(Of KeyboardHookEventArgs) + + ''' + ''' Occurs when a key is released. + ''' + ''' + Public Event KeyUp As EventHandler(Of KeyboardHookEventArgs) + + Private hHook As IntPtr = IntPtr.Zero + Private HookProcedureDelegate As New NativeMethods.KeyboardProc(AddressOf HookCallback) + + Private Modifiers As ModifierKeys = ModifierKeys.None + + Private Function HookCallback(ByVal nCode As Integer, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr + Dim Block As Boolean = False + + If nCode >= NativeMethods.HookCode.HC_ACTION Then + Dim KeyCode As Keys = CType(wParam.ToInt32(), Keys) + Dim KeyFlags As New NativeMethods.QWORD(lParam.ToInt64()) + Dim ScanCode As Byte = BitConverter.GetBytes(KeyFlags)(2) 'The scan code is the third byte in the integer (bits 16-23). + Dim Extended As Boolean = (KeyFlags.LowWord.High And NativeMethods.KeyboardFlags.KF_EXTENDED) = NativeMethods.KeyboardFlags.KF_EXTENDED + Dim AltDown As Boolean = (KeyFlags.LowWord.High And NativeMethods.KeyboardFlags.KF_ALTDOWN) = NativeMethods.KeyboardFlags.KF_ALTDOWN + Dim KeyUp As Boolean = (KeyFlags.LowWord.High And NativeMethods.KeyboardFlags.KF_UP) = NativeMethods.KeyboardFlags.KF_UP + + 'Set the ALT modifier if the KF_ALTDOWN flag is set. + If AltDown = True _ + AndAlso Internal.IsModifier(KeyCode, ModifierKeys.Alt) = False _ + AndAlso (Me.Modifiers And ModifierKeys.Alt) <> ModifierKeys.Alt Then + + Me.Modifiers = Me.Modifiers Or ModifierKeys.Alt + End If + + 'Raise KeyDown/KeyUp event. + If KeyUp = False Then + Dim HookEventArgs As New KeyboardHookEventArgs(KeyCode, ScanCode, Extended, KeyState.Down, Me.Modifiers) + + If Internal.IsModifier(KeyCode, ModifierKeys.Control) = True Then Me.Modifiers = Me.Modifiers Or ModifierKeys.Control + If Internal.IsModifier(KeyCode, ModifierKeys.Shift) = True Then Me.Modifiers = Me.Modifiers Or ModifierKeys.Shift + If Internal.IsModifier(KeyCode, ModifierKeys.Alt) = True Then Me.Modifiers = Me.Modifiers Or ModifierKeys.Alt + If Internal.IsModifier(KeyCode, ModifierKeys.Windows) = True Then Me.Modifiers = Me.Modifiers Or ModifierKeys.Windows + + RaiseEvent KeyDown(Me, HookEventArgs) + Block = HookEventArgs.Block + Else + 'Must be done before creating the HookEventArgs during KeyUp. + If Internal.IsModifier(KeyCode, ModifierKeys.Control) = True Then Me.Modifiers = Me.Modifiers And Not ModifierKeys.Control + If Internal.IsModifier(KeyCode, ModifierKeys.Shift) = True Then Me.Modifiers = Me.Modifiers And Not ModifierKeys.Shift + If Internal.IsModifier(KeyCode, ModifierKeys.Alt) = True Then Me.Modifiers = Me.Modifiers And Not ModifierKeys.Alt + If Internal.IsModifier(KeyCode, ModifierKeys.Windows) = True Then Me.Modifiers = Me.Modifiers And Not ModifierKeys.Windows + + Dim HookEventArgs As New KeyboardHookEventArgs(KeyCode, ScanCode, Extended, KeyState.Up, Me.Modifiers) + + RaiseEvent KeyUp(Me, HookEventArgs) + Block = HookEventArgs.Block + End If + End If + + Return If(Block, New IntPtr(1), NativeMethods.CallNextHookEx(hHook, nCode, wParam, lParam)) + End Function + + ''' + ''' Initializes a new instance of the LocalKeyboardHook class attached to the current thread. + ''' + ''' + Public Sub New() + Me.New(NativeMethods.GetCurrentThreadId()) + End Sub + + ''' + ''' Initializes a new instance of the LocalKeyboardHook class attached to the specified thread. + ''' + ''' The thread to attach the hook to. + ''' + Public Sub New(ByVal ThreadID As UInteger) + hHook = NativeMethods.SetWindowsHookEx(NativeMethods.HookType.WH_KEYBOARD, HookProcedureDelegate, IntPtr.Zero, ThreadID) + If hHook = IntPtr.Zero Then + Dim Win32Error As Integer = Marshal.GetLastWin32Error() + Throw New Win32Exception(Win32Error, "Failed to create local keyboard hook! (" & Win32Error & ")") + End If + End Sub + +#Region "IDisposable Support" + Private disposedValue As Boolean ' To detect redundant calls + + ' IDisposable + Protected Sub Dispose(disposing As Boolean) + If Not Me.disposedValue Then + If disposing Then + ' TODO: dispose managed state (managed objects). + End If + + ' TODO: free unmanaged resources (unmanaged objects) and override Finalize() below. + ' TODO: set large fields to null. + If hHook <> IntPtr.Zero Then NativeMethods.UnhookWindowsHookEx(hHook) + End If + Me.disposedValue = True + End Sub + + Protected Overrides Sub Finalize() + ' Do not change this code. Put cleanup code in Dispose(ByVal disposing As Boolean) above. + Dispose(False) + MyBase.Finalize() + End Sub + + ' This code added by Visual Basic to correctly implement the disposable pattern. + Public Sub Dispose() Implements IDisposable.Dispose + ' Do not change this code. Put cleanup code in Dispose(ByVal disposing As Boolean) above. + Dispose(True) + GC.SuppressFinalize(Me) + End Sub +#End Region + + End Class End Namespace \ No newline at end of file diff --git a/InputHelper Library/InputHelper .NET 4.x/Hooks/MouseHook.vb b/InputHelper/Hooks/MouseHook.vb similarity index 97% rename from InputHelper Library/InputHelper .NET 4.x/Hooks/MouseHook.vb rename to InputHelper/Hooks/MouseHook.vb index d708fb3..11860e1 100644 --- a/InputHelper Library/InputHelper .NET 4.x/Hooks/MouseHook.vb +++ b/InputHelper/Hooks/MouseHook.vb @@ -1,252 +1,252 @@ -'+---------------------------------------------------------------------------------+' -'| === InputHelper === |' -'| |' -'| Created by Vincent "Visual Vincent" Bengtsson |' -'| Website: https://www.mydoomsite.com/ |' -'| GitHub: https://github.com/Visual-Vincent |' -'| |' -'| |' -'| === COPYRIGHT LICENSE === |' -'| |' -'| Copyright (c) 2016-2019, Vincent Bengtsson |' -'| All rights reserved. |' -'| |' -'| Redistribution and use in source and binary forms, with or without |' -'| modification, are permitted provided that the following conditions are met: |' -'| |' -'| 1. Redistributions of source code must retain the above copyright notice, this |' -'| list of conditions and the following disclaimer. |' -'| |' -'| 2. Redistributions in binary form must reproduce the above copyright notice, |' -'| this list of conditions and the following disclaimer in the documentation |' -'| and/or other materials provided with the distribution. |' -'| |' -'| 3. Neither the name of the copyright holder nor the names of its |' -'| contributors may be used to endorse or promote products derived from |' -'| this software without specific prior written permission. |' -'| |' -'| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |' -'| AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |' -'| IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |' -'| DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |' -'| FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |' -'| DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |' -'| SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |' -'| CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |' -'| OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |' -'| OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |' -'+---------------------------------------------------------------------------------+' - -Imports System.Drawing -Imports System.Windows.Forms -Imports System.Runtime.InteropServices -Imports System.ComponentModel -Imports InputHelper.EventArgs - -Namespace Hooks - ''' - ''' A global low-level mouse hook that raises events when a mouse event occurs. - ''' - ''' - Public NotInheritable Class MouseHook - Implements IDisposable - - ''' - ''' Occurs when a mouse button is pressed or held down. - ''' - ''' - Public Event MouseDown As EventHandler(Of MouseHookEventArgs) - - ''' - ''' Occurs when a mouse button is released. - ''' - ''' - Public Event MouseUp As EventHandler(Of MouseHookEventArgs) - - ''' - ''' Occurs when the mouse moves. - ''' - ''' - Public Event MouseMove As EventHandler(Of MouseHookEventArgs) - - ''' - ''' Occurs when the mouse wheel is scrolled. - ''' - ''' - Public Event MouseWheel As EventHandler(Of MouseHookEventArgs) - - Private hHook As IntPtr = IntPtr.Zero - Private HookProcedureDelegate As New NativeMethods.LowLevelMouseProc(AddressOf HookCallback) - - Private LeftClickTimeStamp As Integer = 0 - Private MiddleClickTimeStamp As Integer = 0 - Private RightClickTimeStamp As Integer = 0 - Private X1ClickTimeStamp As Integer = 0 - Private X2ClickTimeStamp As Integer = 0 - - Private Function HookCallback(ByVal nCode As Integer, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr - Dim Block As Boolean = False - - If nCode >= NativeMethods.HookCode.HC_ACTION AndAlso _ - (wParam = NativeMethods.MouseMessage.WM_LBUTTONDOWN OrElse _ - wParam = NativeMethods.MouseMessage.WM_LBUTTONUP OrElse _ - wParam = NativeMethods.MouseMessage.WM_MBUTTONDOWN OrElse _ - wParam = NativeMethods.MouseMessage.WM_MBUTTONUP OrElse _ - wParam = NativeMethods.MouseMessage.WM_RBUTTONDOWN OrElse _ - wParam = NativeMethods.MouseMessage.WM_RBUTTONUP OrElse _ - wParam = NativeMethods.MouseMessage.WM_XBUTTONDOWN OrElse _ - wParam = NativeMethods.MouseMessage.WM_XBUTTONUP OrElse _ - wParam = NativeMethods.MouseMessage.WM_MOUSEWHEEL OrElse _ - wParam = NativeMethods.MouseMessage.WM_MOUSEHWHEEL OrElse _ - wParam = NativeMethods.MouseMessage.WM_MOUSEMOVE) Then - - Dim MouseEventInfo As NativeMethods.MSLLHOOKSTRUCT = _ - CType(Marshal.PtrToStructure(lParam, GetType(NativeMethods.MSLLHOOKSTRUCT)), NativeMethods.MSLLHOOKSTRUCT) - - Select Case wParam - Case NativeMethods.MouseMessage.WM_LBUTTONDOWN - Dim DoubleClick As Boolean = (Environment.TickCount - LeftClickTimeStamp) <= NativeMethods.GetDoubleClickTime() - LeftClickTimeStamp = Environment.TickCount - - Dim HookEventArgs As New MouseHookEventArgs(MouseButtons.Left, KeyState.Down, DoubleClick, _ - New Point(MouseEventInfo.pt.x, MouseEventInfo.pt.y), ScrollDirection.None, 0) - RaiseEvent MouseDown(Me, HookEventArgs) - Block = HookEventArgs.Block - - - Case NativeMethods.MouseMessage.WM_LBUTTONUP - Dim HookEventArgs As New MouseHookEventArgs(MouseButtons.Left, KeyState.Up, False, _ - New Point(MouseEventInfo.pt.x, MouseEventInfo.pt.y), ScrollDirection.None, 0) - RaiseEvent MouseUp(Me, HookEventArgs) - Block = HookEventArgs.Block - - - Case NativeMethods.MouseMessage.WM_MBUTTONDOWN - Dim DoubleClick As Boolean = (Environment.TickCount - MiddleClickTimeStamp) <= NativeMethods.GetDoubleClickTime() - MiddleClickTimeStamp = Environment.TickCount - - Dim HookEventArgs As New MouseHookEventArgs(MouseButtons.Middle, KeyState.Down, DoubleClick, _ - New Point(MouseEventInfo.pt.x, MouseEventInfo.pt.y), ScrollDirection.None, 0) - RaiseEvent MouseDown(Me, HookEventArgs) - Block = HookEventArgs.Block - - - Case NativeMethods.MouseMessage.WM_MBUTTONUP - Dim HookEventArgs As New MouseHookEventArgs(MouseButtons.Middle, KeyState.Up, False, _ - New Point(MouseEventInfo.pt.x, MouseEventInfo.pt.y), ScrollDirection.None, 0) - RaiseEvent MouseUp(Me, HookEventArgs) - Block = HookEventArgs.Block - - - Case NativeMethods.MouseMessage.WM_RBUTTONDOWN - Dim DoubleClick As Boolean = (Environment.TickCount - RightClickTimeStamp) <= NativeMethods.GetDoubleClickTime() - RightClickTimeStamp = Environment.TickCount - - Dim HookEventArgs As New MouseHookEventArgs(MouseButtons.Right, KeyState.Down, DoubleClick, _ - New Point(MouseEventInfo.pt.x, MouseEventInfo.pt.y), ScrollDirection.None, 0) - RaiseEvent MouseDown(Me, HookEventArgs) - Block = HookEventArgs.Block - - - Case NativeMethods.MouseMessage.WM_RBUTTONUP - Dim HookEventArgs As New MouseHookEventArgs(MouseButtons.Right, KeyState.Up, False, _ - New Point(MouseEventInfo.pt.x, MouseEventInfo.pt.y), ScrollDirection.None, 0) - RaiseEvent MouseUp(Me, HookEventArgs) - Block = HookEventArgs.Block - - - Case NativeMethods.MouseMessage.WM_XBUTTONDOWN - Dim IsXButton2 As Boolean = (New NativeMethods.DWORD(MouseEventInfo.mouseData).High = 2) - Dim DoubleClick As Boolean = (Environment.TickCount - If(IsXButton2, X2ClickTimeStamp, X1ClickTimeStamp)) <= NativeMethods.GetDoubleClickTime() - - If IsXButton2 = True Then X2ClickTimeStamp = Environment.TickCount _ - Else X1ClickTimeStamp = Environment.TickCount - - Dim HookEventArgs As New MouseHookEventArgs(If(IsXButton2, MouseButtons.XButton2, MouseButtons.XButton1), KeyState.Down, DoubleClick, _ - New Point(MouseEventInfo.pt.x, MouseEventInfo.pt.y), ScrollDirection.None, 0) - RaiseEvent MouseUp(Me, HookEventArgs) - Block = HookEventArgs.Block - - - Case NativeMethods.MouseMessage.WM_XBUTTONUP - Dim IsXButton2 As Boolean = (New NativeMethods.DWORD(MouseEventInfo.mouseData).High = 2) - Dim HookEventArgs As New MouseHookEventArgs(If(IsXButton2, MouseButtons.XButton2, MouseButtons.XButton1), KeyState.Up, False, _ - New Point(MouseEventInfo.pt.x, MouseEventInfo.pt.y), ScrollDirection.None, 0) - RaiseEvent MouseUp(Me, HookEventArgs) - Block = HookEventArgs.Block - - - Case NativeMethods.MouseMessage.WM_MOUSEWHEEL - Dim Delta As Integer = New NativeMethods.DWORD(MouseEventInfo.mouseData).SignedHigh - Dim HookEventArgs As New MouseHookEventArgs(MouseButtons.None, KeyState.Up, False, _ - New Point(MouseEventInfo.pt.x, MouseEventInfo.pt.y), ScrollDirection.Vertical, Delta) - RaiseEvent MouseWheel(Me, HookEventArgs) - Block = HookEventArgs.Block - - - Case NativeMethods.MouseMessage.WM_MOUSEHWHEEL - Dim Delta As Integer = New NativeMethods.DWORD(MouseEventInfo.mouseData).SignedHigh - Dim HookEventArgs As New MouseHookEventArgs(MouseButtons.None, KeyState.Up, False, _ - New Point(MouseEventInfo.pt.x, MouseEventInfo.pt.y), ScrollDirection.Horizontal, Delta) - RaiseEvent MouseWheel(Me, HookEventArgs) - Block = HookEventArgs.Block - - - Case NativeMethods.MouseMessage.WM_MOUSEMOVE - Dim HookEventArgs As New MouseHookEventArgs(MouseButtons.None, KeyState.Up, False, _ - New Point(MouseEventInfo.pt.x, MouseEventInfo.pt.y), ScrollDirection.None, 0) - RaiseEvent MouseMove(Me, HookEventArgs) - Block = HookEventArgs.Block - - - End Select - End If - - Return If(Block, New IntPtr(1), NativeMethods.CallNextHookEx(hHook, nCode, wParam, lParam)) - End Function - - ''' - ''' Initializes a new instance of the MouseHook clas. - ''' - ''' - Public Sub New() - hHook = NativeMethods.SetWindowsHookEx(NativeMethods.HookType.WH_MOUSE_LL, HookProcedureDelegate, NativeMethods.GetModuleHandle(Nothing), 0) - If hHook = IntPtr.Zero Then - Dim Win32Error As Integer = Marshal.GetLastWin32Error() - Throw New Win32Exception(Win32Error, "Failed to create mouse hook! (" & Win32Error & ")") - End If - End Sub - -#Region "IDisposable Support" - Private disposedValue As Boolean ' To detect redundant calls - - ' IDisposable - Protected Sub Dispose(disposing As Boolean) - If Not Me.disposedValue Then - If disposing Then - ' TODO: dispose managed state (managed objects). - End If - - ' TODO: free unmanaged resources (unmanaged objects) and override Finalize() below. - ' TODO: set large fields to null. - If hHook <> IntPtr.Zero Then NativeMethods.UnhookWindowsHookEx(hHook) - End If - Me.disposedValue = True - End Sub - - Protected Overrides Sub Finalize() - ' Do not change this code. Put cleanup code in Dispose(ByVal disposing As Boolean) above. - Dispose(False) - MyBase.Finalize() - End Sub - - ' This code added by Visual Basic to correctly implement the disposable pattern. - Public Sub Dispose() Implements IDisposable.Dispose - ' Do not change this code. Put cleanup code in Dispose(ByVal disposing As Boolean) above. - Dispose(True) - GC.SuppressFinalize(Me) - End Sub -#End Region - - End Class +'+---------------------------------------------------------------------------------+' +'| === InputHelper === |' +'| |' +'| Created by Vincent "Visual Vincent" Bengtsson |' +'| Website: https://www.mydoomsite.com/ |' +'| GitHub: https://github.com/Visual-Vincent |' +'| |' +'| |' +'| === COPYRIGHT LICENSE === |' +'| |' +'| Copyright (c) 2016-2022, Vincent Bengtsson |' +'| All rights reserved. |' +'| |' +'| Redistribution and use in source and binary forms, with or without |' +'| modification, are permitted provided that the following conditions are met: |' +'| |' +'| 1. Redistributions of source code must retain the above copyright notice, this |' +'| list of conditions and the following disclaimer. |' +'| |' +'| 2. Redistributions in binary form must reproduce the above copyright notice, |' +'| this list of conditions and the following disclaimer in the documentation |' +'| and/or other materials provided with the distribution. |' +'| |' +'| 3. Neither the name of the copyright holder nor the names of its |' +'| contributors may be used to endorse or promote products derived from |' +'| this software without specific prior written permission. |' +'| |' +'| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |' +'| AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |' +'| IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |' +'| DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |' +'| FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |' +'| DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |' +'| SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |' +'| CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |' +'| OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |' +'| OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |' +'+---------------------------------------------------------------------------------+' + +Imports System.Drawing +Imports System.Windows.Forms +Imports System.Runtime.InteropServices +Imports System.ComponentModel +Imports InputHelper.EventArgs + +Namespace Hooks + ''' + ''' A global low-level mouse hook that raises events when a mouse event occurs. + ''' + ''' + Public NotInheritable Class MouseHook + Implements IDisposable + + ''' + ''' Occurs when a mouse button is pressed or held down. + ''' + ''' + Public Event MouseDown As EventHandler(Of MouseHookEventArgs) + + ''' + ''' Occurs when a mouse button is released. + ''' + ''' + Public Event MouseUp As EventHandler(Of MouseHookEventArgs) + + ''' + ''' Occurs when the mouse moves. + ''' + ''' + Public Event MouseMove As EventHandler(Of MouseHookEventArgs) + + ''' + ''' Occurs when the mouse wheel is scrolled. + ''' + ''' + Public Event MouseWheel As EventHandler(Of MouseHookEventArgs) + + Private hHook As IntPtr = IntPtr.Zero + Private HookProcedureDelegate As New NativeMethods.LowLevelMouseProc(AddressOf HookCallback) + + Private LeftClickTimeStamp As Integer = 0 + Private MiddleClickTimeStamp As Integer = 0 + Private RightClickTimeStamp As Integer = 0 + Private X1ClickTimeStamp As Integer = 0 + Private X2ClickTimeStamp As Integer = 0 + + Private Function HookCallback(ByVal nCode As Integer, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr + Dim Block As Boolean = False + + If nCode >= NativeMethods.HookCode.HC_ACTION AndAlso _ + (wParam = NativeMethods.MouseMessage.WM_LBUTTONDOWN OrElse _ + wParam = NativeMethods.MouseMessage.WM_LBUTTONUP OrElse _ + wParam = NativeMethods.MouseMessage.WM_MBUTTONDOWN OrElse _ + wParam = NativeMethods.MouseMessage.WM_MBUTTONUP OrElse _ + wParam = NativeMethods.MouseMessage.WM_RBUTTONDOWN OrElse _ + wParam = NativeMethods.MouseMessage.WM_RBUTTONUP OrElse _ + wParam = NativeMethods.MouseMessage.WM_XBUTTONDOWN OrElse _ + wParam = NativeMethods.MouseMessage.WM_XBUTTONUP OrElse _ + wParam = NativeMethods.MouseMessage.WM_MOUSEWHEEL OrElse _ + wParam = NativeMethods.MouseMessage.WM_MOUSEHWHEEL OrElse _ + wParam = NativeMethods.MouseMessage.WM_MOUSEMOVE) Then + + Dim MouseEventInfo As NativeMethods.MSLLHOOKSTRUCT = _ + CType(Marshal.PtrToStructure(lParam, GetType(NativeMethods.MSLLHOOKSTRUCT)), NativeMethods.MSLLHOOKSTRUCT) + + Select Case wParam + Case NativeMethods.MouseMessage.WM_LBUTTONDOWN + Dim DoubleClick As Boolean = (Environment.TickCount - LeftClickTimeStamp) <= NativeMethods.GetDoubleClickTime() + LeftClickTimeStamp = Environment.TickCount + + Dim HookEventArgs As New MouseHookEventArgs(MouseButtons.Left, KeyState.Down, DoubleClick, _ + New Point(MouseEventInfo.pt.x, MouseEventInfo.pt.y), ScrollDirection.None, 0) + RaiseEvent MouseDown(Me, HookEventArgs) + Block = HookEventArgs.Block + + + Case NativeMethods.MouseMessage.WM_LBUTTONUP + Dim HookEventArgs As New MouseHookEventArgs(MouseButtons.Left, KeyState.Up, False, _ + New Point(MouseEventInfo.pt.x, MouseEventInfo.pt.y), ScrollDirection.None, 0) + RaiseEvent MouseUp(Me, HookEventArgs) + Block = HookEventArgs.Block + + + Case NativeMethods.MouseMessage.WM_MBUTTONDOWN + Dim DoubleClick As Boolean = (Environment.TickCount - MiddleClickTimeStamp) <= NativeMethods.GetDoubleClickTime() + MiddleClickTimeStamp = Environment.TickCount + + Dim HookEventArgs As New MouseHookEventArgs(MouseButtons.Middle, KeyState.Down, DoubleClick, _ + New Point(MouseEventInfo.pt.x, MouseEventInfo.pt.y), ScrollDirection.None, 0) + RaiseEvent MouseDown(Me, HookEventArgs) + Block = HookEventArgs.Block + + + Case NativeMethods.MouseMessage.WM_MBUTTONUP + Dim HookEventArgs As New MouseHookEventArgs(MouseButtons.Middle, KeyState.Up, False, _ + New Point(MouseEventInfo.pt.x, MouseEventInfo.pt.y), ScrollDirection.None, 0) + RaiseEvent MouseUp(Me, HookEventArgs) + Block = HookEventArgs.Block + + + Case NativeMethods.MouseMessage.WM_RBUTTONDOWN + Dim DoubleClick As Boolean = (Environment.TickCount - RightClickTimeStamp) <= NativeMethods.GetDoubleClickTime() + RightClickTimeStamp = Environment.TickCount + + Dim HookEventArgs As New MouseHookEventArgs(MouseButtons.Right, KeyState.Down, DoubleClick, _ + New Point(MouseEventInfo.pt.x, MouseEventInfo.pt.y), ScrollDirection.None, 0) + RaiseEvent MouseDown(Me, HookEventArgs) + Block = HookEventArgs.Block + + + Case NativeMethods.MouseMessage.WM_RBUTTONUP + Dim HookEventArgs As New MouseHookEventArgs(MouseButtons.Right, KeyState.Up, False, _ + New Point(MouseEventInfo.pt.x, MouseEventInfo.pt.y), ScrollDirection.None, 0) + RaiseEvent MouseUp(Me, HookEventArgs) + Block = HookEventArgs.Block + + + Case NativeMethods.MouseMessage.WM_XBUTTONDOWN + Dim IsXButton2 As Boolean = (New NativeMethods.DWORD(MouseEventInfo.mouseData).High = 2) + Dim DoubleClick As Boolean = (Environment.TickCount - If(IsXButton2, X2ClickTimeStamp, X1ClickTimeStamp)) <= NativeMethods.GetDoubleClickTime() + + If IsXButton2 = True Then X2ClickTimeStamp = Environment.TickCount _ + Else X1ClickTimeStamp = Environment.TickCount + + Dim HookEventArgs As New MouseHookEventArgs(If(IsXButton2, MouseButtons.XButton2, MouseButtons.XButton1), KeyState.Down, DoubleClick, _ + New Point(MouseEventInfo.pt.x, MouseEventInfo.pt.y), ScrollDirection.None, 0) + RaiseEvent MouseDown(Me, HookEventArgs) + Block = HookEventArgs.Block + + + Case NativeMethods.MouseMessage.WM_XBUTTONUP + Dim IsXButton2 As Boolean = (New NativeMethods.DWORD(MouseEventInfo.mouseData).High = 2) + Dim HookEventArgs As New MouseHookEventArgs(If(IsXButton2, MouseButtons.XButton2, MouseButtons.XButton1), KeyState.Up, False, _ + New Point(MouseEventInfo.pt.x, MouseEventInfo.pt.y), ScrollDirection.None, 0) + RaiseEvent MouseUp(Me, HookEventArgs) + Block = HookEventArgs.Block + + + Case NativeMethods.MouseMessage.WM_MOUSEWHEEL + Dim Delta As Integer = New NativeMethods.DWORD(MouseEventInfo.mouseData).SignedHigh + Dim HookEventArgs As New MouseHookEventArgs(MouseButtons.None, KeyState.Up, False, _ + New Point(MouseEventInfo.pt.x, MouseEventInfo.pt.y), ScrollDirection.Vertical, Delta) + RaiseEvent MouseWheel(Me, HookEventArgs) + Block = HookEventArgs.Block + + + Case NativeMethods.MouseMessage.WM_MOUSEHWHEEL + Dim Delta As Integer = New NativeMethods.DWORD(MouseEventInfo.mouseData).SignedHigh + Dim HookEventArgs As New MouseHookEventArgs(MouseButtons.None, KeyState.Up, False, _ + New Point(MouseEventInfo.pt.x, MouseEventInfo.pt.y), ScrollDirection.Horizontal, Delta) + RaiseEvent MouseWheel(Me, HookEventArgs) + Block = HookEventArgs.Block + + + Case NativeMethods.MouseMessage.WM_MOUSEMOVE + Dim HookEventArgs As New MouseHookEventArgs(MouseButtons.None, KeyState.Up, False, _ + New Point(MouseEventInfo.pt.x, MouseEventInfo.pt.y), ScrollDirection.None, 0) + RaiseEvent MouseMove(Me, HookEventArgs) + Block = HookEventArgs.Block + + + End Select + End If + + Return If(Block, New IntPtr(1), NativeMethods.CallNextHookEx(hHook, nCode, wParam, lParam)) + End Function + + ''' + ''' Initializes a new instance of the MouseHook clas. + ''' + ''' + Public Sub New() + hHook = NativeMethods.SetWindowsHookEx(NativeMethods.HookType.WH_MOUSE_LL, HookProcedureDelegate, NativeMethods.GetModuleHandle(Nothing), 0) + If hHook = IntPtr.Zero Then + Dim Win32Error As Integer = Marshal.GetLastWin32Error() + Throw New Win32Exception(Win32Error, "Failed to create mouse hook! (" & Win32Error & ")") + End If + End Sub + +#Region "IDisposable Support" + Private disposedValue As Boolean ' To detect redundant calls + + ' IDisposable + Protected Sub Dispose(disposing As Boolean) + If Not Me.disposedValue Then + If disposing Then + ' TODO: dispose managed state (managed objects). + End If + + ' TODO: free unmanaged resources (unmanaged objects) and override Finalize() below. + ' TODO: set large fields to null. + If hHook <> IntPtr.Zero Then NativeMethods.UnhookWindowsHookEx(hHook) + End If + Me.disposedValue = True + End Sub + + Protected Overrides Sub Finalize() + ' Do not change this code. Put cleanup code in Dispose(ByVal disposing As Boolean) above. + Dispose(False) + MyBase.Finalize() + End Sub + + ' This code added by Visual Basic to correctly implement the disposable pattern. + Public Sub Dispose() Implements IDisposable.Dispose + ' Do not change this code. Put cleanup code in Dispose(ByVal disposing As Boolean) above. + Dispose(True) + GC.SuppressFinalize(Me) + End Sub +#End Region + + End Class End Namespace \ No newline at end of file diff --git a/InputHelper Library/InputHelper .NET 4.x/Input Handling/Keyboard.vb b/InputHelper/Input Handling/Keyboard.vb similarity index 97% rename from InputHelper Library/InputHelper .NET 4.x/Input Handling/Keyboard.vb rename to InputHelper/Input Handling/Keyboard.vb index 19e80ad..fffd4be 100644 --- a/InputHelper Library/InputHelper .NET 4.x/Input Handling/Keyboard.vb +++ b/InputHelper/Input Handling/Keyboard.vb @@ -1,154 +1,154 @@ -'+---------------------------------------------------------------------------------+' -'| === InputHelper === |' -'| |' -'| Created by Vincent "Visual Vincent" Bengtsson |' -'| Website: https://www.mydoomsite.com/ |' -'| GitHub: https://github.com/Visual-Vincent |' -'| |' -'| |' -'| === COPYRIGHT LICENSE === |' -'| |' -'| Copyright (c) 2016-2019, Vincent Bengtsson |' -'| All rights reserved. |' -'| |' -'| Redistribution and use in source and binary forms, with or without |' -'| modification, are permitted provided that the following conditions are met: |' -'| |' -'| 1. Redistributions of source code must retain the above copyright notice, this |' -'| list of conditions and the following disclaimer. |' -'| |' -'| 2. Redistributions in binary form must reproduce the above copyright notice, |' -'| this list of conditions and the following disclaimer in the documentation |' -'| and/or other materials provided with the distribution. |' -'| |' -'| 3. Neither the name of the copyright holder nor the names of its |' -'| contributors may be used to endorse or promote products derived from |' -'| this software without specific prior written permission. |' -'| |' -'| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |' -'| AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |' -'| IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |' -'| DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |' -'| FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |' -'| DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |' -'| SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |' -'| CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |' -'| OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |' -'| OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |' -'+---------------------------------------------------------------------------------+' - -Imports System.Windows.Forms -Imports System.Runtime.InteropServices - -''' -''' A static class for handling and simulating physical keyboard input. -''' -''' -Public NotInheritable Class Keyboard - Private Sub New() - End Sub - -#Region "Public methods" - -#Region "IsKeyDown()" - ''' - ''' Checks whether the specified key is currently held down. - ''' - ''' The key to check. - ''' - Public Shared Function IsKeyDown(ByVal Key As Keys) As Boolean - Dim Modifiers As Keys() = Internal.ExtractModifiers(Key) - For Each Modifier As Keys In Modifiers - If (NativeMethods.GetAsyncKeyState(Modifier) And Constants.KeyDownBit) <> Constants.KeyDownBit Then - Return False - End If - Next - - If Key = Keys.None Then Return True 'All modifiers are held down, no more keys left to check. - - Return (NativeMethods.GetAsyncKeyState(Key) And Constants.KeyDownBit) = Constants.KeyDownBit - End Function -#End Region - -#Region "IsKeyUp()" - ''' - ''' Checks whether the specified key is currently NOT held down. - ''' - ''' The key to check. - ''' - Public Shared Function IsKeyUp(ByVal Key As Keys) As Boolean - Return Keyboard.IsKeyDown(Key) = False - End Function -#End Region - -#Region "PressKey()" - ''' - ''' Simulates a keystroke. - ''' - ''' The key to press. - ''' Whether to simulate the keystroke using its virtual key code or its hardware scan code. - ''' - Public Shared Sub PressKey(ByVal Key As Keys, Optional ByVal HardwareKey As Boolean = False) - Keyboard.SetKeyState(Key, True, HardwareKey) - Keyboard.SetKeyState(Key, False, HardwareKey) - End Sub -#End Region - -#Region "SetKeyState()" - ''' - ''' Simulates a key being pushed down or released. - ''' - ''' The key which to simulate. - ''' Whether to push down or release the key. - ''' Whether to simulate the event using the key's virtual key code or its hardware scan code. - ''' - Public Shared Sub SetKeyState(ByVal Key As Keys, ByVal KeyDown As Boolean, Optional ByVal HardwareKey As Boolean = False) - Dim InputList As New List(Of NativeMethods.INPUT) - Dim Modifiers As Keys() = Internal.ExtractModifiers(Key) - - For Each Modifier As Keys In Modifiers - InputList.Add(Keyboard.GetKeyboardInputStructure(Modifier, KeyDown, HardwareKey)) - Next - InputList.Add(Keyboard.GetKeyboardInputStructure(Key, KeyDown, HardwareKey)) - - NativeMethods.SendInput(CType(InputList.Count, UInteger), InputList.ToArray(), Marshal.SizeOf(GetType(NativeMethods.INPUT))) - End Sub -#End Region - -#End Region - -#Region "Internal methods" - -#Region "GetKeyboardInputStructure()" - ''' - ''' Constructs a native keyboard INPUT structure that can be passed to SendInput(). - ''' - ''' The key to send. - ''' Whether to send a KeyDown/KeyUp stroke. - ''' Whether to send the key's hardware scan code instead of its virtual key code. - ''' - Private Shared Function GetKeyboardInputStructure(ByVal Key As Keys, ByVal KeyDown As Boolean, ByVal HardwareKey As Boolean) As NativeMethods.INPUT - Dim KeyboardInput As New NativeMethods.KEYBDINPUT With { - .wVk = If(HardwareKey = False, (Key And UShort.MaxValue), 0), - .wScan = If(HardwareKey, - NativeMethods.MapVirtualKeyEx(CType(Key, UInteger), 0, NativeMethods.GetKeyboardLayout(0)), - 0) And UShort.MaxValue, - .time = 0, - .dwFlags = If(HardwareKey, NativeMethods.KEYEVENTF.SCANCODE, 0) Or - If(KeyDown = False, NativeMethods.KEYEVENTF.KEYUP, 0), - .dwExtraInfo = UIntPtr.Zero - } - - Dim Union As New NativeMethods.INPUTUNION With {.ki = KeyboardInput} - Dim Input As New NativeMethods.INPUT With { - .type = NativeMethods.INPUTTYPE.KEYBOARD, - .U = Union - } - - Return Input - End Function -#End Region - -#End Region - +'+---------------------------------------------------------------------------------+' +'| === InputHelper === |' +'| |' +'| Created by Vincent "Visual Vincent" Bengtsson |' +'| Website: https://www.mydoomsite.com/ |' +'| GitHub: https://github.com/Visual-Vincent |' +'| |' +'| |' +'| === COPYRIGHT LICENSE === |' +'| |' +'| Copyright (c) 2016-2022, Vincent Bengtsson |' +'| All rights reserved. |' +'| |' +'| Redistribution and use in source and binary forms, with or without |' +'| modification, are permitted provided that the following conditions are met: |' +'| |' +'| 1. Redistributions of source code must retain the above copyright notice, this |' +'| list of conditions and the following disclaimer. |' +'| |' +'| 2. Redistributions in binary form must reproduce the above copyright notice, |' +'| this list of conditions and the following disclaimer in the documentation |' +'| and/or other materials provided with the distribution. |' +'| |' +'| 3. Neither the name of the copyright holder nor the names of its |' +'| contributors may be used to endorse or promote products derived from |' +'| this software without specific prior written permission. |' +'| |' +'| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |' +'| AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |' +'| IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |' +'| DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |' +'| FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |' +'| DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |' +'| SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |' +'| CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |' +'| OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |' +'| OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |' +'+---------------------------------------------------------------------------------+' + +Imports System.Windows.Forms +Imports System.Runtime.InteropServices + +''' +''' A static class for handling and simulating physical keyboard input. +''' +''' +Public NotInheritable Class Keyboard + Private Sub New() + End Sub + +#Region "Public methods" + +#Region "IsKeyDown()" + ''' + ''' Checks whether the specified key is currently held down. + ''' + ''' The key to check. + ''' + Public Shared Function IsKeyDown(ByVal Key As Keys) As Boolean + Dim Modifiers As Keys() = Internal.ExtractModifiers(Key) + For Each Modifier As Keys In Modifiers + If (NativeMethods.GetAsyncKeyState(Modifier) And Constants.KeyDownBit) <> Constants.KeyDownBit Then + Return False + End If + Next + + If Key = Keys.None Then Return True 'All modifiers are held down, no more keys left to check. + + Return (NativeMethods.GetAsyncKeyState(Key) And Constants.KeyDownBit) = Constants.KeyDownBit + End Function +#End Region + +#Region "IsKeyUp()" + ''' + ''' Checks whether the specified key is currently NOT held down. + ''' + ''' The key to check. + ''' + Public Shared Function IsKeyUp(ByVal Key As Keys) As Boolean + Return Keyboard.IsKeyDown(Key) = False + End Function +#End Region + +#Region "PressKey()" + ''' + ''' Simulates a keystroke. + ''' + ''' The key to press. + ''' Whether to simulate the keystroke using its virtual key code or its hardware scan code. + ''' + Public Shared Sub PressKey(ByVal Key As Keys, Optional ByVal HardwareKey As Boolean = False) + Keyboard.SetKeyState(Key, True, HardwareKey) + Keyboard.SetKeyState(Key, False, HardwareKey) + End Sub +#End Region + +#Region "SetKeyState()" + ''' + ''' Simulates a key being pushed down or released. + ''' + ''' The key which to simulate. + ''' Whether to push down or release the key. + ''' Whether to simulate the event using the key's virtual key code or its hardware scan code. + ''' + Public Shared Sub SetKeyState(ByVal Key As Keys, ByVal KeyDown As Boolean, Optional ByVal HardwareKey As Boolean = False) + Dim InputList As New List(Of NativeMethods.INPUT) + Dim Modifiers As Keys() = Internal.ExtractModifiers(Key) + + For Each Modifier As Keys In Modifiers + InputList.Add(Keyboard.GetKeyboardInputStructure(Modifier, KeyDown, HardwareKey)) + Next + InputList.Add(Keyboard.GetKeyboardInputStructure(Key, KeyDown, HardwareKey)) + + NativeMethods.SendInput(CType(InputList.Count, UInteger), InputList.ToArray(), Marshal.SizeOf(GetType(NativeMethods.INPUT))) + End Sub +#End Region + +#End Region + +#Region "Internal methods" + +#Region "GetKeyboardInputStructure()" + ''' + ''' Constructs a native keyboard INPUT structure that can be passed to SendInput(). + ''' + ''' The key to send. + ''' Whether to send a KeyDown/KeyUp stroke. + ''' Whether to send the key's hardware scan code instead of its virtual key code. + ''' + Private Shared Function GetKeyboardInputStructure(ByVal Key As Keys, ByVal KeyDown As Boolean, ByVal HardwareKey As Boolean) As NativeMethods.INPUT + Dim KeyboardInput As New NativeMethods.KEYBDINPUT With { + .wVk = If(HardwareKey = False, (Key And UShort.MaxValue), 0), + .wScan = If(HardwareKey, + NativeMethods.MapVirtualKeyEx(CType(Key, UInteger), 0, NativeMethods.GetKeyboardLayout(0)), + 0) And UShort.MaxValue, + .time = 0, + .dwFlags = If(HardwareKey, NativeMethods.KEYEVENTF.SCANCODE, 0) Or + If(KeyDown = False, NativeMethods.KEYEVENTF.KEYUP, 0), + .dwExtraInfo = UIntPtr.Zero + } + + Dim Union As New NativeMethods.INPUTUNION With {.ki = KeyboardInput} + Dim Input As New NativeMethods.INPUT With { + .type = NativeMethods.INPUTTYPE.KEYBOARD, + .U = Union + } + + Return Input + End Function +#End Region + +#End Region + End Class \ No newline at end of file diff --git a/InputHelper Library/InputHelper .NET 3.5/Input Handling/Mouse.vb b/InputHelper/Input Handling/Mouse.vb similarity index 97% rename from InputHelper Library/InputHelper .NET 3.5/Input Handling/Mouse.vb rename to InputHelper/Input Handling/Mouse.vb index 7101995..63fe418 100644 --- a/InputHelper Library/InputHelper .NET 3.5/Input Handling/Mouse.vb +++ b/InputHelper/Input Handling/Mouse.vb @@ -1,164 +1,164 @@ -'+---------------------------------------------------------------------------------+' -'| === InputHelper === |' -'| |' -'| Created by Vincent "Visual Vincent" Bengtsson |' -'| Website: https://www.mydoomsite.com/ |' -'| GitHub: https://github.com/Visual-Vincent |' -'| |' -'| |' -'| === COPYRIGHT LICENSE === |' -'| |' -'| Copyright (c) 2016-2019, Vincent Bengtsson |' -'| All rights reserved. |' -'| |' -'| Redistribution and use in source and binary forms, with or without |' -'| modification, are permitted provided that the following conditions are met: |' -'| |' -'| 1. Redistributions of source code must retain the above copyright notice, this |' -'| list of conditions and the following disclaimer. |' -'| |' -'| 2. Redistributions in binary form must reproduce the above copyright notice, |' -'| this list of conditions and the following disclaimer in the documentation |' -'| and/or other materials provided with the distribution. |' -'| |' -'| 3. Neither the name of the copyright holder nor the names of its |' -'| contributors may be used to endorse or promote products derived from |' -'| this software without specific prior written permission. |' -'| |' -'| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |' -'| AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |' -'| IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |' -'| DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |' -'| FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |' -'| DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |' -'| SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |' -'| CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |' -'| OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |' -'| OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |' -'+---------------------------------------------------------------------------------+' - -Imports System.Drawing -Imports System.Windows.Forms -Imports System.Runtime.InteropServices - -''' -''' A static class for handling and simulating physical mouse input. -''' -''' -Public NotInheritable Class Mouse - Private Sub New() - End Sub - -#Region "Public methods" - -#Region "IsButtonDown()" - ''' - ''' Checks whether the specified mouse button is currently held down. - ''' - ''' The mouse button to check. - ''' - Public Shared Function IsButtonDown(ByVal Button As MouseButtons) As Boolean - Dim Key As Keys = Keys.None - Select Case Button - Case MouseButtons.Left : Key = Keys.LButton - Case MouseButtons.Middle : Key = Keys.MButton - Case MouseButtons.Right : Key = Keys.RButton - Case MouseButtons.XButton1 : Key = Keys.XButton1 - Case MouseButtons.XButton2 : Key = Keys.XButton2 - Case Else - Throw New ArgumentException("Invalid mouse button " & Button.ToString() & "!", "Button") - End Select - - Return Keyboard.IsKeyDown(Key) - End Function -#End Region - -#Region "IsButtonUp()" - ''' - ''' Checks whether the specified mouse button is currently NOT held down. - ''' - ''' The mouse button to check. - ''' - Public Shared Function IsButtonUp(ByVal Button As MouseButtons) As Boolean - Return Mouse.IsButtonDown(Button) = False - End Function -#End Region - -#Region "PressButton()" - ''' - ''' Simulates a mouse button click. - ''' - ''' The button to press. - ''' - Public Shared Sub PressButton(ByVal Button As MouseButtons) - Mouse.SetButtonState(Button, True) - Mouse.SetButtonState(Button, False) - End Sub -#End Region - -#Region "SetButtonState()" - ''' - ''' Simulates a mouse button being pushed down or released. - ''' - ''' The button which to simulate. - ''' Whether to push down or release the mouse button. - ''' - Public Shared Sub SetButtonState(ByVal Button As MouseButtons, ByVal MouseDown As Boolean) - Dim InputList As NativeMethods.INPUT() = _ - New NativeMethods.INPUT(1 - 1) {Mouse.GetMouseClickInputStructure(Button, MouseDown)} - NativeMethods.SendInput(CType(InputList.Length, UInteger), InputList, Marshal.SizeOf(GetType(NativeMethods.INPUT))) - End Sub -#End Region - -#End Region - -#Region "Internal methods" - -#Region "GetMouseClickInputStructure()" - ''' - ''' Constructs a native mouse INPUT structure for click events that can be passed to SendInput(). - ''' - ''' The button of the event. - ''' Whether to push down or release the mouse button. - ''' - Private Shared Function GetMouseClickInputStructure(ByVal Button As MouseButtons, ByVal MouseDown As Boolean) As NativeMethods.INPUT - Dim Position As Point = Cursor.Position - Dim MouseFlags As NativeMethods.MOUSEEVENTF - Dim MouseData As UInteger = 0 - - Select Case Button - Case MouseButtons.Left : MouseFlags = If(MouseDown, NativeMethods.MOUSEEVENTF.LEFTDOWN, NativeMethods.MOUSEEVENTF.LEFTUP) - Case MouseButtons.Middle : MouseFlags = If(MouseDown, NativeMethods.MOUSEEVENTF.MIDDLEDOWN, NativeMethods.MOUSEEVENTF.MIDDLEUP) - Case MouseButtons.Right : MouseFlags = If(MouseDown, NativeMethods.MOUSEEVENTF.RIGHTDOWN, NativeMethods.MOUSEEVENTF.RIGHTUP) - Case MouseButtons.XButton1 - MouseFlags = If(MouseDown, NativeMethods.MOUSEEVENTF.XDOWN, NativeMethods.MOUSEEVENTF.XUP) - MouseData = NativeMethods.MouseXButton.XBUTTON1 - Case MouseButtons.XButton2 - MouseFlags = If(MouseDown, NativeMethods.MOUSEEVENTF.XDOWN, NativeMethods.MOUSEEVENTF.XUP) - MouseData = NativeMethods.MouseXButton.XBUTTON2 - Case Else - Throw New ArgumentException("Invalid mouse button " & Button.ToString() & "!", "Button") - End Select - - Dim MouseInput As New NativeMethods.MOUSEINPUT With { - .dx = Position.X, - .dy = Position.Y, - .mouseData = MouseData, - .dwFlags = MouseFlags, - .time = 0, - .dwExtraInfo = UIntPtr.Zero - } - - Dim Union As New NativeMethods.INPUTUNION With {.mi = MouseInput} - Dim Input As New NativeMethods.INPUT With { - .type = NativeMethods.INPUTTYPE.MOUSE, - .U = Union - } - - Return Input - End Function -#End Region - -#End Region - +'+---------------------------------------------------------------------------------+' +'| === InputHelper === |' +'| |' +'| Created by Vincent "Visual Vincent" Bengtsson |' +'| Website: https://www.mydoomsite.com/ |' +'| GitHub: https://github.com/Visual-Vincent |' +'| |' +'| |' +'| === COPYRIGHT LICENSE === |' +'| |' +'| Copyright (c) 2016-2022, Vincent Bengtsson |' +'| All rights reserved. |' +'| |' +'| Redistribution and use in source and binary forms, with or without |' +'| modification, are permitted provided that the following conditions are met: |' +'| |' +'| 1. Redistributions of source code must retain the above copyright notice, this |' +'| list of conditions and the following disclaimer. |' +'| |' +'| 2. Redistributions in binary form must reproduce the above copyright notice, |' +'| this list of conditions and the following disclaimer in the documentation |' +'| and/or other materials provided with the distribution. |' +'| |' +'| 3. Neither the name of the copyright holder nor the names of its |' +'| contributors may be used to endorse or promote products derived from |' +'| this software without specific prior written permission. |' +'| |' +'| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |' +'| AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |' +'| IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |' +'| DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |' +'| FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |' +'| DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |' +'| SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |' +'| CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |' +'| OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |' +'| OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |' +'+---------------------------------------------------------------------------------+' + +Imports System.Drawing +Imports System.Windows.Forms +Imports System.Runtime.InteropServices + +''' +''' A static class for handling and simulating physical mouse input. +''' +''' +Public NotInheritable Class Mouse + Private Sub New() + End Sub + +#Region "Public methods" + +#Region "IsButtonDown()" + ''' + ''' Checks whether the specified mouse button is currently held down. + ''' + ''' The mouse button to check. + ''' + Public Shared Function IsButtonDown(ByVal Button As MouseButtons) As Boolean + Dim Key As Keys = Keys.None + Select Case Button + Case MouseButtons.Left : Key = Keys.LButton + Case MouseButtons.Middle : Key = Keys.MButton + Case MouseButtons.Right : Key = Keys.RButton + Case MouseButtons.XButton1 : Key = Keys.XButton1 + Case MouseButtons.XButton2 : Key = Keys.XButton2 + Case Else + Throw New ArgumentException("Invalid mouse button " & Button.ToString() & "!", "Button") + End Select + + Return Keyboard.IsKeyDown(Key) + End Function +#End Region + +#Region "IsButtonUp()" + ''' + ''' Checks whether the specified mouse button is currently NOT held down. + ''' + ''' The mouse button to check. + ''' + Public Shared Function IsButtonUp(ByVal Button As MouseButtons) As Boolean + Return Mouse.IsButtonDown(Button) = False + End Function +#End Region + +#Region "PressButton()" + ''' + ''' Simulates a mouse button click. + ''' + ''' The button to press. + ''' + Public Shared Sub PressButton(ByVal Button As MouseButtons) + Mouse.SetButtonState(Button, True) + Mouse.SetButtonState(Button, False) + End Sub +#End Region + +#Region "SetButtonState()" + ''' + ''' Simulates a mouse button being pushed down or released. + ''' + ''' The button which to simulate. + ''' Whether to push down or release the mouse button. + ''' + Public Shared Sub SetButtonState(ByVal Button As MouseButtons, ByVal MouseDown As Boolean) + Dim InputList As NativeMethods.INPUT() = _ + New NativeMethods.INPUT(1 - 1) {Mouse.GetMouseClickInputStructure(Button, MouseDown)} + NativeMethods.SendInput(CType(InputList.Length, UInteger), InputList, Marshal.SizeOf(GetType(NativeMethods.INPUT))) + End Sub +#End Region + +#End Region + +#Region "Internal methods" + +#Region "GetMouseClickInputStructure()" + ''' + ''' Constructs a native mouse INPUT structure for click events that can be passed to SendInput(). + ''' + ''' The button of the event. + ''' Whether to push down or release the mouse button. + ''' + Private Shared Function GetMouseClickInputStructure(ByVal Button As MouseButtons, ByVal MouseDown As Boolean) As NativeMethods.INPUT + Dim Position As Point = Cursor.Position + Dim MouseFlags As NativeMethods.MOUSEEVENTF + Dim MouseData As UInteger = 0 + + Select Case Button + Case MouseButtons.Left : MouseFlags = If(MouseDown, NativeMethods.MOUSEEVENTF.LEFTDOWN, NativeMethods.MOUSEEVENTF.LEFTUP) + Case MouseButtons.Middle : MouseFlags = If(MouseDown, NativeMethods.MOUSEEVENTF.MIDDLEDOWN, NativeMethods.MOUSEEVENTF.MIDDLEUP) + Case MouseButtons.Right : MouseFlags = If(MouseDown, NativeMethods.MOUSEEVENTF.RIGHTDOWN, NativeMethods.MOUSEEVENTF.RIGHTUP) + Case MouseButtons.XButton1 + MouseFlags = If(MouseDown, NativeMethods.MOUSEEVENTF.XDOWN, NativeMethods.MOUSEEVENTF.XUP) + MouseData = NativeMethods.MouseXButton.XBUTTON1 + Case MouseButtons.XButton2 + MouseFlags = If(MouseDown, NativeMethods.MOUSEEVENTF.XDOWN, NativeMethods.MOUSEEVENTF.XUP) + MouseData = NativeMethods.MouseXButton.XBUTTON2 + Case Else + Throw New ArgumentException("Invalid mouse button " & Button.ToString() & "!", "Button") + End Select + + Dim MouseInput As New NativeMethods.MOUSEINPUT With { + .dx = Position.X, + .dy = Position.Y, + .mouseData = MouseData, + .dwFlags = MouseFlags, + .time = 0, + .dwExtraInfo = UIntPtr.Zero + } + + Dim Union As New NativeMethods.INPUTUNION With {.mi = MouseInput} + Dim Input As New NativeMethods.INPUT With { + .type = NativeMethods.INPUTTYPE.MOUSE, + .U = Union + } + + Return Input + End Function +#End Region + +#End Region + End Class \ No newline at end of file diff --git a/InputHelper Library/InputHelper .NET 3.5/Input Handling/WindowMessages.vb b/InputHelper/Input Handling/WindowMessages.vb similarity index 95% rename from InputHelper Library/InputHelper .NET 3.5/Input Handling/WindowMessages.vb rename to InputHelper/Input Handling/WindowMessages.vb index d77767f..00b94ef 100644 --- a/InputHelper Library/InputHelper .NET 3.5/Input Handling/WindowMessages.vb +++ b/InputHelper/Input Handling/WindowMessages.vb @@ -1,679 +1,683 @@ -'+---------------------------------------------------------------------------------+' -'| === InputHelper === |' -'| |' -'| Created by Vincent "Visual Vincent" Bengtsson |' -'| Website: https://www.mydoomsite.com/ |' -'| GitHub: https://github.com/Visual-Vincent |' -'| |' -'| |' -'| === COPYRIGHT LICENSE === |' -'| |' -'| Copyright (c) 2016-2019, Vincent Bengtsson |' -'| All rights reserved. |' -'| |' -'| Redistribution and use in source and binary forms, with or without |' -'| modification, are permitted provided that the following conditions are met: |' -'| |' -'| 1. Redistributions of source code must retain the above copyright notice, this |' -'| list of conditions and the following disclaimer. |' -'| |' -'| 2. Redistributions in binary form must reproduce the above copyright notice, |' -'| this list of conditions and the following disclaimer in the documentation |' -'| and/or other materials provided with the distribution. |' -'| |' -'| 3. Neither the name of the copyright holder nor the names of its |' -'| contributors may be used to endorse or promote products derived from |' -'| this software without specific prior written permission. |' -'| |' -'| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |' -'| AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |' -'| IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |' -'| DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |' -'| FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |' -'| DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |' -'| SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |' -'| CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |' -'| OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |' -'| OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |' -'+---------------------------------------------------------------------------------+' - -Imports System.Drawing -Imports System.Windows.Forms -Imports System.Runtime.InteropServices -Imports System.Text - -''' -''' A static class for handling and simulating input via Window Messages. -''' -''' -Public NotInheritable Class WindowMessages - Private Sub New() - End Sub - -#Region "Fields" - ''' - ''' An array holding all keys' current states (down/up). - ''' - ''' - Private Shared KeyboardState As Byte() = New Byte(256 - 1) {} - - ''' - ''' Indicates whether we are currently in an ALT+numpad combination (ALT code). - ''' - ''' - Private Shared IsAltCodeCombination As Boolean = False - - ''' - ''' A list holding the keys pressed during an ALT+numpad combination. - ''' - ''' - Private Shared AltCode As New List(Of Keys) - - ''' - ''' Whether the current alt code is a Codepage 437 code. - ''' - ''' - Private Shared IsAltCodeCP437 As Boolean = False - - ''' - ''' Lookup table for Codepage 437-to-Unicode character codes. - ''' - ''' - Private Shared ReadOnly CP437LookupTable As Integer() = _ - New Integer(256 - 1) { _ - 0, 9786, 9787, 9829, 9830, 9827, 9824, _ - 8226, 9688, 9675, 9689, 9794, 9792, 9834, 9835, _ - 9788, 9658, 9668, 8597, 8252, 182, 167, 9644, _ - 8616, 8593, 8595, 8594, 8592, 8735, 8596, 9650, _ - 9660, 32, 33, 34, 35, 36, 37, 38, _ - 39, 40, 41, 42, 43, 44, 45, 46, _ - 47, 48, 49, 50, 51, 52, 53, 54, _ - 55, 56, 57, 58, 59, 60, 61, 62, _ - 63, 64, 65, 66, 67, 68, 69, 70, _ - 71, 72, 73, 74, 75, 76, 77, 78, _ - 79, 80, 81, 82, 83, 84, 85, 86, _ - 87, 88, 89, 90, 91, 92, 93, 94, _ - 95, 96, 97, 98, 99, 100, 101, 102, _ - 103, 104, 105, 106, 107, 108, 109, 110, _ - 111, 112, 113, 114, 115, 116, 117, 118, _ - 119, 120, 121, 122, 123, 124, 125, 126, _ - 8962, 199, 252, 233, 226, 228, 224, 229, _ - 231, 234, 235, 232, 239, 238, 236, 196, _ - 197, 201, 230, 198, 244, 246, 242, 251, _ - 249, 255, 214, 220, 162, 163, 165, 8359, _ - 402, 225, 237, 243, 250, 241, 209, 170, _ - 186, 191, 8976, 172, 189, 188, 161, 171, _ - 187, 9617, 9618, 9619, 9474, 9508, 9569, 9570, _ - 9558, 9557, 9571, 9553, 9559, 9565, 9564, 9563, _ - 9488, 9492, 9524, 9516, 9500, 9472, 9532, 9566, _ - 9567, 9562, 9556, 9577, 9574, 9568, 9552, 9580, _ - 9575, 9576, 9572, 9573, 9561, 9560, 9554, 9555, _ - 9579, 9578, 9496, 9484, 9608, 9604, 9612, 9616, _ - 9600, 945, 223, 915, 960, 931, 963, 181, _ - 964, 934, 920, 937, 948, 8734, 966, 949, _ - 8745, 8801, 177, 8805, 8804, 8992, 8993, 247, _ - 8776, 176, 8729, 183, 8730, 8319, 178, 9632, _ - 160 _ - } -#End Region - -#Region "Public methods" - -#Region "Keyboard" - -#Region "IsKeyDown()" - ''' - ''' Checks whether a specific key is down in InputHelper's internal keyboard state (not related to the physical keyboard!). - ''' - ''' The key to check. - ''' - Public Shared Function IsKeyDown(ByVal Key As Keys) As Boolean - If Internal.ExtractModifiers(Key).Length > 0 Then _ - Throw New ArgumentOutOfRangeException("Key", "Keys.Control, Keys.Shift and Keys.Alt is not valid in this context." & Environment.NewLine & _ - "Use Keys.ControlKey, Keys.ShiftKey and Keys.Menu instead.") - Return (WindowMessages.KeyboardState(CType(Key, Integer) And 255) And (1 << 7)) = (1 << 7) - End Function -#End Region - -#Region "IsKeyToggled()" - ''' - ''' Checks whether a specific key is toggled or not in InputHelper's internal keyboard state (not related to the physical keyboard!). - ''' - ''' The key to check (e.g. Keys.CapsLock, Keys.NumLock, etc.). - ''' - Public Shared Function IsKeyToggled(ByVal Key As Keys) As Boolean - If Internal.ExtractModifiers(Key).Length > 0 Then _ - Throw New ArgumentOutOfRangeException("Key", "Keys.Control, Keys.Shift and Keys.Alt is not valid in this context." & Environment.NewLine & _ - "Use Keys.ControlKey, Keys.ShiftKey and Keys.Menu instead.") - Return (WindowMessages.KeyboardState(CType(Key, Integer) And 255) And (1 << 0)) = (1 << 0) - End Function -#End Region - -#Region "IsModifierDown()" - ''' - ''' Checks whether any Left or Right version of a modifier is down in InputHelper's internal keyboard state (not related to the physical keyboard!). - ''' - ''' The modifier to check. - ''' - Public Shared Function IsModifierDown(ByVal Modifier As ModifierKeys) As Boolean - Select Case Modifier - Case ModifierKeys.Control - Return WindowMessages.IsKeyDown(Keys.ControlKey) OrElse _ - WindowMessages.IsKeyDown(Keys.LControlKey) OrElse _ - WindowMessages.IsKeyDown(Keys.RControlKey) - Case ModifierKeys.Shift - Return WindowMessages.IsKeyDown(Keys.ShiftKey) OrElse _ - WindowMessages.IsKeyDown(Keys.LShiftKey) OrElse _ - WindowMessages.IsKeyDown(Keys.RShiftKey) - Case ModifierKeys.Alt - Return WindowMessages.IsKeyDown(Keys.Menu) OrElse _ - WindowMessages.IsKeyDown(Keys.LMenu) OrElse _ - WindowMessages.IsKeyDown(Keys.RMenu) - Case ModifierKeys.Windows - Return WindowMessages.IsKeyDown(Keys.LWin) OrElse _ - WindowMessages.IsKeyDown(Keys.RWin) - End Select - Throw New ArgumentOutOfRangeException("Modifier", CType(Modifier, Integer) & " is not a valid modifier key!") - End Function -#End Region - -#Region "SendAltCode()" - ''' - ''' Sends an ALT code message to the active window. - ''' - ''' The numpad combination to send. - ''' - Public Shared Sub SendAltCode(ByVal NumpadKeys As Keys()) - Dim ActiveWindow As IntPtr = WindowMessages.GetAbsoluteActiveWindow() - WindowMessages.SendAltCode(ActiveWindow, NumpadKeys) - End Sub - - ''' - ''' Sends an ALT code message to a window. - ''' - ''' The handle of the window to send the ALT code message to. - ''' The numpad combination to send. - ''' - Public Shared Sub SendAltCode(ByVal WindowHandle As IntPtr, ByVal NumpadKeys As Keys()) - If NumpadKeys.Any(Function(k As Keys) k < Keys.NumPad0 OrElse k > Keys.NumPad9) = True Then _ - Throw New ArgumentOutOfRangeException("NumpadKeys", "Only Keys.NumPad0 through Keys.NumPad9 are allowed to be passed to this method.") - - Dim LoopTo As Integer = If(NumpadKeys.Length > 4, 4, NumpadKeys.Length) - 1 - - If NumpadKeys(0) = Keys.NumPad0 Then 'Windows-1252 ALT code. - - WindowMessages.SendKey(WindowHandle, Keys.Alt, True) - For x = 0 To LoopTo - WindowMessages.SendKeyPress(WindowHandle, NumpadKeys(x)) - Next - WindowMessages.SendKey(WindowHandle, Keys.Alt, False) - - Else 'Codepage 437 ALT code. - - WindowMessages.SendKey(WindowHandle, Keys.Alt, True) - For x = 0 To LoopTo - WindowMessages.SendKey(WindowHandle, NumpadKeys(x), True) - If x = LoopTo Then - WindowMessages.SendKey(WindowHandle, Keys.Alt, False) 'Release ALT before sending KeyUp of the last key. - End If - WindowMessages.SendKey(WindowHandle, NumpadKeys(x), False) - Next - - End If - End Sub -#End Region - -#Region "SendKey()" - ''' - ''' Sends a KeyDown/KeyUp message to the active window. - ''' - ''' The key to send. - ''' Whether to send a KeyDown or KeyUp message. - ''' Whether to send the hardware scan code along with the virtual key code (recommended to be 'True'!). - ''' Whether or not to wait for the window to handle the message before continuing. - ''' - Public Shared Sub SendKey(ByVal Key As Keys, ByVal KeyDown As Boolean, Optional ByVal HardwareKey As Boolean = True, Optional ByVal SendAsynchronously As Boolean = False) - Dim ActiveWindow As IntPtr = InputHelper.WindowMessages.GetAbsoluteActiveWindow() - WindowMessages.SendKey(ActiveWindow, Key, KeyDown, HardwareKey, SendAsynchronously) - End Sub - - ''' - ''' Sends a KeyDown/KeyUp message to a window. - ''' - ''' The handle of the window to send the key message to. - ''' The key to send. - ''' Whether to send a KeyDown or KeyUp message. - ''' Whether to send the hardware scan code along with the virtual key code (recommended to be 'True'!). - ''' Whether or not to wait for the window to handle the message before continuing. - ''' - Public Shared Sub SendKey(ByVal WindowHandle As IntPtr, ByVal Key As Keys, ByVal KeyDown As Boolean, Optional ByVal HardwareKey As Boolean = True, Optional ByVal SendAsynchronously As Boolean = False) - Dim Modifiers As Keys() = Internal.ExtractModifiers(Key) - - 'Send the modifiers first. - For Each Modifier As Keys In Modifiers - WindowMessages.InternalSendKey(WindowHandle, Modifier, KeyDown, HardwareKey, SendAsynchronously) - Next - - If Key = Keys.None Then Return 'We only sent modifiers. - - WindowMessages.InternalSendKey(WindowHandle, Key, KeyDown, HardwareKey, SendAsynchronously) - End Sub -#End Region - -#Region "SendKeyPress()" - ''' - ''' Sends a keystroke message to the active window. - ''' - ''' The key to send. - ''' Whether to send the hardware scan code along with the virtual key code (recommended to be 'True'!). - ''' Whether or not to wait for the window to handle the message before continuing. - ''' - Public Shared Sub SendKeyPress(ByVal Key As Keys, Optional ByVal HardwareKey As Boolean = True, Optional ByVal SendAsynchronously As Boolean = False) - WindowMessages.SendKey(Key, True, HardwareKey, SendAsynchronously) - WindowMessages.SendKey(Key, False, HardwareKey, SendAsynchronously) - End Sub - - ''' - ''' Sends a keystroke message to a window. - ''' - ''' The handle of the window to send the keystroke message to. - ''' The key to send. - ''' Whether to send the hardware scan code along with the virtual key code (recommended to be 'True'!). - ''' Whether or not to wait for the window to handle the message before continuing. - ''' - Public Shared Sub SendKeyPress(ByVal WindowHandle As IntPtr, ByVal Key As Keys, Optional ByVal HardwareKey As Boolean = True, Optional ByVal SendAsynchronously As Boolean = False) - WindowMessages.SendKey(WindowHandle, Key, True, HardwareKey, SendAsynchronously) - WindowMessages.SendKey(WindowHandle, Key, False, HardwareKey, SendAsynchronously) - End Sub -#End Region - -#Region "ToggleKey()" - ''' - ''' Toggles a specific key in InputHelper's internal keyboard state (not related to the physical keyboard!). Use only with toggleable keys! - ''' - ''' The key to toggle (e.g. Keys.CapsLock, Keys.NumLock, etc.). - ''' Whether to mark the key as toggled or untoggled (Nothing/Null = toggle automatically). - ''' - Public Shared Sub ToggleKey(ByVal Key As Keys, Optional ByVal SetToggled As Nullable(Of Boolean) = Nothing) - Dim Modifiers As Keys() = Internal.ExtractModifiers(Key) - - If SetToggled Is Nothing Then 'Toggle the key. - For Each Modifier As Keys In Modifiers - Dim ModifierIndex As Integer = CType(Modifier, Integer) And 255 'Cap index between 0-255. - WindowMessages.KeyboardState(ModifierIndex) = WindowMessages.KeyboardState(ModifierIndex) Xor (1 << 0) 'Toggle the least significant bit. - Next - - If Key = Keys.None Then Return 'We toggled modifiers only. - - Dim Index As Integer = CType(Key, Integer) And 255 'Cap index between 0-255. - WindowMessages.KeyboardState(Index) = WindowMessages.KeyboardState(Index) Xor (1 << 0) 'Toggle the least significant bit. - - Else 'Set the key to a specific value (toggled/untoggled) - For Each Modifier As Keys In Modifiers - Dim ModifierIndex As Integer = CType(Modifier, Integer) And 255 'Cap index between 0-255. - If SetToggled = True Then - WindowMessages.KeyboardState(ModifierIndex) = WindowMessages.KeyboardState(ModifierIndex) Or (1 << 0) 'Set the least significant bit. - Else - WindowMessages.KeyboardState(ModifierIndex) = WindowMessages.KeyboardState(ModifierIndex) And Not (1 << 0) 'Unset the least significant bit. - End If - Next - - If Key = Keys.None Then Return 'We set modifiers only. - - Dim Index As Integer = CType(Key, Integer) And 255 'Cap index between 0-255. - If SetToggled = True Then - WindowMessages.KeyboardState(Index) = WindowMessages.KeyboardState(Index) Or (1 << 0) 'Set the least significant bit. - Else - WindowMessages.KeyboardState(Index) = WindowMessages.KeyboardState(Index) And Not (1 << 0) 'Unset the least significant bit. - End If - - End If - End Sub -#End Region - -#End Region - -#Region "Mouse" - -#Region "SendMouseClick()" - ''' - ''' Sends a Window Message-based mouse click to the window located at the specified coordinates of the screen. - ''' The coordinates are automatically translated to client coordinates and the click occurs in that specific point of the window. - ''' - ''' The button to press. - ''' The position where to send the click (in screen coordinates). - ''' - Public Shared Sub SendMouseClick(ByVal Button As MouseButtons, ByVal Location As Point) - WindowMessages.SendMouseClick(Button, Location, True, False) - WindowMessages.SendMouseClick(Button, Location, False, False) - End Sub - - ''' - ''' Sends a Window Message-based mouse click to the window located at the specified coordinates of the screen. - ''' The coordinates are automatically translated to client coordinates and the click occurs in that specific point of the window. - ''' - ''' The button to press. - ''' The position where to send the click (in screen coordinates). - ''' Whether to push down or release the mouse button. - ''' Whether or not to wait for the window to handle the message before continuing. - ''' - Public Shared Sub SendMouseClick(ByVal Button As MouseButtons, ByVal Location As Point, ByVal MouseDown As Boolean, Optional ByVal SendAsynchronously As Boolean = False) - Dim hWnd As IntPtr = NativeMethods.WindowFromPoint(New NativeMethods.NATIVEPOINT(Location.X, Location.Y)) 'Get the window at the specified click point. - Dim ButtonMessage As NativeMethods.MouseMessage 'A variable holding which Window Message to use. - - Select Case Button 'Set the appropriate mouse button Window Message. - Case MouseButtons.Left : ButtonMessage = If(MouseDown, NativeMethods.MouseMessage.WM_LBUTTONDOWN, NativeMethods.MouseMessage.WM_LBUTTONUP) - Case MouseButtons.Right : ButtonMessage = If(MouseDown, NativeMethods.MouseMessage.WM_RBUTTONDOWN, NativeMethods.MouseMessage.WM_RBUTTONUP) - Case MouseButtons.Middle : ButtonMessage = If(MouseDown, NativeMethods.MouseMessage.WM_MBUTTONDOWN, NativeMethods.MouseMessage.WM_MBUTTONUP) - Case MouseButtons.XButton1, MouseButtons.XButton2 - ButtonMessage = NativeMethods.MouseMessage.WM_XBUTTONDOWN - Case Else - Throw New ArgumentException("Invalid mouse button " & Button.ToString() & "!", "Button") - End Select - - Dim ClickPoint As New NativeMethods.NATIVEPOINT(Location.X, Location.Y) 'Create a native point. - - If NativeMethods.ScreenToClient(hWnd, ClickPoint) = False Then 'Convert the click point to client coordinates relative to the window. - Throw New Exception("Unable to convert screen coordinates to client coordinates! Win32Err: " & _ - Marshal.GetLastWin32Error()) - End If - - Dim wParam As IntPtr = IntPtr.Zero 'Used to specify which X button was clicked (if any). - Dim lParam As IntPtr = New NativeMethods.DWORD(CType(ClickPoint.x And Short.MaxValue, Short), CType(ClickPoint.y And Short.MaxValue, Short)) 'Click point. - - If Button = MouseButtons.XButton1 OrElse _ - Button = MouseButtons.XButton2 Then - wParam = New NativeMethods.DWORD(0US, CType(Button / MouseButtons.XButton1, UShort)) 'Set the correct XButton. - End If - - InputHelper.WindowMessages.SendMessage(hWnd, ButtonMessage, wParam, lParam, SendAsynchronously) - End Sub -#End Region - -#End Region - -#Region "Miscellaneous" - -#Region "GetActiveWindow()" - ''' - ''' Gets the active top-level window. - ''' - ''' - Public Shared Function GetActiveWindow() As IntPtr - Return NativeMethods.GetForegroundWindow() - End Function -#End Region - -#Region "GetAbsoluteActiveWindow()" - ''' - ''' Gets the (absolute) active top-level window or child window (apart from GetActiveWindow() which will only get the active top-level window). - ''' - ''' - Public Shared Function GetAbsoluteActiveWindow() As IntPtr - Dim CurrentThreadID As UInteger = NativeMethods.GetCurrentThreadId() - Dim ActiveWindow As IntPtr = NativeMethods.GetForegroundWindow() - Dim ActiveThread As UInteger = NativeMethods.GetWindowThreadProcessId(ActiveWindow, Nothing) - - If ActiveThread = 0 Then _ - Return ActiveWindow - - If NativeMethods.AttachThreadInput(CurrentThreadID, ActiveThread, True) = False Then _ - Return ActiveWindow - - Dim AbsoluteActiveWindow As IntPtr = NativeMethods.GetFocus() - Dim DetachAttempts As Integer = 0 - - While NativeMethods.AttachThreadInput(CurrentThreadID, ActiveThread, False) = False - DetachAttempts += 1 - If DetachAttempts >= 10 Then Exit While - Threading.Thread.Sleep(1) - End While - - Return AbsoluteActiveWindow - End Function -#End Region - -#End Region - -#End Region - -#Region "Internal methods" - -#Region "GetKeyWindowMessage()" - ''' - ''' Gets the window message type of the specified key. - ''' - ''' The key to use for the message. - ''' Whether this is a KeyDown or KeyUp message. - ''' - Private Shared Function GetKeyWindowMessage(ByVal Key As Keys, ByVal KeyDown As Boolean) As NativeMethods.KeyMessage - Dim IsAlt As Boolean = ( _ - (Key And Keys.Alt) = Keys.Alt _ - OrElse Key = Keys.Menu _ - OrElse Key = Keys.LMenu _ - OrElse Key = Keys.RMenu _ - ) - - Dim SystemKey As Boolean = ( _ - ( _ - IsAlt _ - OrElse Key = Keys.F10 _ - OrElse WindowMessages.IsKeyDown(Keys.Menu) _ - OrElse WindowMessages.IsKeyDown(Keys.LMenu) _ - OrElse WindowMessages.IsKeyDown(Keys.RMenu) _ - ) _ - AndAlso Not (IsAlt = True AndAlso KeyDown = False) - ) - - If SystemKey = True Then _ - Return If(KeyDown, NativeMethods.KeyMessage.WM_SYSKEYDOWN, NativeMethods.KeyMessage.WM_SYSKEYUP) - - Return If(KeyDown, NativeMethods.KeyMessage.WM_KEYDOWN, NativeMethods.KeyMessage.WM_KEYUP) - End Function -#End Region - -#Region "InternalSendKey()" - ''' - ''' Internal method for sending KeyDown/KeyUp messages to a specific window (DOES NOT HANDLE MODIFIERS! USE 'SendKey()' INSTEAD!). - ''' - ''' The handle to the window to send the keystrokes to. - ''' The key to send. - ''' Whether to send a KeyDown or KeyUp message. - ''' Whether to send the hardware scan code along with the virtual key code (recommended to be 'True'!). - ''' Whether or not to wait for the window to handle the message before continuing. - ''' - Private Shared Sub InternalSendKey(ByVal WindowHandle As IntPtr, ByVal Key As Keys, ByVal KeyDown As Boolean, ByVal HardwareKey As Boolean, ByVal SendAsynchronously As Boolean) - Dim KeyboardLayout As IntPtr = NativeMethods.GetKeyboardLayout(0) - Dim Message As NativeMethods.KeyMessage = WindowMessages.GetKeyWindowMessage(Key, KeyDown) - Dim lParam As IntPtr = WindowMessages.MakeKeyLParam(Key, KeyDown, HardwareKey) - Dim KeyCode As UInteger = CType(Key And UInteger.MaxValue, UInteger) - Dim ScanCode As UInteger = If(HardwareKey, NativeMethods.MapVirtualKeyEx(KeyCode, 0, KeyboardLayout), 0) - - Dim CharBuffer As New StringBuilder(16) - Dim CharCode As UInteger = NativeMethods.MapVirtualKeyEx(KeyCode, 2, KeyboardLayout) - Dim CharacterConversionResult As Integer = -1 - - Dim IsDeadChar As Boolean = (CharCode And (1 << 31)) = (CType(1, UInteger) << 31) 'If the most significant bit is set the key is a dead char. - Dim IsAltDown As Boolean = WindowMessages.IsModifierDown(ModifierKeys.Alt) - Dim IsAlt As Boolean = Internal.IsModifier(Key, ModifierKeys.Alt) - Dim AltUp As Boolean = (IsAlt = True AndAlso IsAltDown = True AndAlso KeyDown = False) - Dim IsNumpadNumber As Boolean = (KeyCode >= CType(Keys.NumPad0, UInteger) AndAlso KeyCode <= CType(Keys.NumPad9, UInteger)) - - 'Is this an ALT+numpad combination? - If WindowMessages.IsAltCodeCombination = False AndAlso IsAltDown = True AndAlso IsNumpadNumber = True Then - WindowMessages.IsAltCodeCombination = True 'Begin an ALT+numpad combination. - End If - - 'Check the key's state. - If KeyDown = True Then - WindowMessages.KeyboardState(CType(Key, Integer)) = (1 << 7) 'Set the most significant bit if the key is down. - Else - WindowMessages.KeyboardState(CType(Key, Integer)) = 0 'Unset value if key is up. - End If - - 'Must be done AFTER the key state has been changed. - If KeyDown = True AndAlso WindowMessages.IsAltCodeCombination = False Then - CharacterConversionResult = _ - NativeMethods.ToUnicodeEx(KeyCode, ScanCode, WindowMessages.KeyboardState, CharBuffer, CharBuffer.Capacity, 0, KeyboardLayout) - End If - - 'Verify conversion result. - If CharacterConversionResult = 0 Then 'Conversion failed. Try MapVirtualKeyEx() instead. - CharBuffer = New StringBuilder(CharBuffer.Capacity) - - Dim MappedCharCode As UInteger = NativeMethods.MapVirtualKeyEx(KeyCode, 2, KeyboardLayout) And Not (1 << 31) - If MappedCharCode <> 0 Then CharBuffer.Append(Convert.ToChar(MappedCharCode)) - - ElseIf CharacterConversionResult > 0 Then 'Conversion succeded. - CharBuffer.Remove(CharacterConversionResult, CharBuffer.Length - CharacterConversionResult) 'Truncate CharBuffer to the amount of chars we want. - - End If - - 'Send the actual key press. - WindowMessages.SendMessage(WindowHandle, Message, New IntPtr(Key), lParam, SendAsynchronously) - - - - 'Is this the end of an ALT+numpad combination? - If KeyDown = False AndAlso IsAlt = True AndAlso WindowMessages.IsAltCodeCombination = True AndAlso AltCode.Count > 0 Then - WindowMessages.IsAltCodeCombination = False 'ALT is being released, end ALT+numpad combination. - - Dim NumberString As String = "" - For x = 0 To WindowMessages.AltCode.Count - 1 - If WindowMessages.AltCode(x) = Keys.NumPad0 AndAlso x = 0 Then Continue For 'Skip the first key if it's a zero. - NumberString &= Convert.ToChar(NativeMethods.MapVirtualKeyEx(WindowMessages.AltCode(x), 2, KeyboardLayout)) 'Convert each key into a digit character. - Next - - Dim AltCodeNumber As Byte = 0 'The ALT code can only range from 0-255. - - If Byte.TryParse(NumberString, AltCodeNumber) = True Then - - If WindowMessages.AltCode(0) = Keys.NumPad0 Then 'Windows-1252 ALT codes start with zero. - Dim DecodedBytes As Byte() = Encoding.Convert(Constants.Windows1252, Encoding.UTF8, New Byte() {AltCodeNumber}) - Dim DecodedChars As Char() = Encoding.UTF8.GetChars(DecodedBytes) - - If DecodedChars.Length >= 1 Then 'Send the resulting char. - WindowMessages.SendMessage(WindowHandle, NativeMethods.KeyMessage.WM_CHAR, New IntPtr(Convert.ToInt32(DecodedChars(0))), lParam, SendAsynchronously) - End If - - Else 'Codepage 437 ALT code. - WindowMessages.SendMessage(WindowHandle, NativeMethods.KeyMessage.WM_CHAR, New IntPtr(WindowMessages.CP437LookupTable(AltCodeNumber)), lParam, SendAsynchronously) - End If - - End If - - AltCode.Clear() 'Clear the combination list. - End If - - - - 'Shall we send a WM_CHAR/WM_DEADCHAR message or is this an ALT+numpad combination? - If KeyDown = True AndAlso WindowMessages.IsAltCodeCombination = False Then - If IsDeadChar = False Then - Dim CharMessage As NativeMethods.KeyMessage = If(IsAltDown, NativeMethods.KeyMessage.WM_SYSCHAR, NativeMethods.KeyMessage.WM_CHAR) - - 'Send WM_CHAR or WM_SYSCHAR. - For Each c As Char In CharBuffer.ToString() - WindowMessages.SendMessage(WindowHandle, CharMessage, New IntPtr(Convert.ToInt32(c)), lParam, SendAsynchronously) - Next - Else - Dim CharMessage As NativeMethods.KeyMessage = If(IsAltDown, NativeMethods.KeyMessage.WM_SYSDEADCHAR, NativeMethods.KeyMessage.WM_DEADCHAR) - - 'Send WM_DEADCHAR or WM_SYSDEADCHAR for dead characters (ex: `, ´, ^, ¨, ~, etc.). - WindowMessages.SendMessage(WindowHandle, NativeMethods.KeyMessage.WM_DEADCHAR, New IntPtr(CharCode And Not (1 << 31)), lParam, SendAsynchronously) - End If - - ElseIf KeyDown = True AndAlso WindowMessages.IsAltCodeCombination = True Then - If IsNumpadNumber = True Then - WindowMessages.AltCode.Add(Key) 'Add numpad number to ALT+numpad combination. - Else - WindowMessages.AltCode.Clear() 'Invalid char, reset combination. - End If - - End If - End Sub -#End Region - -#Region "MakeKeyLParam()" - ''' - ''' Constructs the lParam parameter of a key message. - ''' - ''' The key of the message. - ''' Whether this is a KeyDown or KeyUp message. - ''' Whether to include the key's hardware scan code in the lParam parameter (recommended to be 'True'!). - ''' - Private Shared Function MakeKeyLParam(ByVal Key As Keys, ByVal KeyDown As Boolean, ByVal HardwareKey As Boolean) As IntPtr - Dim ScanCode As UInteger = NativeMethods.MapVirtualKeyEx(CType(Key And UInteger.MaxValue, UInteger), 0, NativeMethods.GetKeyboardLayout(0)) - Dim lParam As Integer = (1 << 0) Or If(HardwareKey, (ScanCode And Integer.MaxValue), 0) << 16 'Set bit 16-23 to the Scan code if HardwareKey = True. - - Dim IsAlt As Boolean = ( _ - (Key And Keys.Alt) = Keys.Alt _ - OrElse Key = Keys.Menu _ - OrElse Key = Keys.LMenu _ - OrElse Key = Keys.RMenu _ - ) - - Dim SystemKey As Boolean = ( _ - ( _ - IsAlt _ - OrElse Key = Keys.F10 _ - OrElse WindowMessages.IsKeyDown(Keys.Menu) _ - OrElse WindowMessages.IsKeyDown(Keys.LMenu) _ - OrElse WindowMessages.IsKeyDown(Keys.RMenu) _ - ) _ - AndAlso Not (IsAlt = True AndAlso KeyDown = False) _ - ) - - Dim IsExtendedKey As Boolean = ( _ - Key = Keys.LControlKey OrElse _ - Key = Keys.RControlKey OrElse _ - Key = Keys.LShiftKey OrElse _ - Key = Keys.RShiftKey OrElse _ - Key = Keys.LMenu OrElse _ - Key = Keys.RMenu _ - ) - - If KeyDown = False Then - 'Set bit 30 and 31 to '1' when sending WM_KEYUP or WM_SYSKEYUP: - 'https://msdn.microsoft.com/en-us/library/windows/desktop/ms646281(v=vs.85).aspx - lParam = (lParam Or (1 << 30)) Or (1 << 31) - End If - - If SystemKey = True Then - 'Set bit 29 to '1', indicates that ALT is held down: - 'https://msdn.microsoft.com/en-us/library/windows/desktop/ms646286(v=vs.85).aspx - lParam = lParam Or (1 << 29) - End If - - If IsExtendedKey = True Then - 'Set bit 24 to '1' if this is an extended key: - 'https://msdn.microsoft.com/en-us/library/windows/desktop/ms646280(v=vs.85).aspx - lParam = lParam Or (1 << 24) - End If - - Return New IntPtr(lParam) - End Function -#End Region - -#Region "SendMessage()" - ''' - ''' Sends or posts a message to a window's message queue. - ''' - ''' The handle of the window to send the message to. - ''' The window message to send. - ''' The wParam of the message. - ''' The lParam of the message. - ''' Whether to post or send the message to the window's message queue. - ''' - Private Shared Sub SendMessage(ByVal hWnd As IntPtr, ByVal Msg As UInteger, ByVal wParam As IntPtr, ByVal lParam As IntPtr, ByVal Asynchronous As Boolean) - If Asynchronous = True Then - NativeMethods.PostMessage(hWnd, Msg, wParam, lParam) - Else - NativeMethods.SendMessage(hWnd, Msg, wParam, lParam) - End If - End Sub -#End Region - -#End Region - +'+---------------------------------------------------------------------------------+' +'| === InputHelper === |' +'| |' +'| Created by Vincent "Visual Vincent" Bengtsson |' +'| Website: https://www.mydoomsite.com/ |' +'| GitHub: https://github.com/Visual-Vincent |' +'| |' +'| |' +'| === COPYRIGHT LICENSE === |' +'| |' +'| Copyright (c) 2016-2022, Vincent Bengtsson |' +'| All rights reserved. |' +'| |' +'| Redistribution and use in source and binary forms, with or without |' +'| modification, are permitted provided that the following conditions are met: |' +'| |' +'| 1. Redistributions of source code must retain the above copyright notice, this |' +'| list of conditions and the following disclaimer. |' +'| |' +'| 2. Redistributions in binary form must reproduce the above copyright notice, |' +'| this list of conditions and the following disclaimer in the documentation |' +'| and/or other materials provided with the distribution. |' +'| |' +'| 3. Neither the name of the copyright holder nor the names of its |' +'| contributors may be used to endorse or promote products derived from |' +'| this software without specific prior written permission. |' +'| |' +'| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |' +'| AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |' +'| IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |' +'| DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |' +'| FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |' +'| DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |' +'| SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |' +'| CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |' +'| OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |' +'| OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |' +'+---------------------------------------------------------------------------------+' + +Imports System.Drawing +Imports System.Windows.Forms +Imports System.Runtime.InteropServices +Imports System.Text + +''' +''' A static class for handling and simulating input via Window Messages. +''' +''' +Public NotInheritable Class WindowMessages + Private Sub New() + End Sub + +#Region "Fields" + ''' + ''' An array holding all keys' current states (down/up). + ''' + ''' + Private Shared KeyboardState As Byte() = New Byte(256 - 1) {} + + ''' + ''' Indicates whether we are currently in an ALT+numpad combination (ALT code). + ''' + ''' + Private Shared IsAltCodeCombination As Boolean = False + + ''' + ''' A list holding the keys pressed during an ALT+numpad combination. + ''' + ''' + Private Shared AltCode As New List(Of Keys) + + ''' + ''' Whether the current alt code is a Codepage 437 code. + ''' + ''' + Private Shared IsAltCodeCP437 As Boolean = False + + ''' + ''' Lookup table for Codepage 437-to-Unicode character codes. + ''' + ''' + Private Shared ReadOnly CP437LookupTable As Integer() = _ + New Integer(256 - 1) { _ + 0, 9786, 9787, 9829, 9830, 9827, 9824, _ + 8226, 9688, 9675, 9689, 9794, 9792, 9834, 9835, _ + 9788, 9658, 9668, 8597, 8252, 182, 167, 9644, _ + 8616, 8593, 8595, 8594, 8592, 8735, 8596, 9650, _ + 9660, 32, 33, 34, 35, 36, 37, 38, _ + 39, 40, 41, 42, 43, 44, 45, 46, _ + 47, 48, 49, 50, 51, 52, 53, 54, _ + 55, 56, 57, 58, 59, 60, 61, 62, _ + 63, 64, 65, 66, 67, 68, 69, 70, _ + 71, 72, 73, 74, 75, 76, 77, 78, _ + 79, 80, 81, 82, 83, 84, 85, 86, _ + 87, 88, 89, 90, 91, 92, 93, 94, _ + 95, 96, 97, 98, 99, 100, 101, 102, _ + 103, 104, 105, 106, 107, 108, 109, 110, _ + 111, 112, 113, 114, 115, 116, 117, 118, _ + 119, 120, 121, 122, 123, 124, 125, 126, _ + 8962, 199, 252, 233, 226, 228, 224, 229, _ + 231, 234, 235, 232, 239, 238, 236, 196, _ + 197, 201, 230, 198, 244, 246, 242, 251, _ + 249, 255, 214, 220, 162, 163, 165, 8359, _ + 402, 225, 237, 243, 250, 241, 209, 170, _ + 186, 191, 8976, 172, 189, 188, 161, 171, _ + 187, 9617, 9618, 9619, 9474, 9508, 9569, 9570, _ + 9558, 9557, 9571, 9553, 9559, 9565, 9564, 9563, _ + 9488, 9492, 9524, 9516, 9500, 9472, 9532, 9566, _ + 9567, 9562, 9556, 9577, 9574, 9568, 9552, 9580, _ + 9575, 9576, 9572, 9573, 9561, 9560, 9554, 9555, _ + 9579, 9578, 9496, 9484, 9608, 9604, 9612, 9616, _ + 9600, 945, 223, 915, 960, 931, 963, 181, _ + 964, 934, 920, 937, 948, 8734, 966, 949, _ + 8745, 8801, 177, 8805, 8804, 8992, 8993, 247, _ + 8776, 176, 8729, 183, 8730, 8319, 178, 9632, _ + 160 _ + } +#End Region + +#Region "Public methods" + +#Region "Keyboard" + +#Region "IsKeyDown()" + ''' + ''' Checks whether a specific key is down in InputHelper's internal keyboard state (not related to the physical keyboard!). + ''' + ''' The key to check. + ''' + Public Shared Function IsKeyDown(ByVal Key As Keys) As Boolean + If Internal.ExtractModifiers(Key).Length > 0 Then _ + Throw New ArgumentOutOfRangeException(NameOf(Key), "Keys.Control, Keys.Shift and Keys.Alt is not valid in this context." & Environment.NewLine & + "Use Keys.ControlKey, Keys.ShiftKey and Keys.Menu instead.") + Return (WindowMessages.KeyboardState(CType(Key, Integer) And 255) And (1 << 7)) = (1 << 7) + End Function +#End Region + +#Region "IsKeyToggled()" + ''' + ''' Checks whether a specific key is toggled or not in InputHelper's internal keyboard state (not related to the physical keyboard!). + ''' + ''' The key to check (e.g. Keys.CapsLock, Keys.NumLock, etc.). + ''' + Public Shared Function IsKeyToggled(ByVal Key As Keys) As Boolean + If Internal.ExtractModifiers(Key).Length > 0 Then _ + Throw New ArgumentOutOfRangeException(NameOf(Key), "Keys.Control, Keys.Shift and Keys.Alt is not valid in this context." & Environment.NewLine & + "Use Keys.ControlKey, Keys.ShiftKey and Keys.Menu instead.") + Return (WindowMessages.KeyboardState(CType(Key, Integer) And 255) And (1 << 0)) = (1 << 0) + End Function +#End Region + +#Region "IsModifierDown()" + ''' + ''' Checks whether any Left or Right version of a modifier is down in InputHelper's internal keyboard state (not related to the physical keyboard!). + ''' + ''' The modifier to check. + ''' + Public Shared Function IsModifierDown(ByVal Modifier As ModifierKeys) As Boolean + Select Case Modifier + Case ModifierKeys.Control + Return WindowMessages.IsKeyDown(Keys.ControlKey) OrElse _ + WindowMessages.IsKeyDown(Keys.LControlKey) OrElse _ + WindowMessages.IsKeyDown(Keys.RControlKey) + Case ModifierKeys.Shift + Return WindowMessages.IsKeyDown(Keys.ShiftKey) OrElse _ + WindowMessages.IsKeyDown(Keys.LShiftKey) OrElse _ + WindowMessages.IsKeyDown(Keys.RShiftKey) + Case ModifierKeys.Alt + Return WindowMessages.IsKeyDown(Keys.Menu) OrElse _ + WindowMessages.IsKeyDown(Keys.LMenu) OrElse _ + WindowMessages.IsKeyDown(Keys.RMenu) + Case ModifierKeys.Windows + Return WindowMessages.IsKeyDown(Keys.LWin) OrElse _ + WindowMessages.IsKeyDown(Keys.RWin) + End Select + Throw New ArgumentOutOfRangeException(NameOf(Modifier), CType(Modifier, Integer) & " is not a valid modifier key!") + End Function +#End Region + +#Region "SendAltCode()" + ''' + ''' Sends an ALT code message to the active window. + ''' + ''' The numpad combination to send. + ''' + Public Shared Sub SendAltCode(ByVal NumpadKeys As Keys()) + Dim ActiveWindow As IntPtr = WindowMessages.GetAbsoluteActiveWindow() + WindowMessages.SendAltCode(ActiveWindow, NumpadKeys) + End Sub + + ''' + ''' Sends an ALT code message to a window. + ''' + ''' The handle of the window to send the ALT code message to. + ''' The numpad combination to send. + ''' + Public Shared Sub SendAltCode(ByVal WindowHandle As IntPtr, ByVal NumpadKeys As Keys()) + If NumpadKeys.Any(Function(k As Keys) k < Keys.NumPad0 OrElse k > Keys.NumPad9) = True Then _ + Throw New ArgumentOutOfRangeException(NameOf(NumpadKeys), "Only Keys.NumPad0 through Keys.NumPad9 are allowed to be passed to this method.") + + Dim LoopTo As Integer = If(NumpadKeys.Length > 4, 4, NumpadKeys.Length) - 1 + + If NumpadKeys(0) = Keys.NumPad0 Then 'Windows-1252 ALT code. + + WindowMessages.SendKey(WindowHandle, Keys.Alt, True) + For x = 0 To LoopTo + WindowMessages.SendKeyPress(WindowHandle, NumpadKeys(x)) + Next + WindowMessages.SendKey(WindowHandle, Keys.Alt, False) + + Else 'Codepage 437 ALT code. + + WindowMessages.SendKey(WindowHandle, Keys.Alt, True) + For x = 0 To LoopTo + WindowMessages.SendKey(WindowHandle, NumpadKeys(x), True) + If x = LoopTo Then + WindowMessages.SendKey(WindowHandle, Keys.Alt, False) 'Release ALT before sending KeyUp of the last key. + End If + WindowMessages.SendKey(WindowHandle, NumpadKeys(x), False) + Next + + End If + End Sub +#End Region + +#Region "SendKey()" + ''' + ''' Sends a KeyDown/KeyUp message to the active window. + ''' + ''' The key to send. + ''' Whether to send a KeyDown or KeyUp message. + ''' Whether to send the hardware scan code along with the virtual key code (recommended to be 'True'!). + ''' Whether or not to wait for the window to handle the message before continuing. + ''' + Public Shared Sub SendKey(ByVal Key As Keys, ByVal KeyDown As Boolean, Optional ByVal HardwareKey As Boolean = True, Optional ByVal SendAsynchronously As Boolean = False) + Dim ActiveWindow As IntPtr = InputHelper.WindowMessages.GetAbsoluteActiveWindow() + WindowMessages.SendKey(ActiveWindow, Key, KeyDown, HardwareKey, SendAsynchronously) + End Sub + + ''' + ''' Sends a KeyDown/KeyUp message to a window. + ''' + ''' The handle of the window to send the key message to. + ''' The key to send. + ''' Whether to send a KeyDown or KeyUp message. + ''' Whether to send the hardware scan code along with the virtual key code (recommended to be 'True'!). + ''' Whether or not to wait for the window to handle the message before continuing. + ''' + Public Shared Sub SendKey(ByVal WindowHandle As IntPtr, ByVal Key As Keys, ByVal KeyDown As Boolean, Optional ByVal HardwareKey As Boolean = True, Optional ByVal SendAsynchronously As Boolean = False) + Dim Modifiers As Keys() = Internal.ExtractModifiers(Key) + + 'Send the modifiers first. + For Each Modifier As Keys In Modifiers + WindowMessages.InternalSendKey(WindowHandle, Modifier, KeyDown, HardwareKey, SendAsynchronously) + Next + + If Key = Keys.None Then Return 'We only sent modifiers. + + WindowMessages.InternalSendKey(WindowHandle, Key, KeyDown, HardwareKey, SendAsynchronously) + End Sub +#End Region + +#Region "SendKeyPress()" + ''' + ''' Sends a keystroke message to the active window. + ''' + ''' The key to send. + ''' Whether to send the hardware scan code along with the virtual key code (recommended to be 'True'!). + ''' Whether or not to wait for the window to handle the message before continuing. + ''' + Public Shared Sub SendKeyPress(ByVal Key As Keys, Optional ByVal HardwareKey As Boolean = True, Optional ByVal SendAsynchronously As Boolean = False) + WindowMessages.SendKey(Key, True, HardwareKey, SendAsynchronously) + WindowMessages.SendKey(Key, False, HardwareKey, SendAsynchronously) + End Sub + + ''' + ''' Sends a keystroke message to a window. + ''' + ''' The handle of the window to send the keystroke message to. + ''' The key to send. + ''' Whether to send the hardware scan code along with the virtual key code (recommended to be 'True'!). + ''' Whether or not to wait for the window to handle the message before continuing. + ''' + Public Shared Sub SendKeyPress(ByVal WindowHandle As IntPtr, ByVal Key As Keys, Optional ByVal HardwareKey As Boolean = True, Optional ByVal SendAsynchronously As Boolean = False) + WindowMessages.SendKey(WindowHandle, Key, True, HardwareKey, SendAsynchronously) + WindowMessages.SendKey(WindowHandle, Key, False, HardwareKey, SendAsynchronously) + End Sub +#End Region + +#Region "ToggleKey()" + ''' + ''' Toggles a specific key in InputHelper's internal keyboard state (not related to the physical keyboard!). Use only with toggleable keys! + ''' + ''' The key to toggle (e.g. Keys.CapsLock, Keys.NumLock, etc.). + ''' Whether to mark the key as toggled or untoggled (Nothing/Null = toggle automatically). + ''' + Public Shared Sub ToggleKey(ByVal Key As Keys, Optional ByVal SetToggled As Nullable(Of Boolean) = Nothing) + Dim Modifiers As Keys() = Internal.ExtractModifiers(Key) + + If SetToggled Is Nothing Then 'Toggle the key. + For Each Modifier As Keys In Modifiers + Dim ModifierIndex As Integer = CType(Modifier, Integer) And 255 'Cap index between 0-255. + WindowMessages.KeyboardState(ModifierIndex) = WindowMessages.KeyboardState(ModifierIndex) Xor (1 << 0) 'Toggle the least significant bit. + Next + + If Key = Keys.None Then Return 'We toggled modifiers only. + + Dim Index As Integer = CType(Key, Integer) And 255 'Cap index between 0-255. + WindowMessages.KeyboardState(Index) = WindowMessages.KeyboardState(Index) Xor (1 << 0) 'Toggle the least significant bit. + + Else 'Set the key to a specific value (toggled/untoggled) + For Each Modifier As Keys In Modifiers + Dim ModifierIndex As Integer = CType(Modifier, Integer) And 255 'Cap index between 0-255. + If SetToggled = True Then + WindowMessages.KeyboardState(ModifierIndex) = WindowMessages.KeyboardState(ModifierIndex) Or (1 << 0) 'Set the least significant bit. + Else + WindowMessages.KeyboardState(ModifierIndex) = WindowMessages.KeyboardState(ModifierIndex) And Not (1 << 0) 'Unset the least significant bit. + End If + Next + + If Key = Keys.None Then Return 'We set modifiers only. + + Dim Index As Integer = CType(Key, Integer) And 255 'Cap index between 0-255. + If SetToggled = True Then + WindowMessages.KeyboardState(Index) = WindowMessages.KeyboardState(Index) Or (1 << 0) 'Set the least significant bit. + Else + WindowMessages.KeyboardState(Index) = WindowMessages.KeyboardState(Index) And Not (1 << 0) 'Unset the least significant bit. + End If + + End If + End Sub +#End Region + +#End Region + +#Region "Mouse" + +#Region "SendMouseClick()" + ''' + ''' Sends a Window Message-based mouse click to the window located at the specified coordinates of the screen. + ''' The coordinates are automatically translated to client coordinates and the click occurs in that specific point of the window. + ''' + ''' The button to press. + ''' The position where to send the click (in screen coordinates). + ''' + Public Shared Sub SendMouseClick(ByVal Button As MouseButtons, ByVal Location As Point) + WindowMessages.SendMouseClick(Button, Location, True, False) + WindowMessages.SendMouseClick(Button, Location, False, False) + End Sub + + ''' + ''' Sends a Window Message-based mouse click to the window located at the specified coordinates of the screen. + ''' The coordinates are automatically translated to client coordinates and the click occurs in that specific point of the window. + ''' + ''' The button to press. + ''' The position where to send the click (in screen coordinates). + ''' Whether to push down or release the mouse button. + ''' Whether or not to wait for the window to handle the message before continuing. + ''' + Public Shared Sub SendMouseClick(ByVal Button As MouseButtons, ByVal Location As Point, ByVal MouseDown As Boolean, Optional ByVal SendAsynchronously As Boolean = False) + Dim hWnd As IntPtr = NativeMethods.WindowFromPoint(New NativeMethods.NATIVEPOINT(Location.X, Location.Y)) 'Get the window at the specified click point. + Dim ButtonMessage As NativeMethods.MouseMessage 'A variable holding which Window Message to use. + + Select Case Button 'Set the appropriate mouse button Window Message. + Case MouseButtons.Left : ButtonMessage = If(MouseDown, NativeMethods.MouseMessage.WM_LBUTTONDOWN, NativeMethods.MouseMessage.WM_LBUTTONUP) + Case MouseButtons.Right : ButtonMessage = If(MouseDown, NativeMethods.MouseMessage.WM_RBUTTONDOWN, NativeMethods.MouseMessage.WM_RBUTTONUP) + Case MouseButtons.Middle : ButtonMessage = If(MouseDown, NativeMethods.MouseMessage.WM_MBUTTONDOWN, NativeMethods.MouseMessage.WM_MBUTTONUP) + Case MouseButtons.XButton1, MouseButtons.XButton2 + ButtonMessage = NativeMethods.MouseMessage.WM_XBUTTONDOWN + Case Else + Throw New ArgumentException("Invalid mouse button " & Button.ToString() & "!", NameOf(Button)) + End Select + + Dim ClickPoint As New NativeMethods.NATIVEPOINT(Location.X, Location.Y) 'Create a native point. + + If NativeMethods.ScreenToClient(hWnd, ClickPoint) = False Then 'Convert the click point to client coordinates relative to the window. + Throw New Exception("Unable to convert screen coordinates to client coordinates! Win32Err: " & _ + Marshal.GetLastWin32Error()) + End If + + Dim wParam As IntPtr = IntPtr.Zero 'Used to specify which X button was clicked (if any). + Dim lParam As IntPtr = New NativeMethods.DWORD(CType(ClickPoint.x And Short.MaxValue, Short), CType(ClickPoint.y And Short.MaxValue, Short)) 'Click point. + + If Button = MouseButtons.XButton1 OrElse _ + Button = MouseButtons.XButton2 Then + wParam = New NativeMethods.DWORD(0US, CType(Button / MouseButtons.XButton1, UShort)) 'Set the correct XButton. + End If + + InputHelper.WindowMessages.SendMessage(hWnd, ButtonMessage, wParam, lParam, SendAsynchronously) + End Sub +#End Region + +#End Region + +#Region "Miscellaneous" + +#Region "GetActiveWindow()" + ''' + ''' Gets the active top-level window. + ''' + ''' + Public Shared Function GetActiveWindow() As IntPtr + Return NativeMethods.GetForegroundWindow() + End Function +#End Region + +#Region "GetAbsoluteActiveWindow()" + ''' + ''' Gets the (absolute) active top-level window or child window (apart from GetActiveWindow() which will only get the active top-level window). + ''' + ''' + Public Shared Function GetAbsoluteActiveWindow() As IntPtr + Dim CurrentThreadID As UInteger = NativeMethods.GetCurrentThreadId() + Dim ActiveWindow As IntPtr = NativeMethods.GetForegroundWindow() + Dim ActiveThread As UInteger = NativeMethods.GetWindowThreadProcessId(ActiveWindow, Nothing) + + If ActiveThread = 0 Then _ + Return ActiveWindow + + If NativeMethods.AttachThreadInput(CurrentThreadID, ActiveThread, True) = False Then _ + Return ActiveWindow + + Dim AbsoluteActiveWindow As IntPtr = NativeMethods.GetFocus() + Dim DetachAttempts As Integer = 0 + + While NativeMethods.AttachThreadInput(CurrentThreadID, ActiveThread, False) = False + DetachAttempts += 1 + If DetachAttempts >= 10 Then Exit While + Threading.Thread.Sleep(1) + End While + + Return AbsoluteActiveWindow + End Function +#End Region + +#End Region + +#End Region + +#Region "Internal methods" + +#Region "GetKeyWindowMessage()" + ''' + ''' Gets the window message type of the specified key. + ''' + ''' The key to use for the message. + ''' Whether this is a KeyDown or KeyUp message. + ''' + Private Shared Function GetKeyWindowMessage(ByVal Key As Keys, ByVal KeyDown As Boolean) As NativeMethods.KeyMessage + Dim IsAlt As Boolean = ( _ + (Key And Keys.Alt) = Keys.Alt _ + OrElse Key = Keys.Menu _ + OrElse Key = Keys.LMenu _ + OrElse Key = Keys.RMenu _ + ) + + Dim SystemKey As Boolean = ( _ + ( _ + IsAlt _ + OrElse Key = Keys.F10 _ + OrElse WindowMessages.IsKeyDown(Keys.Menu) _ + OrElse WindowMessages.IsKeyDown(Keys.LMenu) _ + OrElse WindowMessages.IsKeyDown(Keys.RMenu) _ + ) _ + AndAlso Not (IsAlt = True AndAlso KeyDown = False) + ) + + If SystemKey = True Then _ + Return If(KeyDown, NativeMethods.KeyMessage.WM_SYSKEYDOWN, NativeMethods.KeyMessage.WM_SYSKEYUP) + + Return If(KeyDown, NativeMethods.KeyMessage.WM_KEYDOWN, NativeMethods.KeyMessage.WM_KEYUP) + End Function +#End Region + +#Region "InternalSendKey()" + ''' + ''' Internal method for sending KeyDown/KeyUp messages to a specific window (DOES NOT HANDLE MODIFIERS! USE 'SendKey()' INSTEAD!). + ''' + ''' The handle to the window to send the keystrokes to. + ''' The key to send. + ''' Whether to send a KeyDown or KeyUp message. + ''' Whether to send the hardware scan code along with the virtual key code (recommended to be 'True'!). + ''' Whether or not to wait for the window to handle the message before continuing. + ''' + Private Shared Sub InternalSendKey(ByVal WindowHandle As IntPtr, ByVal Key As Keys, ByVal KeyDown As Boolean, ByVal HardwareKey As Boolean, ByVal SendAsynchronously As Boolean) + Dim KeyboardLayout As IntPtr = NativeMethods.GetKeyboardLayout(0) + Dim Message As NativeMethods.KeyMessage = WindowMessages.GetKeyWindowMessage(Key, KeyDown) + Dim lParam As IntPtr = WindowMessages.MakeKeyLParam(Key, KeyDown, HardwareKey) + Dim KeyCode As UInteger = CType(Key And UInteger.MaxValue, UInteger) + Dim ScanCode As UInteger = If(HardwareKey, NativeMethods.MapVirtualKeyEx(KeyCode, 0, KeyboardLayout), 0) + + Dim CharBuffer As New StringBuilder(16) + Dim CharCode As UInteger = NativeMethods.MapVirtualKeyEx(KeyCode, 2, KeyboardLayout) + Dim CharacterConversionResult As Integer = -1 + + Dim IsDeadChar As Boolean = (CharCode And (1 << 31)) = (CType(1, UInteger) << 31) 'If the most significant bit is set the key is a dead char. + Dim IsAltDown As Boolean = WindowMessages.IsModifierDown(ModifierKeys.Alt) + Dim IsAlt As Boolean = Internal.IsModifier(Key, ModifierKeys.Alt) + Dim AltUp As Boolean = (IsAlt = True AndAlso IsAltDown = True AndAlso KeyDown = False) + Dim IsNumpadNumber As Boolean = (KeyCode >= CType(Keys.NumPad0, UInteger) AndAlso KeyCode <= CType(Keys.NumPad9, UInteger)) + + 'Is this an ALT+numpad combination? + If WindowMessages.IsAltCodeCombination = False AndAlso IsAltDown = True AndAlso IsNumpadNumber = True Then + WindowMessages.IsAltCodeCombination = True 'Begin an ALT+numpad combination. + End If + + 'Check the key's state. + If KeyDown = True Then + WindowMessages.KeyboardState(CType(Key, Integer)) = (1 << 7) 'Set the most significant bit if the key is down. + Else + WindowMessages.KeyboardState(CType(Key, Integer)) = 0 'Unset value if key is up. + End If + + 'Must be done AFTER the key state has been changed. + If KeyDown = True AndAlso WindowMessages.IsAltCodeCombination = False Then + CharacterConversionResult = _ + NativeMethods.ToUnicodeEx(KeyCode, ScanCode, WindowMessages.KeyboardState, CharBuffer, CharBuffer.Capacity, 0, KeyboardLayout) + End If + + 'Verify conversion result. + If CharacterConversionResult = 0 Then 'Conversion failed. Try MapVirtualKeyEx() instead. +#If NET35 Then + CharBuffer = New StringBuilder(CharBuffer.Capacity) +#Else + CharBuffer.Clear() +#End If + + Dim MappedCharCode As UInteger = NativeMethods.MapVirtualKeyEx(KeyCode, 2, KeyboardLayout) And Not (1 << 31) + If MappedCharCode <> 0 Then CharBuffer.Append(Convert.ToChar(MappedCharCode)) + + ElseIf CharacterConversionResult > 0 Then 'Conversion succeded. + CharBuffer.Remove(CharacterConversionResult, CharBuffer.Length - CharacterConversionResult) 'Truncate CharBuffer to the amount of chars we want. + + End If + + 'Send the actual key press. + WindowMessages.SendMessage(WindowHandle, Message, New IntPtr(Key), lParam, SendAsynchronously) + + + + 'Is this the end of an ALT+numpad combination? + If KeyDown = False AndAlso IsAlt = True AndAlso WindowMessages.IsAltCodeCombination = True AndAlso AltCode.Count > 0 Then + WindowMessages.IsAltCodeCombination = False 'ALT is being released, end ALT+numpad combination. + + Dim NumberString As String = "" + For x = 0 To WindowMessages.AltCode.Count - 1 + If WindowMessages.AltCode(x) = Keys.NumPad0 AndAlso x = 0 Then Continue For 'Skip the first key if it's a zero. + NumberString &= Convert.ToChar(NativeMethods.MapVirtualKeyEx(WindowMessages.AltCode(x), 2, KeyboardLayout)) 'Convert each key into a digit character. + Next + + Dim AltCodeNumber As Byte = 0 'The ALT code can only range from 0-255. + + If Byte.TryParse(NumberString, AltCodeNumber) = True Then + + If WindowMessages.AltCode(0) = Keys.NumPad0 Then 'Windows-1252 ALT codes start with zero. + Dim DecodedBytes As Byte() = Encoding.Convert(Constants.Windows1252, Encoding.UTF8, New Byte() {AltCodeNumber}) + Dim DecodedChars As Char() = Encoding.UTF8.GetChars(DecodedBytes) + + If DecodedChars.Length >= 1 Then 'Send the resulting char. + WindowMessages.SendMessage(WindowHandle, NativeMethods.KeyMessage.WM_CHAR, New IntPtr(Convert.ToInt32(DecodedChars(0))), lParam, SendAsynchronously) + End If + + Else 'Codepage 437 ALT code. + WindowMessages.SendMessage(WindowHandle, NativeMethods.KeyMessage.WM_CHAR, New IntPtr(WindowMessages.CP437LookupTable(AltCodeNumber)), lParam, SendAsynchronously) + End If + + End If + + AltCode.Clear() 'Clear the combination list. + End If + + + + 'Shall we send a WM_CHAR/WM_DEADCHAR message or is this an ALT+numpad combination? + If KeyDown = True AndAlso WindowMessages.IsAltCodeCombination = False Then + If IsDeadChar = False Then + Dim CharMessage As NativeMethods.KeyMessage = If(IsAltDown, NativeMethods.KeyMessage.WM_SYSCHAR, NativeMethods.KeyMessage.WM_CHAR) + + 'Send WM_CHAR or WM_SYSCHAR. + For Each c As Char In CharBuffer.ToString() + WindowMessages.SendMessage(WindowHandle, CharMessage, New IntPtr(Convert.ToInt32(c)), lParam, SendAsynchronously) + Next + Else + Dim CharMessage As NativeMethods.KeyMessage = If(IsAltDown, NativeMethods.KeyMessage.WM_SYSDEADCHAR, NativeMethods.KeyMessage.WM_DEADCHAR) + + 'Send WM_DEADCHAR or WM_SYSDEADCHAR for dead characters (ex: `, ´, ^, ¨, ~, etc.). + WindowMessages.SendMessage(WindowHandle, NativeMethods.KeyMessage.WM_DEADCHAR, New IntPtr(CharCode And Not (1 << 31)), lParam, SendAsynchronously) + End If + + ElseIf KeyDown = True AndAlso WindowMessages.IsAltCodeCombination = True Then + If IsNumpadNumber = True Then + WindowMessages.AltCode.Add(Key) 'Add numpad number to ALT+numpad combination. + Else + WindowMessages.AltCode.Clear() 'Invalid char, reset combination. + End If + + End If + End Sub +#End Region + +#Region "MakeKeyLParam()" + ''' + ''' Constructs the lParam parameter of a key message. + ''' + ''' The key of the message. + ''' Whether this is a KeyDown or KeyUp message. + ''' Whether to include the key's hardware scan code in the lParam parameter (recommended to be 'True'!). + ''' + Private Shared Function MakeKeyLParam(ByVal Key As Keys, ByVal KeyDown As Boolean, ByVal HardwareKey As Boolean) As IntPtr + Dim ScanCode As UInteger = NativeMethods.MapVirtualKeyEx(CType(Key And UInteger.MaxValue, UInteger), 0, NativeMethods.GetKeyboardLayout(0)) + Dim lParam As Integer = (1 << 0) Or If(HardwareKey, (ScanCode And Integer.MaxValue), 0) << 16 'Set bit 16-23 to the Scan code if HardwareKey = True. + + Dim IsAlt As Boolean = ( _ + (Key And Keys.Alt) = Keys.Alt _ + OrElse Key = Keys.Menu _ + OrElse Key = Keys.LMenu _ + OrElse Key = Keys.RMenu _ + ) + + Dim SystemKey As Boolean = ( _ + ( _ + IsAlt _ + OrElse Key = Keys.F10 _ + OrElse WindowMessages.IsKeyDown(Keys.Menu) _ + OrElse WindowMessages.IsKeyDown(Keys.LMenu) _ + OrElse WindowMessages.IsKeyDown(Keys.RMenu) _ + ) _ + AndAlso Not (IsAlt = True AndAlso KeyDown = False) _ + ) + + Dim IsExtendedKey As Boolean = ( _ + Key = Keys.LControlKey OrElse _ + Key = Keys.RControlKey OrElse _ + Key = Keys.LShiftKey OrElse _ + Key = Keys.RShiftKey OrElse _ + Key = Keys.LMenu OrElse _ + Key = Keys.RMenu _ + ) + + If KeyDown = False Then + 'Set bit 30 and 31 to '1' when sending WM_KEYUP or WM_SYSKEYUP: + 'https://msdn.microsoft.com/en-us/library/windows/desktop/ms646281(v=vs.85).aspx + lParam = (lParam Or (1 << 30)) Or (1 << 31) + End If + + If SystemKey = True Then + 'Set bit 29 to '1', indicates that ALT is held down: + 'https://msdn.microsoft.com/en-us/library/windows/desktop/ms646286(v=vs.85).aspx + lParam = lParam Or (1 << 29) + End If + + If IsExtendedKey = True Then + 'Set bit 24 to '1' if this is an extended key: + 'https://msdn.microsoft.com/en-us/library/windows/desktop/ms646280(v=vs.85).aspx + lParam = lParam Or (1 << 24) + End If + + Return New IntPtr(lParam) + End Function +#End Region + +#Region "SendMessage()" + ''' + ''' Sends or posts a message to a window's message queue. + ''' + ''' The handle of the window to send the message to. + ''' The window message to send. + ''' The wParam of the message. + ''' The lParam of the message. + ''' Whether to post or send the message to the window's message queue. + ''' + Private Shared Sub SendMessage(ByVal hWnd As IntPtr, ByVal Msg As UInteger, ByVal wParam As IntPtr, ByVal lParam As IntPtr, ByVal Asynchronous As Boolean) + If Asynchronous = True Then + NativeMethods.PostMessage(hWnd, Msg, wParam, lParam) + Else + NativeMethods.SendMessage(hWnd, Msg, wParam, lParam) + End If + End Sub +#End Region + +#End Region + End Class \ No newline at end of file diff --git a/InputHelper/InputHelper.vbproj b/InputHelper/InputHelper.vbproj new file mode 100644 index 0000000..42fc6bb --- /dev/null +++ b/InputHelper/InputHelper.vbproj @@ -0,0 +1,17 @@ + + + + InputHelper + net35;net40;netcoreapp3.1-windows;net5.0-windows;net6.0-windows + false + true + true + InputHelper.pfx + true + + + + + + + diff --git a/InputHelper Library/InputHelper .NET 4.x/Internal.vb b/InputHelper/Internal.vb similarity index 97% rename from InputHelper Library/InputHelper .NET 4.x/Internal.vb rename to InputHelper/Internal.vb index 57d0df7..3685c11 100644 --- a/InputHelper Library/InputHelper .NET 4.x/Internal.vb +++ b/InputHelper/Internal.vb @@ -1,112 +1,112 @@ -'+---------------------------------------------------------------------------------+' -'| === InputHelper === |' -'| |' -'| Created by Vincent "Visual Vincent" Bengtsson |' -'| Website: https://www.mydoomsite.com/ |' -'| GitHub: https://github.com/Visual-Vincent |' -'| |' -'| |' -'| === COPYRIGHT LICENSE === |' -'| |' -'| Copyright (c) 2016-2019, Vincent Bengtsson |' -'| All rights reserved. |' -'| |' -'| Redistribution and use in source and binary forms, with or without |' -'| modification, are permitted provided that the following conditions are met: |' -'| |' -'| 1. Redistributions of source code must retain the above copyright notice, this |' -'| list of conditions and the following disclaimer. |' -'| |' -'| 2. Redistributions in binary form must reproduce the above copyright notice, |' -'| this list of conditions and the following disclaimer in the documentation |' -'| and/or other materials provided with the distribution. |' -'| |' -'| 3. Neither the name of the copyright holder nor the names of its |' -'| contributors may be used to endorse or promote products derived from |' -'| this software without specific prior written permission. |' -'| |' -'| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |' -'| AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |' -'| IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |' -'| DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |' -'| FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |' -'| DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |' -'| SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |' -'| CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |' -'| OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |' -'| OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |' -'+---------------------------------------------------------------------------------+' - -Imports System.Windows.Forms - -''' -''' A class holding internal methods and fields related to InputHelper. -''' -''' -Friend Class Internal - -#Region "ExtractModifiers()" - ''' - ''' Extracts any .NET modifiers from the specified key combination and returns them as native virtual key code keys. - ''' - ''' The key combination to extract the modifiers from (if any). - ''' - Public Shared Function ExtractModifiers(ByRef Key As Keys) As Keys() - Dim Modifiers As New List(Of Keys) - - If (Key And Keys.Control) = Keys.Control Then - Key = Key And Not Keys.Control - Modifiers.Add(Keys.ControlKey) - End If - - If (Key And Keys.Shift) = Keys.Shift Then - Key = Key And Not Keys.Shift - Modifiers.Add(Keys.ShiftKey) - End If - - If (Key And Keys.Alt) = Keys.Alt Then - Key = Key And Not Keys.Alt - Modifiers.Add(Keys.Menu) - End If - - Return Modifiers.ToArray() - End Function -#End Region - -#Region "IsModifier()" - ''' - ''' Checks whether the specified key is any Left or Right version of the specified modifier. - ''' - ''' The key to check. - ''' The modifier to check for. - ''' - Public Shared Function IsModifier(ByVal Key As Keys, ByVal Modifier As ModifierKeys) As Boolean - Select Case Modifier - Case ModifierKeys.Control - Return _ - Key = Keys.Control OrElse _ - Key = Keys.ControlKey OrElse _ - Key = Keys.LControlKey OrElse _ - Key = Keys.RControlKey - Case ModifierKeys.Shift - Return _ - Key = Keys.Shift OrElse _ - Key = Keys.ShiftKey OrElse _ - Key = Keys.LShiftKey OrElse _ - Key = Keys.RShiftKey - Case ModifierKeys.Alt - Return _ - Key = Keys.Alt OrElse _ - Key = Keys.Menu OrElse _ - Key = Keys.LMenu OrElse _ - Key = Keys.RMenu - Case ModifierKeys.Windows - Return _ - Key = Keys.LWin OrElse _ - Key = Keys.RWin - End Select - Throw New ArgumentOutOfRangeException("Modifier", CType(Modifier, Integer) & " is not a valid modifier key!") - End Function -#End Region - -End Class +'+---------------------------------------------------------------------------------+' +'| === InputHelper === |' +'| |' +'| Created by Vincent "Visual Vincent" Bengtsson |' +'| Website: https://www.mydoomsite.com/ |' +'| GitHub: https://github.com/Visual-Vincent |' +'| |' +'| |' +'| === COPYRIGHT LICENSE === |' +'| |' +'| Copyright (c) 2016-2022, Vincent Bengtsson |' +'| All rights reserved. |' +'| |' +'| Redistribution and use in source and binary forms, with or without |' +'| modification, are permitted provided that the following conditions are met: |' +'| |' +'| 1. Redistributions of source code must retain the above copyright notice, this |' +'| list of conditions and the following disclaimer. |' +'| |' +'| 2. Redistributions in binary form must reproduce the above copyright notice, |' +'| this list of conditions and the following disclaimer in the documentation |' +'| and/or other materials provided with the distribution. |' +'| |' +'| 3. Neither the name of the copyright holder nor the names of its |' +'| contributors may be used to endorse or promote products derived from |' +'| this software without specific prior written permission. |' +'| |' +'| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |' +'| AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |' +'| IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |' +'| DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |' +'| FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |' +'| DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |' +'| SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |' +'| CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |' +'| OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |' +'| OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |' +'+---------------------------------------------------------------------------------+' + +Imports System.Windows.Forms + +''' +''' A class holding internal methods and fields related to InputHelper. +''' +''' +Friend Class Internal + +#Region "ExtractModifiers()" + ''' + ''' Extracts any .NET modifiers from the specified key combination and returns them as native virtual key code keys. + ''' + ''' The key combination to extract the modifiers from (if any). + ''' + Public Shared Function ExtractModifiers(ByRef Key As Keys) As Keys() + Dim Modifiers As New List(Of Keys) + + If (Key And Keys.Control) = Keys.Control Then + Key = Key And Not Keys.Control + Modifiers.Add(Keys.ControlKey) + End If + + If (Key And Keys.Shift) = Keys.Shift Then + Key = Key And Not Keys.Shift + Modifiers.Add(Keys.ShiftKey) + End If + + If (Key And Keys.Alt) = Keys.Alt Then + Key = Key And Not Keys.Alt + Modifiers.Add(Keys.Menu) + End If + + Return Modifiers.ToArray() + End Function +#End Region + +#Region "IsModifier()" + ''' + ''' Checks whether the specified key is any Left or Right version of the specified modifier. + ''' + ''' The key to check. + ''' The modifier to check for. + ''' + Public Shared Function IsModifier(ByVal Key As Keys, ByVal Modifier As ModifierKeys) As Boolean + Select Case Modifier + Case ModifierKeys.Control + Return _ + Key = Keys.Control OrElse _ + Key = Keys.ControlKey OrElse _ + Key = Keys.LControlKey OrElse _ + Key = Keys.RControlKey + Case ModifierKeys.Shift + Return _ + Key = Keys.Shift OrElse _ + Key = Keys.ShiftKey OrElse _ + Key = Keys.LShiftKey OrElse _ + Key = Keys.RShiftKey + Case ModifierKeys.Alt + Return _ + Key = Keys.Alt OrElse _ + Key = Keys.Menu OrElse _ + Key = Keys.LMenu OrElse _ + Key = Keys.RMenu + Case ModifierKeys.Windows + Return _ + Key = Keys.LWin OrElse _ + Key = Keys.RWin + End Select + Throw New ArgumentOutOfRangeException("Modifier", CType(Modifier, Integer) & " is not a valid modifier key!") + End Function +#End Region + +End Class diff --git a/InputHelper Library/InputHelper .NET 4.x/NativeMethods.vb b/InputHelper/NativeMethods.vb similarity index 97% rename from InputHelper Library/InputHelper .NET 4.x/NativeMethods.vb rename to InputHelper/NativeMethods.vb index 31782d4..b396a05 100644 --- a/InputHelper Library/InputHelper .NET 4.x/NativeMethods.vb +++ b/InputHelper/NativeMethods.vb @@ -1,508 +1,508 @@ -'+---------------------------------------------------------------------------------+' -'| === InputHelper === |' -'| |' -'| Created by Vincent "Visual Vincent" Bengtsson |' -'| Website: https://www.mydoomsite.com/ |' -'| GitHub: https://github.com/Visual-Vincent |' -'| |' -'| |' -'| === COPYRIGHT LICENSE === |' -'| |' -'| Copyright (c) 2016-2019, Vincent Bengtsson |' -'| All rights reserved. |' -'| |' -'| Redistribution and use in source and binary forms, with or without |' -'| modification, are permitted provided that the following conditions are met: |' -'| |' -'| 1. Redistributions of source code must retain the above copyright notice, this |' -'| list of conditions and the following disclaimer. |' -'| |' -'| 2. Redistributions in binary form must reproduce the above copyright notice, |' -'| this list of conditions and the following disclaimer in the documentation |' -'| and/or other materials provided with the distribution. |' -'| |' -'| 3. Neither the name of the copyright holder nor the names of its |' -'| contributors may be used to endorse or promote products derived from |' -'| this software without specific prior written permission. |' -'| |' -'| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |' -'| AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |' -'| IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |' -'| DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |' -'| FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |' -'| DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |' -'| SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |' -'| CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |' -'| OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |' -'| OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |' -'+---------------------------------------------------------------------------------+' - -Imports System.Windows.Forms -Imports System.Runtime.InteropServices -Imports System.Text - -''' -''' A class containing all the native WinAPI methods, structures, declarations, etc. used by InputHelper. -''' -''' -Public NotInheritable Class NativeMethods - Private Sub New() - End Sub - -#Region "Delegates" - Public Delegate Function KeyboardProc(ByVal nCode As Integer, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr - Public Delegate Function LowLevelKeyboardProc(ByVal nCode As Integer, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr - Public Delegate Function LowLevelMouseProc(ByVal nCode As Integer, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr -#End Region - -#Region "Methods" - -#Region "Hook methods" - _ - Public Shared Function SetWindowsHookEx(ByVal idHook As HookType, ByVal lpfn As KeyboardProc, ByVal hMod As IntPtr, ByVal dwThreadId As UInteger) As IntPtr - End Function - - _ - Public Shared Function SetWindowsHookEx(ByVal idHook As HookType, ByVal lpfn As LowLevelKeyboardProc, ByVal hMod As IntPtr, ByVal dwThreadId As UInteger) As IntPtr - End Function - - _ - Public Shared Function SetWindowsHookEx(ByVal idHook As HookType, ByVal lpfn As LowLevelMouseProc, ByVal hMod As IntPtr, ByVal dwThreadId As UInteger) As IntPtr - End Function - - _ - Public Shared Function UnhookWindowsHookEx(ByVal hhk As IntPtr) As Boolean - End Function - - _ - Public Shared Function CallNextHookEx(ByVal hhk As IntPtr, ByVal nCode As Integer, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr - End Function -#End Region - -#Region "Input methods" - - Public Shared Function SendInput(ByVal nInputs As UInteger, ByVal pInputs() As INPUT, ByVal cbSize As Integer) As UInteger - End Function - - _ - Public Shared Function MapVirtualKeyEx(uCode As UInteger, uMapType As UInteger, dwhkl As IntPtr) As UInteger - End Function - - _ - Public Shared Function GetKeyboardLayout(idThread As UInteger) As IntPtr - End Function - - _ - Public Shared Function GetKeyboardState( ByVal lpKeyState As Byte()) As Boolean - End Function - - _ - Public Shared Function GetAsyncKeyState(ByVal vKey As Keys) As Short - End Function - - _ - Public Shared Function ToUnicodeEx(ByVal wVirtKey As UInteger, ByVal wScanCode As UInteger, ByVal lpKeyState As Byte(), ByVal pwszBuff As StringBuilder, ByVal cchBuff As Integer, ByVal wFlags As UInteger, ByVal dwhkl As IntPtr) As Integer - End Function -#End Region - -#Region "Window and thread methods" - 'CharSet.Unicode is required for CP437 ALT codes to work! - _ - Public Shared Function SendMessage(ByVal hWnd As IntPtr, ByVal Msg As UInteger, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr - End Function - - _ - Public Shared Function PostMessage(ByVal hWnd As IntPtr, ByVal Msg As UInteger, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As Boolean - End Function - - _ - Public Shared Function GetForegroundWindow() As IntPtr - End Function - - _ - Public Shared Function GetFocus() As IntPtr - End Function - - _ - Public Shared Function AttachThreadInput(ByVal idAttach As UInteger, ByVal idAttachTo As UInteger, fAttach As Boolean) As Boolean - End Function - - _ - Public Shared Function GetCurrentThreadId() As UInteger - End Function - - _ - Public Shared Function GetWindowThreadProcessId(ByVal hWnd As IntPtr, lpdwProcessId As UIntPtr) As UInteger - End Function - - _ - Public Shared Function WindowFromPoint(ByVal p As NATIVEPOINT) As IntPtr - End Function - - _ - Public Shared Function ScreenToClient(ByVal hWnd As IntPtr, ByRef lpPoint As NATIVEPOINT) As Boolean - End Function - - - Public Shared Function GetModuleHandle(ByVal lpModuleName As String) As IntPtr - End Function -#End Region - -#Region "System information methods" - _ - Public Shared Function GetDoubleClickTime() As UInteger - End Function -#End Region - -#End Region - -#Region "Enumerations" - Public Enum HookType As Integer - WH_CALLWNDPROC = 4 - WH_CALLWNDPROCRET = 12 - WH_CBT = 5 - WH_DEBUG = 9 - WH_FOREGROUNDIDLE = 11 - WH_GETMESSAGE = 3 - WH_JOURNALPLAYBACK = 1 - WH_JOURNALRECORD = 0 - WH_KEYBOARD = 2 - WH_KEYBOARD_LL = 13 - WH_MOUSE = 7 - WH_MOUSE_LL = 14 - WH_MSGFILTER = -1 - WH_SHELL = 10 - WH_SYSMSGFILTER = 6 - End Enum - - Public Enum HookCode As Integer - HC_ACTION = 0 - HC_NOREMOVE = 3 - End Enum - - Public Enum KeyboardFlags As UInteger - KF_EXTENDED = &H100 - KF_DLGMODE = &H800 - KF_MENUMODE = &H1000 - KF_ALTDOWN = &H2000 - KF_REPEAT = &H4000 - KF_UP = &H8000 - End Enum - - Public Enum LowLevelKeyboardHookFlags As UInteger - LLKHF_EXTENDED = &H1 - LLKHF_LOWER_IL_INJECTED = &H2 - LLKHF_INJECTED = &H10 - LLKHF_ALTDOWN = &H20 - LLKHF_UP = &H80 - End Enum - - Public Enum LowLevelMouseHookFlags As UInteger - LLMHF_INJECTED = &H1 - LLMHF_LOWER_IL_INJECTED = &H2 - End Enum - - Public Enum INPUTTYPE As UInteger - MOUSE = 0 - KEYBOARD = 1 - HARDWARE = 2 - End Enum - - _ - Public Enum KEYEVENTF As UInteger - ''' - ''' If specified, the scan code was preceded by a prefix byte that has the value 0xE0 (224). - ''' - ''' - EXTENDEDKEY = &H1 - - ''' - ''' If specified, the key is being released. If not specified, the key is being pressed. - ''' - ''' - KEYUP = &H2 - - ''' - ''' If specified, wScan identifies the key and wVk is ignored. - ''' - ''' - SCANCODE = &H8 - - ''' - ''' If specified, the system synthesizes a VK_PACKET keystroke. The wVk parameter must be zero. This flag can only be combined with the KEYEVENTF_KEYUP flag. - ''' - ''' - UNICODE = &H4 - End Enum - - _ - Public Enum MOUSEEVENTF As UInteger - ''' - ''' The dx and dy members contain normalized absolute (screen) coordinates. - ''' - ''' - ABSOLUTE = &H8000 - - ''' - ''' The wheel was moved horizontally, if the mouse has a wheel. The amount of movement is specified in mouseData. - ''' - ''' - HWHEEL = &H1000 - - ''' - ''' Movement occurred. - ''' - ''' - MOVE = &H1 - - ''' - ''' The WM_MOUSEMOVE messages will not be coalesced. The default behavior is to coalesce WM_MOUSEMOVE messages. - ''' - ''' - MOVE_NOCOALESCE = &H2000 - - ''' - ''' The left button was pressed. - ''' - ''' - LEFTDOWN = &H2 - - ''' - ''' The left button was released. - ''' - ''' - LEFTUP = &H4 - - ''' - ''' The right button was pressed. - ''' - ''' - RIGHTDOWN = &H8 - - ''' - ''' The right button was released. - ''' - ''' - RIGHTUP = &H10 - - ''' - ''' The middle button was pressed. - ''' - ''' - MIDDLEDOWN = &H20 - - ''' - ''' The middle button was released. - ''' - ''' - MIDDLEUP = &H40 - - ''' - ''' Maps coordinates to the entire desktop. Must be used with MOUSEEVENTF_ABSOLUTE. - ''' - ''' - VIRTUALDESK = &H4000 - - ''' - ''' The wheel was moved, if the mouse has a wheel. The amount of movement is specified in mouseData. - ''' - ''' - WHEEL = &H800 - - ''' - ''' An X button was pressed. - ''' - ''' - XDOWN = &H80 - - ''' - ''' An X button was released. - ''' - ''' - XUP = &H100 - End Enum - - Public Enum MouseXButton As UInteger - XBUTTON1 = &H1 - XBUTTON2 = &H2 - End Enum - - Public Enum KeyMessage As UInteger - WM_KEYDOWN = &H100 - WM_KEYUP = &H101 - WM_CHAR = &H102 - WM_DEADCHAR = &H103 - WM_SYSKEYDOWN = &H104 - WM_SYSKEYUP = &H105 - WM_SYSCHAR = &H106 - WM_SYSDEADCHAR = &H107 - WM_UNICHAR = &H109 - End Enum - - Public Enum MouseMessage As Integer - WM_MOUSEMOVE = &H200 - WM_LBUTTONDOWN = &H201 - WM_LBUTTONUP = &H202 - WM_LBUTTONDBLCLK = &H203 - WM_MBUTTONDOWN = &H207 - WM_MBUTTONUP = &H208 - WM_MBUTTONDBLCLK = &H209 - WM_RBUTTONDOWN = &H204 - WM_RBUTTONUP = &H205 - WM_RBUTTONDBLCLK = &H206 - WM_MOUSEWHEEL = &H20A - WM_MOUSEHWHEEL = &H20E - WM_XBUTTONDOWN = &H20B - WM_XBUTTONUP = &H20C - WM_XBUTTONDBLCLK = &H20D - End Enum -#End Region - -#Region "Structures" - _ - Public Structure KBDLLHOOKSTRUCT - Public vkCode As UInteger - Public scanCode As UInteger - Public flags As LowLevelKeyboardHookFlags - Public time As UInteger - Public dwExtraInfo As UIntPtr - End Structure - - _ - Public Structure MSLLHOOKSTRUCT - Public pt As NATIVEPOINT - Public mouseData As UInteger - Public flags As UInteger - Public time As UInteger - Public dwExtraInfo As UIntPtr - End Structure - - - Public Structure DWORD - Public Value As UInteger - Public Low As UShort - Public High As UShort - - Public SignedValue As Integer - Public SignedLow As Short - Public SignedHigh As Short - - Public Shared Widening Operator CType(ByVal DWORD As DWORD) As IntPtr - Return New IntPtr(DWORD.SignedValue) - End Operator - - Public Shared Widening Operator CType(ByVal DWORD As DWORD) As UInteger - Return DWORD.Value - End Operator - - Public Shared Widening Operator CType(ByVal DWORD As DWORD) As Integer - Return DWORD.SignedValue - End Operator - - Public Sub New(ByVal Value As UInteger) - Me.Value = Value - End Sub - - Public Sub New(ByVal Value As Integer) - Me.SignedValue = Value - End Sub - - Public Sub New(ByVal Low As UShort, ByVal High As UShort) - Me.Low = Low - Me.High = High - End Sub - - Public Sub New(ByVal Low As Short, ByVal High As Short) - Me.SignedLow = Low - Me.SignedHigh = High - End Sub - End Structure - - - Public Structure QWORD - Public Value As ULong - Public Low As UInteger - Public High As UInteger - - Public SignedValue As Long - Public SignedLow As Integer - Public SignedHigh As Integer - - Public LowWord As DWORD - Public HighWord As DWORD - - Public Shared Widening Operator CType(ByVal QWORD As QWORD) As ULong - Return QWORD.Value - End Operator - - Public Shared Widening Operator CType(ByVal QWORD As QWORD) As Long - Return QWORD.SignedValue - End Operator - - Public Sub New(ByVal Value As ULong) - Me.Value = Value - End Sub - - Public Sub New(ByVal Value As Long) - Me.SignedValue = Value - End Sub - - Public Sub New(ByVal Low As UInteger, ByVal High As UInteger) - Me.Low = Low - Me.High = High - End Sub - - Public Sub New(ByVal Low As Integer, ByVal High As Integer) - Me.SignedLow = Low - Me.SignedHigh = High - End Sub - End Structure - - _ - Public Structure INPUTUNION - Public mi As MOUSEINPUT - Public ki As KEYBDINPUT - Public hi As HARDWAREINPUT - End Structure - - Public Structure INPUT - Public type As INPUTTYPE - Public U As INPUTUNION - End Structure - - Public Structure MOUSEINPUT - Public dx As Integer - Public dy As Integer - Public mouseData As UInteger - Public dwFlags As UInteger - Public time As UInteger - Public dwExtraInfo As UIntPtr - End Structure - - Public Structure KEYBDINPUT - Public wVk As UShort - Public wScan As UShort - Public dwFlags As UInteger - Public time As UInteger - Public dwExtraInfo As UIntPtr - End Structure - - Public Structure HARDWAREINPUT - Public uMsg As UInteger - Public wParamL As UShort - Public wParamH As UShort - End Structure - - _ - Public Structure NATIVEPOINT - Public x As Integer - Public y As Integer - - Public Sub New(ByVal X As Integer, ByVal Y As Integer) - Me.x = X - Me.y = Y - End Sub - End Structure -#End Region - -End Class +'+---------------------------------------------------------------------------------+' +'| === InputHelper === |' +'| |' +'| Created by Vincent "Visual Vincent" Bengtsson |' +'| Website: https://www.mydoomsite.com/ |' +'| GitHub: https://github.com/Visual-Vincent |' +'| |' +'| |' +'| === COPYRIGHT LICENSE === |' +'| |' +'| Copyright (c) 2016-2022, Vincent Bengtsson |' +'| All rights reserved. |' +'| |' +'| Redistribution and use in source and binary forms, with or without |' +'| modification, are permitted provided that the following conditions are met: |' +'| |' +'| 1. Redistributions of source code must retain the above copyright notice, this |' +'| list of conditions and the following disclaimer. |' +'| |' +'| 2. Redistributions in binary form must reproduce the above copyright notice, |' +'| this list of conditions and the following disclaimer in the documentation |' +'| and/or other materials provided with the distribution. |' +'| |' +'| 3. Neither the name of the copyright holder nor the names of its |' +'| contributors may be used to endorse or promote products derived from |' +'| this software without specific prior written permission. |' +'| |' +'| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |' +'| AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |' +'| IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |' +'| DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |' +'| FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |' +'| DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |' +'| SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |' +'| CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |' +'| OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |' +'| OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |' +'+---------------------------------------------------------------------------------+' + +Imports System.Windows.Forms +Imports System.Runtime.InteropServices +Imports System.Text + +''' +''' A class containing all the native WinAPI methods, structures, declarations, etc. used by InputHelper. +''' +''' +Public NotInheritable Class NativeMethods + Private Sub New() + End Sub + +#Region "Delegates" + Public Delegate Function KeyboardProc(ByVal nCode As Integer, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr + Public Delegate Function LowLevelKeyboardProc(ByVal nCode As Integer, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr + Public Delegate Function LowLevelMouseProc(ByVal nCode As Integer, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr +#End Region + +#Region "Methods" + +#Region "Hook methods" + _ + Public Shared Function SetWindowsHookEx(ByVal idHook As HookType, ByVal lpfn As KeyboardProc, ByVal hMod As IntPtr, ByVal dwThreadId As UInteger) As IntPtr + End Function + + _ + Public Shared Function SetWindowsHookEx(ByVal idHook As HookType, ByVal lpfn As LowLevelKeyboardProc, ByVal hMod As IntPtr, ByVal dwThreadId As UInteger) As IntPtr + End Function + + _ + Public Shared Function SetWindowsHookEx(ByVal idHook As HookType, ByVal lpfn As LowLevelMouseProc, ByVal hMod As IntPtr, ByVal dwThreadId As UInteger) As IntPtr + End Function + + _ + Public Shared Function UnhookWindowsHookEx(ByVal hhk As IntPtr) As Boolean + End Function + + _ + Public Shared Function CallNextHookEx(ByVal hhk As IntPtr, ByVal nCode As Integer, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr + End Function +#End Region + +#Region "Input methods" + + Public Shared Function SendInput(ByVal nInputs As UInteger, ByVal pInputs() As INPUT, ByVal cbSize As Integer) As UInteger + End Function + + _ + Public Shared Function MapVirtualKeyEx(uCode As UInteger, uMapType As UInteger, dwhkl As IntPtr) As UInteger + End Function + + _ + Public Shared Function GetKeyboardLayout(idThread As UInteger) As IntPtr + End Function + + _ + Public Shared Function GetKeyboardState( ByVal lpKeyState As Byte()) As Boolean + End Function + + _ + Public Shared Function GetAsyncKeyState(ByVal vKey As Keys) As Short + End Function + + _ + Public Shared Function ToUnicodeEx(ByVal wVirtKey As UInteger, ByVal wScanCode As UInteger, ByVal lpKeyState As Byte(), ByVal pwszBuff As StringBuilder, ByVal cchBuff As Integer, ByVal wFlags As UInteger, ByVal dwhkl As IntPtr) As Integer + End Function +#End Region + +#Region "Window and thread methods" + 'CharSet.Unicode is required for CP437 ALT codes to work! + _ + Public Shared Function SendMessage(ByVal hWnd As IntPtr, ByVal Msg As UInteger, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr + End Function + + _ + Public Shared Function PostMessage(ByVal hWnd As IntPtr, ByVal Msg As UInteger, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As Boolean + End Function + + _ + Public Shared Function GetForegroundWindow() As IntPtr + End Function + + _ + Public Shared Function GetFocus() As IntPtr + End Function + + _ + Public Shared Function AttachThreadInput(ByVal idAttach As UInteger, ByVal idAttachTo As UInteger, fAttach As Boolean) As Boolean + End Function + + _ + Public Shared Function GetCurrentThreadId() As UInteger + End Function + + _ + Public Shared Function GetWindowThreadProcessId(ByVal hWnd As IntPtr, lpdwProcessId As UIntPtr) As UInteger + End Function + + _ + Public Shared Function WindowFromPoint(ByVal p As NATIVEPOINT) As IntPtr + End Function + + _ + Public Shared Function ScreenToClient(ByVal hWnd As IntPtr, ByRef lpPoint As NATIVEPOINT) As Boolean + End Function + + + Public Shared Function GetModuleHandle(ByVal lpModuleName As String) As IntPtr + End Function +#End Region + +#Region "System information methods" + _ + Public Shared Function GetDoubleClickTime() As UInteger + End Function +#End Region + +#End Region + +#Region "Enumerations" + Public Enum HookType As Integer + WH_CALLWNDPROC = 4 + WH_CALLWNDPROCRET = 12 + WH_CBT = 5 + WH_DEBUG = 9 + WH_FOREGROUNDIDLE = 11 + WH_GETMESSAGE = 3 + WH_JOURNALPLAYBACK = 1 + WH_JOURNALRECORD = 0 + WH_KEYBOARD = 2 + WH_KEYBOARD_LL = 13 + WH_MOUSE = 7 + WH_MOUSE_LL = 14 + WH_MSGFILTER = -1 + WH_SHELL = 10 + WH_SYSMSGFILTER = 6 + End Enum + + Public Enum HookCode As Integer + HC_ACTION = 0 + HC_NOREMOVE = 3 + End Enum + + Public Enum KeyboardFlags As UInteger + KF_EXTENDED = &H100 + KF_DLGMODE = &H800 + KF_MENUMODE = &H1000 + KF_ALTDOWN = &H2000 + KF_REPEAT = &H4000 + KF_UP = &H8000 + End Enum + + Public Enum LowLevelKeyboardHookFlags As UInteger + LLKHF_EXTENDED = &H1 + LLKHF_LOWER_IL_INJECTED = &H2 + LLKHF_INJECTED = &H10 + LLKHF_ALTDOWN = &H20 + LLKHF_UP = &H80 + End Enum + + Public Enum LowLevelMouseHookFlags As UInteger + LLMHF_INJECTED = &H1 + LLMHF_LOWER_IL_INJECTED = &H2 + End Enum + + Public Enum INPUTTYPE As UInteger + MOUSE = 0 + KEYBOARD = 1 + HARDWARE = 2 + End Enum + + _ + Public Enum KEYEVENTF As UInteger + ''' + ''' If specified, the scan code was preceded by a prefix byte that has the value 0xE0 (224). + ''' + ''' + EXTENDEDKEY = &H1 + + ''' + ''' If specified, the key is being released. If not specified, the key is being pressed. + ''' + ''' + KEYUP = &H2 + + ''' + ''' If specified, wScan identifies the key and wVk is ignored. + ''' + ''' + SCANCODE = &H8 + + ''' + ''' If specified, the system synthesizes a VK_PACKET keystroke. The wVk parameter must be zero. This flag can only be combined with the KEYEVENTF_KEYUP flag. + ''' + ''' + UNICODE = &H4 + End Enum + + _ + Public Enum MOUSEEVENTF As UInteger + ''' + ''' The dx and dy members contain normalized absolute (screen) coordinates. + ''' + ''' + ABSOLUTE = &H8000 + + ''' + ''' The wheel was moved horizontally, if the mouse has a wheel. The amount of movement is specified in mouseData. + ''' + ''' + HWHEEL = &H1000 + + ''' + ''' Movement occurred. + ''' + ''' + MOVE = &H1 + + ''' + ''' The WM_MOUSEMOVE messages will not be coalesced. The default behavior is to coalesce WM_MOUSEMOVE messages. + ''' + ''' + MOVE_NOCOALESCE = &H2000 + + ''' + ''' The left button was pressed. + ''' + ''' + LEFTDOWN = &H2 + + ''' + ''' The left button was released. + ''' + ''' + LEFTUP = &H4 + + ''' + ''' The right button was pressed. + ''' + ''' + RIGHTDOWN = &H8 + + ''' + ''' The right button was released. + ''' + ''' + RIGHTUP = &H10 + + ''' + ''' The middle button was pressed. + ''' + ''' + MIDDLEDOWN = &H20 + + ''' + ''' The middle button was released. + ''' + ''' + MIDDLEUP = &H40 + + ''' + ''' Maps coordinates to the entire desktop. Must be used with MOUSEEVENTF_ABSOLUTE. + ''' + ''' + VIRTUALDESK = &H4000 + + ''' + ''' The wheel was moved, if the mouse has a wheel. The amount of movement is specified in mouseData. + ''' + ''' + WHEEL = &H800 + + ''' + ''' An X button was pressed. + ''' + ''' + XDOWN = &H80 + + ''' + ''' An X button was released. + ''' + ''' + XUP = &H100 + End Enum + + Public Enum MouseXButton As UInteger + XBUTTON1 = &H1 + XBUTTON2 = &H2 + End Enum + + Public Enum KeyMessage As UInteger + WM_KEYDOWN = &H100 + WM_KEYUP = &H101 + WM_CHAR = &H102 + WM_DEADCHAR = &H103 + WM_SYSKEYDOWN = &H104 + WM_SYSKEYUP = &H105 + WM_SYSCHAR = &H106 + WM_SYSDEADCHAR = &H107 + WM_UNICHAR = &H109 + End Enum + + Public Enum MouseMessage As Integer + WM_MOUSEMOVE = &H200 + WM_LBUTTONDOWN = &H201 + WM_LBUTTONUP = &H202 + WM_LBUTTONDBLCLK = &H203 + WM_MBUTTONDOWN = &H207 + WM_MBUTTONUP = &H208 + WM_MBUTTONDBLCLK = &H209 + WM_RBUTTONDOWN = &H204 + WM_RBUTTONUP = &H205 + WM_RBUTTONDBLCLK = &H206 + WM_MOUSEWHEEL = &H20A + WM_MOUSEHWHEEL = &H20E + WM_XBUTTONDOWN = &H20B + WM_XBUTTONUP = &H20C + WM_XBUTTONDBLCLK = &H20D + End Enum +#End Region + +#Region "Structures" + _ + Public Structure KBDLLHOOKSTRUCT + Public vkCode As UInteger + Public scanCode As UInteger + Public flags As LowLevelKeyboardHookFlags + Public time As UInteger + Public dwExtraInfo As UIntPtr + End Structure + + _ + Public Structure MSLLHOOKSTRUCT + Public pt As NATIVEPOINT + Public mouseData As UInteger + Public flags As UInteger + Public time As UInteger + Public dwExtraInfo As UIntPtr + End Structure + + + Public Structure DWORD + Public Value As UInteger + Public Low As UShort + Public High As UShort + + Public SignedValue As Integer + Public SignedLow As Short + Public SignedHigh As Short + + Public Shared Widening Operator CType(ByVal DWORD As DWORD) As IntPtr + Return New IntPtr(DWORD.SignedValue) + End Operator + + Public Shared Widening Operator CType(ByVal DWORD As DWORD) As UInteger + Return DWORD.Value + End Operator + + Public Shared Widening Operator CType(ByVal DWORD As DWORD) As Integer + Return DWORD.SignedValue + End Operator + + Public Sub New(ByVal Value As UInteger) + Me.Value = Value + End Sub + + Public Sub New(ByVal Value As Integer) + Me.SignedValue = Value + End Sub + + Public Sub New(ByVal Low As UShort, ByVal High As UShort) + Me.Low = Low + Me.High = High + End Sub + + Public Sub New(ByVal Low As Short, ByVal High As Short) + Me.SignedLow = Low + Me.SignedHigh = High + End Sub + End Structure + + + Public Structure QWORD + Public Value As ULong + Public Low As UInteger + Public High As UInteger + + Public SignedValue As Long + Public SignedLow As Integer + Public SignedHigh As Integer + + Public LowWord As DWORD + Public HighWord As DWORD + + Public Shared Widening Operator CType(ByVal QWORD As QWORD) As ULong + Return QWORD.Value + End Operator + + Public Shared Widening Operator CType(ByVal QWORD As QWORD) As Long + Return QWORD.SignedValue + End Operator + + Public Sub New(ByVal Value As ULong) + Me.Value = Value + End Sub + + Public Sub New(ByVal Value As Long) + Me.SignedValue = Value + End Sub + + Public Sub New(ByVal Low As UInteger, ByVal High As UInteger) + Me.Low = Low + Me.High = High + End Sub + + Public Sub New(ByVal Low As Integer, ByVal High As Integer) + Me.SignedLow = Low + Me.SignedHigh = High + End Sub + End Structure + + _ + Public Structure INPUTUNION + Public mi As MOUSEINPUT + Public ki As KEYBDINPUT + Public hi As HARDWAREINPUT + End Structure + + Public Structure INPUT + Public type As INPUTTYPE + Public U As INPUTUNION + End Structure + + Public Structure MOUSEINPUT + Public dx As Integer + Public dy As Integer + Public mouseData As UInteger + Public dwFlags As UInteger + Public time As UInteger + Public dwExtraInfo As UIntPtr + End Structure + + Public Structure KEYBDINPUT + Public wVk As UShort + Public wScan As UShort + Public dwFlags As UInteger + Public time As UInteger + Public dwExtraInfo As UIntPtr + End Structure + + Public Structure HARDWAREINPUT + Public uMsg As UInteger + Public wParamL As UShort + Public wParamH As UShort + End Structure + + _ + Public Structure NATIVEPOINT + Public x As Integer + Public y As Integer + + Public Sub New(ByVal X As Integer, ByVal Y As Integer) + Me.x = X + Me.y = Y + End Sub + End Structure +#End Region + +End Class diff --git a/LICENSE b/LICENSE index 7157b74..150fbcc 100644 --- a/LICENSE +++ b/LICENSE @@ -1,29 +1,29 @@ -BSD 3-Clause License - -Copyright (c) 2016-2019, Vincent Bengtsson -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -1. Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -3. Neither the name of the copyright holder nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +BSD 3-Clause License + +Copyright (c) 2016-2022, Vincent Bengtsson +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +3. Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/README.md b/README.md index 33cdf60..2123608 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,18 @@ -# InputHelper -A .NET friendly library for handling, simulating and intercepting mouse and keyboard input. - -# Precompiled download -A precompiled version of the library (DLL) can be found in the [**Releases** section](https://github.com/Visual-Vincent/InputHelper/releases) of this repository. - -# License -See "LICENSE" in the repository or "LICENSE.txt" in the project. - -# Documentation -See the project's [Wiki page](https://github.com/Visual-Vincent/InputHelper/wiki). - -# Questions, Feature requests, Bug reports, etc. -Have any questions, need help with your code, want to report a bug or simply suggest a new feature?
Please write a ticket on the [Issue tracker](https://github.com/Visual-Vincent/InputHelper/issues) and I'll get back to you as soon as I can! +# InputHelper +[![License](https://img.shields.io/github/license/Visual-Vincent/InputHelper?style=plastic)](https://github.com/Visual-Vincent/InputHelper/blob/master/LICENSE) + +A .NET friendly library for handling, simulating and intercepting mouse and keyboard input. + +## Requirements +- Windows 7 SP1 or newer (may work on XP/Vista as well, but this has not been tested) +- .NET Framework: 3.5, 4.0-4.8, _or:_ +- .NET Core (Desktop Runtime): 3.1, 5.0, 6.0 + +## Precompiled download +A precompiled version of the library (DLL) can be found in the [**Releases** section](https://github.com/Visual-Vincent/InputHelper/releases) of this repository. + +## Documentation +See the project's [Wiki page](https://github.com/Visual-Vincent/InputHelper/wiki). + +## Questions, Feature requests, Bug reports, etc. +Have any questions, need help with your code, want to report a bug or simply suggest a new feature?
Please write a ticket on the [Issue tracker](https://github.com/Visual-Vincent/InputHelper/issues) and I'll get back to you as soon as I can!