@@ -27,6 +27,7 @@ The system launches Microsoft Copilot hardware key providers that implement Pres
2727The following example shows the ** uap: Extension ** registering the URI scheme "myapp-copilothotkey".
2828
2929``` xml
30+ <!-- Package.appxmanifest -->
3031...
3132 xmlns:uap3="http://schemas.microsoft.com/appx/manifest/uap/windows10/3"
3233...
@@ -50,6 +51,8 @@ Inside of the **uap3:AppExtension** element, add a [uap3:Properties](/uwp/schema
5051The following example shows a Copilot hot key provider registration with support for PressAndHoldAndRelease.
5152
5253``` xml
54+ <!-- Package.appxmanifest -->
55+
5356<Extensions >
5457 ...
5558 <uap3 : Extension Category =" windows.appExtension" >
@@ -67,5 +70,129 @@ The following example shows a Copilot hot key provider registration with support
6770 ...
6871```
6972
70- ## Handle app activation
73+ ## Handle URI activation
74+
75+ ``` csharp
76+ // App.xaml.cs
77+
78+ private void OnActivated ()
79+ {
80+
81+ AppActivationArguments args = AppInstance .GetCurrent ().GetActivatedEventArgs ();
82+ if (args .Kind == ExtendedActivationKind .Launch )
83+ {
84+ // launched by other means (possibly by copilot button press)
85+ // implement primary UI
86+
87+ }
88+ else if (args .Kind == ExtendedActivationKind .Protocol )
89+ {
90+ var protocolArgs = (Windows .ApplicationModel .Activation .ProtocolActivatedEventArgs )args .Data ;
91+ WwwFormUrlDecoder decoderEntries = new WwwFormUrlDecoder (protocolArgs .Uri .Query );
92+ string state = Uri .UnescapeDataString (decoderEntries .GetFirstValueByName (" state" ));
93+
94+ if (state == " Down" )
95+ {
96+ // Implement press and hold begin activation logic:
97+ // Start microphone capture
98+ // Show no activate a window indicating audio capture is happening
99+ }
100+ else if (state == " Up" )
101+ {
102+ // Implemented press and hold finished logic
103+ // Stop microphone capture
104+ // Indicate audio capture has stopped
105+ // Send the audio to the LLM
106+ }
107+
108+ }
109+ }
110+ ```
111+
112+ ## Handle fast path invocation
113+
114+ ``` xml
115+ <!-- Package.appxmanifest -->
116+
117+ <uap3 : Extension Category =" windows.appExtension" >
118+ <uap3 : AppExtension Name =" com.microsoft.windows.copilotkeyprovider"
119+ Id =" MyAppId"
120+ DisplayName =" App display name"
121+ Description =" App description"
122+ PublicFolder =" Public" >
123+ <uap3 : Properties >
124+ <SingleTap FastPathValue =" 0" />
125+ <PressAndHoldStart FastPathValue =" 1" >myapp-copilothotkey://?state=Down</PressAndHoldStart >
126+ <PressAndHoldStop FastPathValue =" 2" >myapp-copilothotkey://?state=Up</PressAndHoldStop >
127+ </uap3 : Properties >
128+ </uap3 : AppExtension >
129+ </uap3 : Extension >
130+ ```
131+
132+ ``` csharp
133+ // App.xaml.cs
134+
135+ protected override void OnLaunched (Microsoft .UI .Xaml .LaunchActivatedEventArgs args )
136+ {
137+ .. .
138+ var hwnd = WinRT .Interop .WindowNative .GetWindowHandle (m_window );
139+
140+ IPropertyStore propertyStore ;
141+ int hr = SHGetPropertyStoreForWindow (hwnd , ref IID_IPropertyStore , out propertyStore );
142+ PropVariant propVar = new PropVariant ();
143+ propVar .vt = (ushort )VarEnum .VT_UI4 ;
144+ propVar .ulVal = MainWindow .CopilotHotKeyFastpathMessage ;
145+ propertyStore .SetValue (PKEY_Shell_CopilotKeyProviderFastPathMessage , ref propVar );
146+ propertyStore .Commit ();
147+ .. .
148+ }
149+ ```
150+
151+ ``` csharp
152+ // MainWindow.xaml.cs
153+
154+ public MainWindow ()
155+ {
156+ .. .
157+ var hWndMain = WinRT .Interop .WindowNative .GetWindowHandle (this );
158+ Microsoft .UI .Windowing .AppWindow appWindow = AppWindow ;
159+
160+ SubClassDelegate = new SUBCLASSPROC (WindowSubClass );
161+ bool bRet = SetWindowSubclass ((int )appWindow .Id .Value , SubClassDelegate , 0 , 0 );
162+ .. .
163+ }
164+ ```
165+
166+ ``` csharp
167+ private int WindowSubClass (IntPtr hWnd , uint uMsg , IntPtr wParam ,
168+ IntPtr lParam , IntPtr uIdSubclass , uint dwRefData )
169+ {
170+ switch (uMsg )
171+ {
172+ case CopilotHotKeyFastpathMessage :
173+ {
174+ switch (lParam )
175+ {
176+ case 0 :
177+ // Copilot key press, show our window
178+ PInvoke .ShowWindow ((HWND )hWnd , SHOW_WINDOW_CMD .SW_SHOW );
179+ break ;
180+ case 1 :
181+ // Copilot key press and hold start, show our window without activation
182+ // and start listening
183+ PInvoke .ShowWindow ((HWND )hWnd , SHOW_WINDOW_CMD .SW_SHOWNA );
184+ // Start microphone recording
185+ break ;
186+ case 2 :
187+ // Copilot key press and hold stop, stop listening and send query
188+ break ;
189+ }
190+ }
191+ return 0 ;
192+ }
193+
194+ return PInvoke .DefSubclassProc ((HWND )hWnd , uMsg , wParam , lParam );
195+
196+ }
197+ ```
71198
0 commit comments