Skip to content

Commit 3d616fe

Browse files
Moving desktop app from website
1 parent 178b1e4 commit 3d616fe

File tree

95 files changed

+13279
-1
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

95 files changed

+13279
-1
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,3 +348,9 @@ MigrationBackup/
348348

349349
# Ionide (cross platform F# VS Code tools) working folder
350350
.ionide/
351+
352+
.idea/
353+
354+
## Custom
355+
streaming-tools/WindowsKeyboardHook/WindowsKeyboardHook.xml
356+
streaming-tools/streaming-tools/streaming-tools.xml

README.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,12 @@
1-
# notification-app-dot-net
1+
# Notification App
2+
3+
## Getting TTS Voices
4+
5+
1. Open regedit
6+
1. Navigate to `Computer\HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Speech_OneCore\Voices\Tokens`
7+
1. Export the ones you want
8+
1. Navigate to `Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\Voices\Tokens`
9+
1. Edit the exported regedit file changing `HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Speech_OneCore\Voices\Tokens` to `HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\Voices\Tokens`
10+
1. Run the regedit file
11+
12+
TODO: Send pull request to `https://github.com/dotnet/runtime`

doc/cathy-oauth.png

66.5 KB
Loading

go.bat

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
echo off
2+
3+
:: Get the version number
4+
FOR /F "tokens=* USEBACKQ" %%F IN (`git tag --points-at HEAD`) DO (SET version=%%F)
5+
6+
if [%version%]==[] (
7+
echo This build doesn't have a tag
8+
exit 1
9+
)
10+
11+
echo on
12+
call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\Tools\VsDevCmd.bat"
13+
dotnet build streaming-tools/streaming-tools.sln /p:Configuration=Release /p:Platform="Any CPU"
14+
xcopy streaming-tools\streaming-tools\bin\Release\net5.0 "v%version%\streaming-tools\" /s /e
15+
xcopy streaming-tools\WindowsKeyboardHook\bin\Release\net5.0 "v%version%\WindowsKeyboardHook\" /s /e
16+
17+
"C:\Program Files\7-Zip\7z.exe" a "v%version%.zip" "v%version%"

streaming-tools/.editorconfig

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[*.cs]
2+
3+
# CA1416: Validate platform compatibility
4+
dotnet_diagnostic.CA1416.severity = none
5+
6+
# SA1200: Using directives should be placed correctly
7+
dotnet_diagnostic.SA1200.severity = none
8+
9+
# SA1300: Element should begin with upper-case letter
10+
dotnet_diagnostic.SA1300.severity = none
11+
12+
# Default severity for all analyzer diagnostics
13+
dotnet_analyzer_diagnostic.severity = none
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
namespace WindowsKeyboardHook {
2+
using System;
3+
using System.Diagnostics;
4+
using System.Runtime.InteropServices;
5+
using System.Threading;
6+
using PInvoke;
7+
8+
/// <summary>
9+
/// A console application that hooks into the global keyboard keystrokes on the OS and outputs them to STDOUT.
10+
/// </summary>
11+
/// <remarks>
12+
/// See:
13+
/// <see href="https://docs.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes?redirectedfrom=MSDN" />
14+
/// </remarks>
15+
internal class Program {
16+
/// <summary>
17+
/// Information on what kind of event it is.
18+
/// </summary>
19+
public enum KeyboardMessage {
20+
/// <summary>
21+
/// The key was pressed down.
22+
/// </summary>
23+
KeyDown = 0x100,
24+
25+
/// <summary>
26+
/// The key was released after being pressed down.
27+
/// </summary>
28+
KeyUp = 0x101,
29+
30+
/// <summary>
31+
/// No idea.
32+
/// </summary>
33+
SysKeyDown = 0x104,
34+
35+
/// <summary>
36+
/// Don't ask me.
37+
/// </summary>
38+
SysKeyUp = 0x105
39+
}
40+
41+
/// <summary>
42+
/// The pointer to the hook we added.
43+
/// </summary>
44+
private static User32.SafeHookHandle hook;
45+
46+
/// <summary>
47+
/// The event invoked when a key is pressed.
48+
/// </summary>
49+
/// <param name="nCode">The code.</param>
50+
/// <param name="wParam">The <seealso cref="KeyboardMessage" />.</param>
51+
/// <param name="lParam">The <seealso cref="KeyboardLowLevelHookStruct" />.</param>
52+
/// <returns>The next hook that should be called.</returns>
53+
private static int KeystrokeCallback(int nCode, IntPtr wParam, IntPtr lParam) {
54+
var keyboardEvent = Marshal.PtrToStructure<KeyboardLowLevelHookStruct>(lParam);
55+
var whatHappened = (KeyboardMessage)wParam;
56+
57+
if (whatHappened == KeyboardMessage.KeyDown) {
58+
Console.WriteLine(keyboardEvent.vkCode);
59+
}
60+
61+
return User32.CallNextHookEx(Program.hook.DangerousGetHandle(), nCode, wParam, lParam);
62+
}
63+
64+
/// <summary>
65+
/// The main entry point to the application that listens to the keystrokes across the entire OS.
66+
/// </summary>
67+
/// <param name="args">We don't use arguments.</param>
68+
private static void Main(string[] args) {
69+
var pid = -1;
70+
if (args.Length > 0) {
71+
int.TryParse(args[0], out pid);
72+
}
73+
74+
var thread = new Thread(
75+
() => {
76+
while (true) {
77+
if (-1 == pid) {
78+
return;
79+
}
80+
81+
try {
82+
var process = Process.GetProcessById(pid);
83+
if (process.HasExited) {
84+
Environment.Exit(0);
85+
return;
86+
}
87+
} catch (Exception) {
88+
Environment.Exit(0);
89+
return;
90+
}
91+
92+
Thread.Sleep(500);
93+
}
94+
});
95+
thread.IsBackground = true;
96+
thread.Start();
97+
98+
// Set a hook.
99+
Program.hook = User32.SetWindowsHookEx(User32.WindowsHookType.WH_KEYBOARD_LL, Program.KeystrokeCallback, IntPtr.Zero, 0);
100+
101+
unsafe {
102+
// Buffer the messages.
103+
User32.MSG message;
104+
while (0 != User32.GetMessage(&message, IntPtr.Zero, 0, 0)) { }
105+
}
106+
}
107+
108+
/// <summary>
109+
/// The structure representing the key pressed.
110+
/// </summary>
111+
[StructLayout(LayoutKind.Sequential)]
112+
internal struct KeyboardLowLevelHookStruct {
113+
/// <summary>
114+
/// The keystroke.
115+
/// </summary>
116+
public int vkCode;
117+
118+
/// <summary>
119+
/// The scan code.
120+
/// </summary>
121+
public int scanCode;
122+
123+
/// <summary>
124+
/// The flags.
125+
/// </summary>
126+
public int flags;
127+
128+
/// <summary>
129+
/// The time the key was pressed.
130+
/// </summary>
131+
public int time;
132+
133+
/// <summary>
134+
/// The extra info.
135+
/// </summary>
136+
public IntPtr dwExtraInfo;
137+
}
138+
}
139+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"profiles": {
3+
"WindowsKeyboardHook": {
4+
"commandName": "Project",
5+
"commandLineArgs": "123"
6+
}
7+
}
8+
}

0 commit comments

Comments
 (0)