microsoft/TypeAgent

Public

mirrored fromhttps://github.com/microsoft/TypeAgentAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
copilot/remove-deprecated-dependencies

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

dotnet/penLauncher/Program.cs

81lines · modecode

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4using System.Diagnostics;
5using System.IO.Pipes;
6using System.Net;
7using System.Net.Http;
8using System.Reflection;
9using Microsoft.Win32;
10
11namespace PenLauncher;
12
13/// <summary>
14/// Program that either registers or unregisters itself as a click note handler.
15/// Upon click note calls a local HTTP server with a GET request.
16/// </summary>
17internal class Program
18{
19 /// <summary>
20 /// The click note registry key
21 /// </summary>
22 private const string CLICK_NOTE_KEY = "Software\\Microsoft\\Windows\\CurrentVersion\\ClickNote\\UserCustomization\\SingleClickBelowLock";
23
24 static void Main(string[] args)
25 {
26 if (!OperatingSystem.IsWindows())
27 {
28 Console.WriteLine("The application is only supported on Windows.");
29 return;
30 }
31
32 if (args.Length == 1)
33 {
34 switch (args[0])
35 {
36 case "--register":
37
38 Debug.Assert(Environment.ProcessPath != null);
39
40 RegistryKey key = Registry.CurrentUser.CreateSubKey(CLICK_NOTE_KEY, true);
41 key.SetValue("CustomAppPath", Environment.ProcessPath);
42 key.SetValue("Override", 0x3);
43 key.SetValue("PenWorkspaceVerb", 0x0);
44
45 break;
46
47 case "--unregister":
48
49 Registry.CurrentUser.DeleteSubKey(CLICK_NOTE_KEY);
50
51 break;
52
53 default:
54 Console.WriteLine($"The supplied command '{args[0]}' is not recognized.");
55 break;
56 }
57 }
58 else if (args.Length == 0)
59 {
60
61 try
62 {
63 using NamedPipeClientStream pipeClient = new NamedPipeClientStream(".", "TypeAgent\\speech", PipeDirection.Out);
64 pipeClient.Connect();
65
66 using StreamWriter writer = new StreamWriter(pipeClient) { AutoFlush = true };
67 string message = "triggerRecognitionOnce";
68 writer.Write(message);
69 Console.WriteLine($"Sent to server: {message}");
70 }
71 catch (Exception ex)
72 {
73 Console.WriteLine("Unable to connect to the pipe.");
74 }
75 }
76 else
77 {
78 Console.WriteLine("Unexpected command line arguments.");
79 }
80 }
81}
82