node-native-win-utils 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (28) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +174 -0
  3. package/binding.gyp +33 -0
  4. package/build/Release/node-native-win-utils.exp +0 -0
  5. package/build/Release/node-native-win-utils.iobj +0 -0
  6. package/build/Release/node-native-win-utils.ipdb +0 -0
  7. package/build/Release/node-native-win-utils.lib +0 -0
  8. package/build/Release/node-native-win-utils.pdb +0 -0
  9. package/build/Release/nothing.lib +0 -0
  10. package/build/Release/obj/node-native-win-utils/node-nat.99DB284F.tlog/CL.command.1.tlog +0 -0
  11. package/build/Release/obj/node-native-win-utils/node-nat.99DB284F.tlog/CL.read.1.tlog +0 -0
  12. package/build/Release/obj/node-native-win-utils/node-nat.99DB284F.tlog/CL.write.1.tlog +0 -0
  13. package/build/Release/obj/node-native-win-utils/node-nat.99DB284F.tlog/link.command.1.tlog +0 -0
  14. package/build/Release/obj/node-native-win-utils/node-nat.99DB284F.tlog/link.read.1.tlog +0 -0
  15. package/build/Release/obj/node-native-win-utils/node-nat.99DB284F.tlog/link.write.1.tlog +0 -0
  16. package/build/Release/obj/node-native-win-utils/node-nat.99DB284F.tlog/link.write.2u.tlog +0 -0
  17. package/build/Release/obj/node-native-win-utils/node-nat.99DB284F.tlog/node-native-win-utils.lastbuildstate +2 -0
  18. package/build/Release/obj/node-native-win-utils/node-native-win-utils.node.recipe +11 -0
  19. package/build/Release/obj/node-native-win-utils/win_delay_load_hook.obj +0 -0
  20. package/build/binding.sln +36 -0
  21. package/build/node-native-win-utils.vcxproj +154 -0
  22. package/build/node-native-win-utils.vcxproj.filters +52 -0
  23. package/dist/index.d.ts +27 -0
  24. package/dist/index.js +35 -0
  25. package/dist/keyCodes.d.ts +2 -0
  26. package/dist/keyCodes.js +102 -0
  27. package/package.json +33 -0
  28. package/prebuilds/win32-x64/node.napi.node +0 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Andrey
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,174 @@
1
+ [![License][license-src]][license-href]
2
+
3
+ # Node Native Win Utils
4
+
5
+ I did it for myself because I didn't feel like dealing with libraries like 'node-ffi' to implement this functionality. Maybe someone will find it useful. I'ts WINDOWS OS ONLY
6
+
7
+ This package provides a native addon for Node.js that allows you to perform various utility operations on Windows systems. It includes key event listeners, window data retrieval, and window screenshot capture functionality.
8
+
9
+ ## Installation
10
+
11
+ You can install the package using npm:
12
+
13
+ ```shell
14
+
15
+ npm install node-native-win-utils
16
+
17
+ ```
18
+
19
+ ## Usage
20
+
21
+ ### Importing the Package
22
+
23
+ To use the package, import the necessary functions and types:
24
+
25
+ ```javascript
26
+ import {
27
+ keyDownHandler,
28
+ keyUpHandler,
29
+ getWindowData,
30
+ captureWindow,
31
+ KeyListener,
32
+ } from "node-native-win-utils";
33
+ ```
34
+
35
+ ### Key Event Listeners
36
+
37
+ The package provides `keyDownHandler` and `keyUpHandler` functions, which allow you to register callbacks for key down and key up events, respectively. The callbacks receive the `keyCode` as a parameter:
38
+
39
+ ```javascript
40
+ keyDownHandler((keyCode) => {
41
+ console.log("Key down:", keyCode);
42
+ });
43
+
44
+ // Key down: 8
45
+
46
+ keyUpHandler((keyCode) => {
47
+ console.log("Key up:", keyCode);
48
+ });
49
+
50
+ // Key up: 8
51
+ ```
52
+
53
+ ### Window Data
54
+
55
+ The `getWindowData` function retrieves information about a specific window identified by its name. It returns an object with properties `width`, `height`, `x`, and `y`, representing the window dimensions and position:
56
+
57
+ ```javascript
58
+ const windowData = getWindowData("Window Name");
59
+
60
+ console.log("Window data:", windowData);
61
+
62
+ // Window data: { width: 800, height: 600, x: 50, y: 50 }
63
+ ```
64
+
65
+ ### Window Capture
66
+
67
+ The `captureWindow` function allows you to capture a screenshot of a specific window identified by its name. Provide the window name and the output path as parameters:
68
+
69
+ ```javascript
70
+ captureWindow("Window Name", "output.png");
71
+
72
+ // Output: output.png with a screenshot of the window
73
+ ```
74
+
75
+ ### Key Listener Class
76
+
77
+ The `KeyListener` class extends the EventEmitter class and simplifies working with the `keyDownHandler` and `keyUpHandler` functions. You can register event listeners for the "keyDown" and "keyUp" events using the `on` method:
78
+
79
+ ```javascript
80
+ const listener = new KeyListener();
81
+
82
+ listener.on("keyDown", (data) => {
83
+ console.log("Key down:", data.keyCode, data.keyName);
84
+ });
85
+
86
+ // Key down: 8 Backspace
87
+
88
+ listener.on("keyUp", (data) => {
89
+ console.log("Key up:", data.keyCode, data.keyName);
90
+ });
91
+
92
+ // Key up: 8 Backspace
93
+ ```
94
+
95
+ ## Functions
96
+
97
+ | Function | Parameters | Return Type |
98
+
99
+ | -------------- | --------------------------------------------------------------------------------------- | ---------------------- |
100
+
101
+ | keyDownHandler | `callback: (keyCode: number) => void` | `void` |
102
+
103
+ | keyUpHandler | `callback: (keyCode: number) => void` | `void` |
104
+
105
+ | getWindowData | `windowName: string` | `WindowData` |
106
+
107
+ | captureWindow | `windowName: string, outputPath: string` | `void` |
108
+
109
+ | KeyListener.on | `event: "keyDown"`,<br>`callback: (data: { keyCode: number; keyName: string }) => void` | `this` (EventListener) |
110
+
111
+ | KeyListener.on | `event: "keyUp"`,<br>`callback: (data: { keyCode: number; keyName: string }) => void` | `this` (EventListener) |
112
+
113
+ ## Examples
114
+
115
+ Here are some examples of using the package:
116
+
117
+ ```javascript
118
+ import {
119
+ keyDownHandler,
120
+ keyUpHandler,
121
+ getWindowData,
122
+ captureWindow,
123
+ KeyListener,
124
+ } from "node-native-win-utils";
125
+
126
+ // Register key event handlers
127
+
128
+ keyDownHandler((keyCode) => {
129
+ console.log("Key down:", keyCode);
130
+ });
131
+
132
+ // Key down: 123
133
+
134
+ keyUpHandler((keyCode) => {
135
+ console.log("Key up:", keyCode);
136
+ });
137
+
138
+ // Key up: 123
139
+
140
+ // Retrieve window data
141
+
142
+ const windowData = getWindowData("My Window");
143
+
144
+ console.log("Window data:", windowData);
145
+
146
+ // Window data: { width: 1024, height: 768, x: 100, y: 100 }
147
+
148
+ // Capture window screenshot
149
+
150
+ captureWindow("My Window", "output.png");
151
+
152
+ // Output: output.png with a screenshot of the window
153
+
154
+ // Use KeyListener class
155
+
156
+ const listener = new KeyListener();
157
+
158
+ listener.on("keyDown", (data) => {
159
+ console.log("Key down:", data.keyCode, data.keyName);
160
+ });
161
+
162
+ // Key down: 8 Backspace
163
+
164
+ listener.on("keyUp", (data) => {
165
+ console.log("Key up:", data.keyCode, data.keyName);
166
+ });
167
+
168
+ // Key up: 8 Backspace
169
+ ```
170
+
171
+ P.S.: As my knowledge of C++ is just brief, most of the C++ code is written using GPT-3.5 and GPT-4 or found on Google with some minor edits by myself.
172
+
173
+ [license-src]: https://img.shields.io/github/license/nuxt-modules/icon.svg?style=for-the-badge&colorA=18181B&colorB=28CF8D
174
+ [license-href]: https://github.com/RynerNO/node-native-win-utils/blob/main/LICENSE
package/binding.gyp ADDED
@@ -0,0 +1,33 @@
1
+ {
2
+ "targets": [
3
+ {
4
+ "target_name": "node-native-win-utils",
5
+ "sources": ["src/cpp/main.cpp"],
6
+ "openssl_flips": "",
7
+ "include_dirs": [
8
+ "<!@(node -p \"require('node-addon-api').include\")",
9
+ "src/cpp"
10
+ ],
11
+ "dependencies": [
12
+ "<!(node -p \"require('node-addon-api').gyp\")"
13
+ ],
14
+ "libraries": ["dwmapi.lib", "windowsapp.lib"],
15
+ "defines": ["NAPI_DISABLE_CPP_EXCEPTIONS"],
16
+ "conditions": [
17
+ ["OS=='win'", {
18
+ "defines": [
19
+ "_CRT_SECURE_NO_WARNINGS"
20
+ ],
21
+ "msvs_settings": {
22
+ "VCCLCompilerTool": {
23
+ "AdditionalOptions": ["/EHsc"]
24
+ }
25
+ }
26
+ }]
27
+ ],
28
+ "cflags!": ["-fno-exceptions"],
29
+ "cflags_cc!": ["-fno-exceptions"],
30
+ "defines": ["NAPI_CPP_EXCEPTIONS"]
31
+ }
32
+ ]
33
+ }
Binary file
@@ -0,0 +1,2 @@
1
+ PlatformToolSet=v143:VCToolArchitecture=Native64Bit:VCToolsVersion=14.34.31933:TargetPlatformVersion=10.0.22000.0:
2
+ Release|x64|C:\Code\window-handle-js\build\|
@@ -0,0 +1,11 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <Project>
3
+ <ProjectOutputs>
4
+ <ProjectOutput>
5
+ <FullPath>C:\Code\window-handle-js\build\Release\node-native-win-utils.node</FullPath>
6
+ </ProjectOutput>
7
+ </ProjectOutputs>
8
+ <ContentFiles />
9
+ <SatelliteDlls />
10
+ <NonRecipeFileRefs />
11
+ </Project>
@@ -0,0 +1,36 @@
1
+ Microsoft Visual Studio Solution File, Format Version 12.00
2
+ # Visual Studio 2015
3
+ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "node-native-win-utils", "node-native-win-utils.vcxproj", "{99DB284F-4003-4313-F66C-1BD0E3CC12B5}"
4
+ ProjectSection(ProjectDependencies) = postProject
5
+ {7137135D-2036-DDE1-E426-9B03A16079A8} = {7137135D-2036-DDE1-E426-9B03A16079A8}
6
+ EndProjectSection
7
+ EndProject
8
+ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "nothing", "node_modules\node-addon-api\nothing.vcxproj", "{7137135D-2036-DDE1-E426-9B03A16079A8}"
9
+ EndProject
10
+ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "(node_modules)", "..\node_modules", "{9D350B9E-06FB-960D-859F-B43C9597383A}"
11
+ EndProject
12
+ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "(node-addon-api)", "..\node_modules\node-addon-api", "{AF891C37-E709-9CCC-0D50-0CCCC8CCC563}"
13
+ EndProject
14
+ Global
15
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
16
+ Debug|x64 = Debug|x64
17
+ Release|x64 = Release|x64
18
+ EndGlobalSection
19
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
20
+ {7137135D-2036-DDE1-E426-9B03A16079A8}.Debug|x64.ActiveCfg = Debug|x64
21
+ {7137135D-2036-DDE1-E426-9B03A16079A8}.Debug|x64.Build.0 = Debug|x64
22
+ {7137135D-2036-DDE1-E426-9B03A16079A8}.Release|x64.ActiveCfg = Release|x64
23
+ {7137135D-2036-DDE1-E426-9B03A16079A8}.Release|x64.Build.0 = Release|x64
24
+ {99DB284F-4003-4313-F66C-1BD0E3CC12B5}.Debug|x64.ActiveCfg = Debug|x64
25
+ {99DB284F-4003-4313-F66C-1BD0E3CC12B5}.Debug|x64.Build.0 = Debug|x64
26
+ {99DB284F-4003-4313-F66C-1BD0E3CC12B5}.Release|x64.ActiveCfg = Release|x64
27
+ {99DB284F-4003-4313-F66C-1BD0E3CC12B5}.Release|x64.Build.0 = Release|x64
28
+ EndGlobalSection
29
+ GlobalSection(SolutionProperties) = preSolution
30
+ HideSolutionNode = FALSE
31
+ EndGlobalSection
32
+ GlobalSection(NestedProjects) = preSolution
33
+ {AF891C37-E709-9CCC-0D50-0CCCC8CCC563} = {9D350B9E-06FB-960D-859F-B43C9597383A}
34
+ {7137135D-2036-DDE1-E426-9B03A16079A8} = {AF891C37-E709-9CCC-0D50-0CCCC8CCC563}
35
+ EndGlobalSection
36
+ EndGlobal
@@ -0,0 +1,154 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3
+ <ItemGroup Label="ProjectConfigurations">
4
+ <ProjectConfiguration Include="Debug|x64">
5
+ <Configuration>Debug</Configuration>
6
+ <Platform>x64</Platform>
7
+ </ProjectConfiguration>
8
+ <ProjectConfiguration Include="Release|x64">
9
+ <Configuration>Release</Configuration>
10
+ <Platform>x64</Platform>
11
+ </ProjectConfiguration>
12
+ </ItemGroup>
13
+ <PropertyGroup Label="Globals">
14
+ <ProjectGuid>{99DB284F-4003-4313-F66C-1BD0E3CC12B5}</ProjectGuid>
15
+ <Keyword>Win32Proj</Keyword>
16
+ <RootNamespace>node-native-win-utils</RootNamespace>
17
+ <IgnoreWarnCompileDuplicatedFilename>true</IgnoreWarnCompileDuplicatedFilename>
18
+ <PreferredToolArchitecture>x64</PreferredToolArchitecture>
19
+ <WindowsTargetPlatformVersion>10.0.22000.0</WindowsTargetPlatformVersion>
20
+ </PropertyGroup>
21
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props"/>
22
+ <PropertyGroup Label="Configuration">
23
+ <ConfigurationType>DynamicLibrary</ConfigurationType>
24
+ </PropertyGroup>
25
+ <PropertyGroup Label="Locals">
26
+ <PlatformToolset>v143</PlatformToolset>
27
+ </PropertyGroup>
28
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props"/>
29
+ <Import Project="$(VCTargetsPath)\BuildCustomizations\masm.props"/>
30
+ <ImportGroup Label="ExtensionSettings"/>
31
+ <ImportGroup Label="PropertySheets">
32
+ <Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props"/>
33
+ </ImportGroup>
34
+ <PropertyGroup Label="UserMacros"/>
35
+ <PropertyGroup>
36
+ <ExecutablePath>$(ExecutablePath);$(MSBuildProjectDirectory)\..\bin\;$(MSBuildProjectDirectory)\..\bin\</ExecutablePath>
37
+ <IgnoreImportLibrary>true</IgnoreImportLibrary>
38
+ <IntDir>$(Configuration)\obj\$(ProjectName)\</IntDir>
39
+ <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release|x64'">false</LinkIncremental>
40
+ <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</LinkIncremental>
41
+ <OutDir>$(SolutionDir)$(Configuration)\</OutDir>
42
+ <TargetExt Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">.node</TargetExt>
43
+ <TargetExt Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">.node</TargetExt>
44
+ <TargetExt Condition="'$(Configuration)|$(Platform)'=='Release|x64'">.node</TargetExt>
45
+ <TargetExt Condition="'$(Configuration)|$(Platform)'=='Release|x64'">.node</TargetExt>
46
+ <TargetName>$(ProjectName)</TargetName>
47
+ <TargetPath>$(OutDir)\$(ProjectName).node</TargetPath>
48
+ </PropertyGroup>
49
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
50
+ <ClCompile>
51
+ <AdditionalIncludeDirectories>C:\Users\ryner\AppData\Local\Temp\prebuildify\node\20.0.0\include\node;C:\Users\ryner\AppData\Local\Temp\prebuildify\node\20.0.0\src;C:\Users\ryner\AppData\Local\Temp\prebuildify\node\20.0.0\deps\openssl\config;C:\Users\ryner\AppData\Local\Temp\prebuildify\node\20.0.0\deps\openssl\openssl\include;C:\Users\ryner\AppData\Local\Temp\prebuildify\node\20.0.0\deps\uv\include;C:\Users\ryner\AppData\Local\Temp\prebuildify\node\20.0.0\deps\zlib;C:\Users\ryner\AppData\Local\Temp\prebuildify\node\20.0.0\deps\v8\include;C:\Code\window-handle-js\node_modules\node-addon-api;..\src\cpp;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
52
+ <AdditionalOptions>/Zc:__cplusplus -std:c++17 /EHsc %(AdditionalOptions)</AdditionalOptions>
53
+ <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
54
+ <BufferSecurityCheck>true</BufferSecurityCheck>
55
+ <DebugInformationFormat>OldStyle</DebugInformationFormat>
56
+ <DisableSpecificWarnings>4351;4355;4800;4251;4275;4244;4267;%(DisableSpecificWarnings)</DisableSpecificWarnings>
57
+ <ExceptionHandling>false</ExceptionHandling>
58
+ <MinimalRebuild>false</MinimalRebuild>
59
+ <MultiProcessorCompilation>true</MultiProcessorCompilation>
60
+ <OmitFramePointers>false</OmitFramePointers>
61
+ <Optimization>Disabled</Optimization>
62
+ <PrecompiledHeader>NotUsing</PrecompiledHeader>
63
+ <PreprocessorDefinitions>NODE_GYP_MODULE_NAME=node-native-win-utils;USING_UV_SHARED=1;USING_V8_SHARED=1;V8_DEPRECATION_WARNINGS=1;V8_DEPRECATION_WARNINGS;V8_IMMINENT_DEPRECATION_WARNINGS;_GLIBCXX_USE_CXX11_ABI=1;WIN32;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;_HAS_EXCEPTIONS=0;OPENSSL_NO_PINSHARED;OPENSSL_THREADS;NAPI_CPP_EXCEPTIONS;_CRT_SECURE_NO_WARNINGS;BUILDING_NODE_EXTENSION;HOST_BINARY=&quot;node.exe&quot;;DEBUG;_DEBUG;V8_ENABLE_CHECKS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
64
+ <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
65
+ <StringPooling>true</StringPooling>
66
+ <SuppressStartupBanner>true</SuppressStartupBanner>
67
+ <TreatWarningAsError>false</TreatWarningAsError>
68
+ <WarningLevel>Level3</WarningLevel>
69
+ <WholeProgramOptimization>true</WholeProgramOptimization>
70
+ </ClCompile>
71
+ <Lib>
72
+ <AdditionalOptions>/LTCG:INCREMENTAL %(AdditionalOptions)</AdditionalOptions>
73
+ </Lib>
74
+ <Link>
75
+ <AdditionalDependencies>kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;DelayImp.lib;&quot;C:\\Users\\ryner\\AppData\\Local\\Temp\\prebuildify\\node\\20.0.0\\x64\\node.lib&quot;;dwmapi.lib;windowsapp.lib</AdditionalDependencies>
76
+ <AdditionalOptions>/LTCG:INCREMENTAL /ignore:4199 %(AdditionalOptions)</AdditionalOptions>
77
+ <DelayLoadDLLs>node.exe;%(DelayLoadDLLs)</DelayLoadDLLs>
78
+ <EnableCOMDATFolding>true</EnableCOMDATFolding>
79
+ <GenerateDebugInformation>true</GenerateDebugInformation>
80
+ <OptimizeReferences>true</OptimizeReferences>
81
+ <OutputFile>$(OutDir)$(ProjectName).node</OutputFile>
82
+ <SuppressStartupBanner>true</SuppressStartupBanner>
83
+ <TargetExt>.node</TargetExt>
84
+ <TargetMachine>MachineX64</TargetMachine>
85
+ </Link>
86
+ <ResourceCompile>
87
+ <AdditionalIncludeDirectories>C:\Users\ryner\AppData\Local\Temp\prebuildify\node\20.0.0\include\node;C:\Users\ryner\AppData\Local\Temp\prebuildify\node\20.0.0\src;C:\Users\ryner\AppData\Local\Temp\prebuildify\node\20.0.0\deps\openssl\config;C:\Users\ryner\AppData\Local\Temp\prebuildify\node\20.0.0\deps\openssl\openssl\include;C:\Users\ryner\AppData\Local\Temp\prebuildify\node\20.0.0\deps\uv\include;C:\Users\ryner\AppData\Local\Temp\prebuildify\node\20.0.0\deps\zlib;C:\Users\ryner\AppData\Local\Temp\prebuildify\node\20.0.0\deps\v8\include;C:\Code\window-handle-js\node_modules\node-addon-api;..\src\cpp;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
88
+ <PreprocessorDefinitions>NODE_GYP_MODULE_NAME=node-native-win-utils;USING_UV_SHARED=1;USING_V8_SHARED=1;V8_DEPRECATION_WARNINGS=1;V8_DEPRECATION_WARNINGS;V8_IMMINENT_DEPRECATION_WARNINGS;_GLIBCXX_USE_CXX11_ABI=1;WIN32;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;_HAS_EXCEPTIONS=0;OPENSSL_NO_PINSHARED;OPENSSL_THREADS;NAPI_CPP_EXCEPTIONS;_CRT_SECURE_NO_WARNINGS;BUILDING_NODE_EXTENSION;HOST_BINARY=&quot;node.exe&quot;;DEBUG;_DEBUG;V8_ENABLE_CHECKS;%(PreprocessorDefinitions);%(PreprocessorDefinitions)</PreprocessorDefinitions>
89
+ </ResourceCompile>
90
+ </ItemDefinitionGroup>
91
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
92
+ <ClCompile>
93
+ <AdditionalIncludeDirectories>C:\Users\ryner\AppData\Local\Temp\prebuildify\node\20.0.0\include\node;C:\Users\ryner\AppData\Local\Temp\prebuildify\node\20.0.0\src;C:\Users\ryner\AppData\Local\Temp\prebuildify\node\20.0.0\deps\openssl\config;C:\Users\ryner\AppData\Local\Temp\prebuildify\node\20.0.0\deps\openssl\openssl\include;C:\Users\ryner\AppData\Local\Temp\prebuildify\node\20.0.0\deps\uv\include;C:\Users\ryner\AppData\Local\Temp\prebuildify\node\20.0.0\deps\zlib;C:\Users\ryner\AppData\Local\Temp\prebuildify\node\20.0.0\deps\v8\include;C:\Code\window-handle-js\node_modules\node-addon-api;..\src\cpp;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
94
+ <AdditionalOptions>/Zc:__cplusplus -std:c++17 /EHsc %(AdditionalOptions)</AdditionalOptions>
95
+ <BufferSecurityCheck>true</BufferSecurityCheck>
96
+ <DebugInformationFormat>OldStyle</DebugInformationFormat>
97
+ <DisableSpecificWarnings>4351;4355;4800;4251;4275;4244;4267;%(DisableSpecificWarnings)</DisableSpecificWarnings>
98
+ <ExceptionHandling>false</ExceptionHandling>
99
+ <FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
100
+ <FunctionLevelLinking>true</FunctionLevelLinking>
101
+ <InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion>
102
+ <IntrinsicFunctions>true</IntrinsicFunctions>
103
+ <MultiProcessorCompilation>true</MultiProcessorCompilation>
104
+ <OmitFramePointers>true</OmitFramePointers>
105
+ <Optimization>Full</Optimization>
106
+ <PrecompiledHeader>NotUsing</PrecompiledHeader>
107
+ <PreprocessorDefinitions>NODE_GYP_MODULE_NAME=node-native-win-utils;USING_UV_SHARED=1;USING_V8_SHARED=1;V8_DEPRECATION_WARNINGS=1;V8_DEPRECATION_WARNINGS;V8_IMMINENT_DEPRECATION_WARNINGS;_GLIBCXX_USE_CXX11_ABI=1;WIN32;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;_HAS_EXCEPTIONS=0;OPENSSL_NO_PINSHARED;OPENSSL_THREADS;NAPI_CPP_EXCEPTIONS;_CRT_SECURE_NO_WARNINGS;BUILDING_NODE_EXTENSION;HOST_BINARY=&quot;node.exe&quot;;%(PreprocessorDefinitions)</PreprocessorDefinitions>
108
+ <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
109
+ <RuntimeTypeInfo>false</RuntimeTypeInfo>
110
+ <StringPooling>true</StringPooling>
111
+ <SuppressStartupBanner>true</SuppressStartupBanner>
112
+ <TreatWarningAsError>false</TreatWarningAsError>
113
+ <WarningLevel>Level3</WarningLevel>
114
+ <WholeProgramOptimization>true</WholeProgramOptimization>
115
+ </ClCompile>
116
+ <Lib>
117
+ <AdditionalOptions>/LTCG:INCREMENTAL %(AdditionalOptions)</AdditionalOptions>
118
+ </Lib>
119
+ <Link>
120
+ <AdditionalDependencies>kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;DelayImp.lib;&quot;C:\\Users\\ryner\\AppData\\Local\\Temp\\prebuildify\\node\\20.0.0\\x64\\node.lib&quot;;dwmapi.lib;windowsapp.lib</AdditionalDependencies>
121
+ <AdditionalOptions>/LTCG:INCREMENTAL /ignore:4199 %(AdditionalOptions)</AdditionalOptions>
122
+ <DelayLoadDLLs>node.exe;%(DelayLoadDLLs)</DelayLoadDLLs>
123
+ <EnableCOMDATFolding>true</EnableCOMDATFolding>
124
+ <GenerateDebugInformation>true</GenerateDebugInformation>
125
+ <OptimizeReferences>true</OptimizeReferences>
126
+ <OutputFile>$(OutDir)$(ProjectName).node</OutputFile>
127
+ <SuppressStartupBanner>true</SuppressStartupBanner>
128
+ <TargetExt>.node</TargetExt>
129
+ <TargetMachine>MachineX64</TargetMachine>
130
+ </Link>
131
+ <ResourceCompile>
132
+ <AdditionalIncludeDirectories>C:\Users\ryner\AppData\Local\Temp\prebuildify\node\20.0.0\include\node;C:\Users\ryner\AppData\Local\Temp\prebuildify\node\20.0.0\src;C:\Users\ryner\AppData\Local\Temp\prebuildify\node\20.0.0\deps\openssl\config;C:\Users\ryner\AppData\Local\Temp\prebuildify\node\20.0.0\deps\openssl\openssl\include;C:\Users\ryner\AppData\Local\Temp\prebuildify\node\20.0.0\deps\uv\include;C:\Users\ryner\AppData\Local\Temp\prebuildify\node\20.0.0\deps\zlib;C:\Users\ryner\AppData\Local\Temp\prebuildify\node\20.0.0\deps\v8\include;C:\Code\window-handle-js\node_modules\node-addon-api;..\src\cpp;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
133
+ <PreprocessorDefinitions>NODE_GYP_MODULE_NAME=node-native-win-utils;USING_UV_SHARED=1;USING_V8_SHARED=1;V8_DEPRECATION_WARNINGS=1;V8_DEPRECATION_WARNINGS;V8_IMMINENT_DEPRECATION_WARNINGS;_GLIBCXX_USE_CXX11_ABI=1;WIN32;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;_HAS_EXCEPTIONS=0;OPENSSL_NO_PINSHARED;OPENSSL_THREADS;NAPI_CPP_EXCEPTIONS;_CRT_SECURE_NO_WARNINGS;BUILDING_NODE_EXTENSION;HOST_BINARY=&quot;node.exe&quot;;%(PreprocessorDefinitions);%(PreprocessorDefinitions)</PreprocessorDefinitions>
134
+ </ResourceCompile>
135
+ </ItemDefinitionGroup>
136
+ <ItemGroup>
137
+ <None Include="..\binding.gyp"/>
138
+ </ItemGroup>
139
+ <ItemGroup>
140
+ <ClCompile Include="..\src\cpp\main.cpp">
141
+ <ObjectFileName>$(IntDir)\src\cpp\main.obj</ObjectFileName>
142
+ </ClCompile>
143
+ <ClCompile Include="C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\src\win_delay_load_hook.cc"/>
144
+ </ItemGroup>
145
+ <ItemGroup>
146
+ <ProjectReference Include="node_modules\node-addon-api\nothing.vcxproj">
147
+ <Project>{7137135D-2036-DDE1-E426-9B03A16079A8}</Project>
148
+ <ReferenceOutputAssembly>false</ReferenceOutputAssembly>
149
+ </ProjectReference>
150
+ </ItemGroup>
151
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets"/>
152
+ <Import Project="$(VCTargetsPath)\BuildCustomizations\masm.targets"/>
153
+ <ImportGroup Label="ExtensionTargets"/>
154
+ </Project>
@@ -0,0 +1,52 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3
+ <ItemGroup>
4
+ <Filter Include="..">
5
+ <UniqueIdentifier>{739DB09A-CC57-A953-A6CF-F64FA08E4FA7}</UniqueIdentifier>
6
+ </Filter>
7
+ <Filter Include="..\src">
8
+ <UniqueIdentifier>{8CDEE807-BC53-E450-C8B8-4DEBB66742D4}</UniqueIdentifier>
9
+ </Filter>
10
+ <Filter Include="..\src\cpp">
11
+ <UniqueIdentifier>{9938E6E5-8F6B-7587-726E-6CE774E44BEE}</UniqueIdentifier>
12
+ </Filter>
13
+ <Filter Include="C:">
14
+ <UniqueIdentifier>{7B735499-E5DD-1C2B-6C26-70023832A1CF}</UniqueIdentifier>
15
+ </Filter>
16
+ <Filter Include="C:\Program Files">
17
+ <UniqueIdentifier>{92EF4BA8-6BC2-65D1-451F-28EBD4AE726A}</UniqueIdentifier>
18
+ </Filter>
19
+ <Filter Include="C:\Program Files\nodejs">
20
+ <UniqueIdentifier>{A3C8E949-BCF6-0C67-6656-340A2A097708}</UniqueIdentifier>
21
+ </Filter>
22
+ <Filter Include="C:\Program Files\nodejs\node_modules">
23
+ <UniqueIdentifier>{56DF7A98-063D-FB9D-485C-089023B4C16A}</UniqueIdentifier>
24
+ </Filter>
25
+ <Filter Include="C:\Program Files\nodejs\node_modules\npm">
26
+ <UniqueIdentifier>{741E0E76-39B2-B1AB-9FA1-F1A20B16F295}</UniqueIdentifier>
27
+ </Filter>
28
+ <Filter Include="C:\Program Files\nodejs\node_modules\npm\node_modules">
29
+ <UniqueIdentifier>{56DF7A98-063D-FB9D-485C-089023B4C16A}</UniqueIdentifier>
30
+ </Filter>
31
+ <Filter Include="C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp">
32
+ <UniqueIdentifier>{77348C0E-2034-7791-74D5-63C077DF5A3B}</UniqueIdentifier>
33
+ </Filter>
34
+ <Filter Include="C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\src">
35
+ <UniqueIdentifier>{8CDEE807-BC53-E450-C8B8-4DEBB66742D4}</UniqueIdentifier>
36
+ </Filter>
37
+ <Filter Include="..">
38
+ <UniqueIdentifier>{739DB09A-CC57-A953-A6CF-F64FA08E4FA7}</UniqueIdentifier>
39
+ </Filter>
40
+ </ItemGroup>
41
+ <ItemGroup>
42
+ <ClCompile Include="..\src\cpp\main.cpp">
43
+ <Filter>..\src\cpp</Filter>
44
+ </ClCompile>
45
+ <ClCompile Include="C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\src\win_delay_load_hook.cc">
46
+ <Filter>C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\src</Filter>
47
+ </ClCompile>
48
+ <None Include="..\binding.gyp">
49
+ <Filter>..</Filter>
50
+ </None>
51
+ </ItemGroup>
52
+ </Project>
@@ -0,0 +1,27 @@
1
+ /// <reference types="node" />
2
+ import EventEmitter = require("events");
3
+ type WindowData = {
4
+ width: number;
5
+ height: number;
6
+ x: number;
7
+ y: number;
8
+ };
9
+ export type GetWindowData = (windowName: string) => WindowData;
10
+ export type CaptureWindow = (windowName: string, outputPath: string) => void;
11
+ export type KeyDownHandler = (callback: (keyCode: number) => void) => void;
12
+ export type KeyUpHandler = (callback: (keyCode: number) => void) => void;
13
+ export interface KeyListener extends EventEmitter {
14
+ on(event: "keyDown", callback: (data: {
15
+ keyCode: number;
16
+ keyName: string;
17
+ }) => void): this;
18
+ on(event: "keyUp", callback: (data: {
19
+ keyCode: number;
20
+ keyName: string;
21
+ }) => void): this;
22
+ }
23
+ declare const keyDownHandler: KeyDownHandler, keyUpHandler: KeyUpHandler, getWindowData: GetWindowData, captureWindow: CaptureWindow;
24
+ export declare class KeyListener extends EventEmitter {
25
+ constructor();
26
+ }
27
+ export { keyDownHandler, keyUpHandler, getWindowData, captureWindow };
package/dist/index.js ADDED
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.captureWindow = exports.getWindowData = exports.keyUpHandler = exports.keyDownHandler = exports.KeyListener = void 0;
7
+ const EventEmitter = require("events");
8
+ const path_1 = __importDefault(require("path"));
9
+ const bindings = require("node-gyp-build")(path_1.default.resolve(__dirname, ".."));
10
+ const keyCodes_1 = __importDefault(require("./keyCodes"));
11
+ const { keyDownHandler, keyUpHandler, getWindowData, captureWindow, } = bindings;
12
+ exports.keyDownHandler = keyDownHandler;
13
+ exports.keyUpHandler = keyUpHandler;
14
+ exports.getWindowData = getWindowData;
15
+ exports.captureWindow = captureWindow;
16
+ class KeyListener extends EventEmitter {
17
+ constructor() {
18
+ super();
19
+ keyDownHandler((keyCode) => {
20
+ const keyName = keyCodes_1.default.get(keyCode.toString());
21
+ this.emit("keyDown", {
22
+ keyCode,
23
+ keyName,
24
+ });
25
+ });
26
+ keyUpHandler((keyCode) => {
27
+ const keyName = keyCodes_1.default.get(keyCode.toString());
28
+ this.emit("keyUp", {
29
+ keyCode,
30
+ keyName,
31
+ });
32
+ });
33
+ }
34
+ }
35
+ exports.KeyListener = KeyListener;
@@ -0,0 +1,2 @@
1
+ declare const _default: Map<string, string>;
2
+ export default _default;
@@ -0,0 +1,102 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = new Map(Object.entries({
4
+ 8: "Backspace",
5
+ 9: "Tab",
6
+ 13: "Enter",
7
+ 16: "Shift",
8
+ 17: "Ctrl",
9
+ 18: "Alt",
10
+ 20: "CapsLock",
11
+ 27: "Escape",
12
+ 32: "Space",
13
+ 33: "PageUp",
14
+ 34: "PageDown",
15
+ 35: "End",
16
+ 36: "Home",
17
+ 37: "ArrowLeft",
18
+ 38: "ArrowUp",
19
+ 39: "ArrowRight",
20
+ 40: "ArrowDown",
21
+ 45: "Insert",
22
+ 46: "Delete",
23
+ 48: "0",
24
+ 49: "1",
25
+ 50: "2",
26
+ 51: "3",
27
+ 52: "4",
28
+ 53: "5",
29
+ 54: "6",
30
+ 55: "7",
31
+ 56: "8",
32
+ 57: "9",
33
+ 65: "A",
34
+ 66: "B",
35
+ 67: "C",
36
+ 68: "D",
37
+ 69: "E",
38
+ 70: "F",
39
+ 71: "G",
40
+ 72: "H",
41
+ 73: "I",
42
+ 74: "J",
43
+ 75: "K",
44
+ 76: "L",
45
+ 77: "M",
46
+ 78: "N",
47
+ 79: "O",
48
+ 80: "P",
49
+ 81: "Q",
50
+ 82: "R",
51
+ 83: "S",
52
+ 84: "T",
53
+ 85: "U",
54
+ 86: "V",
55
+ 87: "W",
56
+ 88: "X",
57
+ 89: "Y",
58
+ 90: "Z",
59
+ 91: "MetaLeft",
60
+ 92: "MetaRight",
61
+ 93: "ContextMenu",
62
+ 96: "Numpad0",
63
+ 97: "Numpad1",
64
+ 98: "Numpad2",
65
+ 99: "Numpad3",
66
+ 100: "Numpad4",
67
+ 101: "Numpad5",
68
+ 102: "Numpad6",
69
+ 103: "Numpad7",
70
+ 104: "Numpad8",
71
+ 105: "Numpad9",
72
+ 106: "NumpadMultiply",
73
+ 107: "NumpadAdd",
74
+ 109: "NumpadSubtract",
75
+ 110: "NumpadDecimal",
76
+ 111: "NumpadDivide",
77
+ 112: "F1",
78
+ 113: "F2",
79
+ 114: "F3",
80
+ 115: "F4",
81
+ 116: "F5",
82
+ 117: "F6",
83
+ 118: "F7",
84
+ 119: "F8",
85
+ 120: "F9",
86
+ 121: "F10",
87
+ 122: "F11",
88
+ 123: "F12",
89
+ 144: "NumLock",
90
+ 145: "ScrollLock",
91
+ 186: "Semicolon",
92
+ 187: "Equal",
93
+ 188: "Comma",
94
+ 189: "Minus",
95
+ 190: "Period",
96
+ 191: "Slash",
97
+ 192: "Backquote",
98
+ 219: "BracketLeft",
99
+ 220: "Backslash",
100
+ 221: "BracketRight",
101
+ 222: "Quote",
102
+ }));
package/package.json ADDED
@@ -0,0 +1,33 @@
1
+ {
2
+ "name": "node-native-win-utils",
3
+ "version": "1.0.0",
4
+ "author": "RynerNO",
5
+ "license": "MIT",
6
+ "description": "Native addon for Node.js providing utility operations on Windows systems",
7
+ "keywords": [
8
+ "node.js",
9
+ "native",
10
+ "addon",
11
+ "Windows",
12
+ "utility",
13
+ "key event",
14
+ "window",
15
+ "screenshot",
16
+ "capture",
17
+ "listener"
18
+ ],
19
+ "main": "dist/index.js",
20
+ "types": "dist/index.d.ts",
21
+ "gypfile": true,
22
+ "scripts": {
23
+ "install": "node-gyp-build",
24
+ "build": "node-gyp clean && prebuildify --napi && tsc"
25
+ },
26
+ "dependencies": {
27
+ "node-addon-api": "^6.1.0",
28
+ "node-gyp-build": "^4.6.0"
29
+ },
30
+ "devDependencies": {
31
+ "@types/node": "^20.2.5"
32
+ }
33
+ }