• 0

[C#] How should I use ITaskbarList and how to detect program start?


Question

Hi, I cannot figure out and I also had no luck with google so I'm asking for your help...

I'd like to edit the taskbar buttons and I know (found in the VS Documentation) that I need the ITaskbarList interface but I don't no quite how to use such a unmanaged interface in C#... can you help?

The second question is: how can I detect that a program was launched (or started) in C#? I tried with a lot of WM_messages but I just can't catch this event... I also tested some hooks and so on, but it seems to catch only the program's own WM_CEATE message... how can I catch other programs' messages in my app?

The third question: how can I catch mouse move event outside of my app? As soon as the cursor leaves my app I receive no new messages from the system... there has to be some way to do it, like in SnagIt for example etc

7 answers to this question

Recommended Posts

  • 0

ok, so let's forget C# for a while... I'd like to know the concept how it works...

this is exacly what I've tried to do, I used the SetWindowsHookEx funtion and I hooked all the possible functions but they catch only messages of my own program... I suppose I use the wrong window handles, I mean this hwnd variables, but I can't find the right one

do you know what else do I need to be able to catch all messages? like moving the cursor outside of my app, or that some other program was started?

  • 0

You need to setup global hooks. This is the code I use to check for system events. Included are events for window creating / destroying, minimizing and foreground changes. It should give a good example if you need to include something else.

using System;
using System.ComponentModel;
using System.Runtime.InteropServices;

namespace Four13Designs
{
	public delegate void OnWindowMinimizeStartDelegate(IntPtr hWnd);
	public delegate void OnWindowMinimizeEndDelegate(IntPtr hWnd);
	public delegate void OnWindowForegroundChangedDelegate(IntPtr hWnd);
	public delegate void OnWindowDestroyDelegate(IntPtr hWnd);
	public delegate void OnWindowCreateDelegate(IntPtr hWnd);

	public sealed class Hooks
	{
		#region Windows API

		private enum SystemEvents : uint
		{
			EVENT_SYSTEM_CREATE = 3,
			EVENT_SYSTEM_DESTROY = 0x8001,
			EVENT_SYSTEM_MINIMIZESTART = 0x0016,
			EVENT_SYSTEM_MINIMIZEEND = 0x0017,
			EVENT_SYSTEM_FOREGROUND = 0x0003
		}

		private const uint WINEVENT_OUTOFCONTEXT = 0x0000;

		private delegate void WinEventDelegate(
			IntPtr hWinEventHook,
			uint eventType,
			IntPtr hWnd,
			int idObject,
			int idChild,
			uint dwEventThread,
			uint dwmsEventTime);

		[DllImport("User32.dll", SetLastError = true)]
		private static extern IntPtr SetWinEventHook(
			uint eventMin,
			uint eventMax,
			IntPtr hmodWinEventProc,
			WinEventDelegate lpfnWinEventProc,
			uint idProcess,
			uint idThread,
			uint dwFlags);

		[DllImport("user32.dll")]
		private static extern bool UnhookWinEvent(
			IntPtr hWinEventHook
			);

		#endregion

		private WinEventDelegate dEvent;
		private IntPtr pHook;
		public OnWindowMinimizeStartDelegate OnWindowMinimizeStart;
		public OnWindowMinimizeEndDelegate OnWindowMinimizeEnd;
		public OnWindowForegroundChangedDelegate OnWindowForegroundChanged;
		public OnWindowDestroyDelegate OnWindowDestroy;
		public OnWindowCreateDelegate OnWindowCreate;

		public Hooks()
		{
			dEvent = this.WinEvent;
			pHook = SetWinEventHook(
				(uint)SystemEvents.EVENT_SYSTEM_FOREGROUND,
				(uint)SystemEvents.EVENT_SYSTEM_DESTROY,
				IntPtr.Zero,
				dEvent,
				0,
				0,
				WINEVENT_OUTOFCONTEXT
				);

			if (IntPtr.Zero.Equals(pHook)) throw new Win32Exception();

			GC.KeepAlive(dEvent);
		}

		private void WinEvent(IntPtr hWinEventHook, uint eventType, IntPtr hWnd, int idObject, int idChild, uint dwEventThread, uint dwmsEventTime)
		{
			switch (eventType)
			{
				case (uint)SystemEvents.EVENT_SYSTEM_DESTROY:
					if (OnWindowDestroy != null) OnWindowDestroy(hWnd);
					break;
				case (uint)SystemEvents.EVENT_SYSTEM_FOREGROUND:
					if (OnWindowForegroundChanged != null) OnWindowForegroundChanged(hWnd);
					break;
				case (uint)SystemEvents.EVENT_SYSTEM_MINIMIZESTART:
					if (OnWindowMinimizeStart != null) OnWindowMinimizeStart(hWnd);
					break;
				case (uint)SystemEvents.EVENT_SYSTEM_MINIMIZEEND:
					if (OnWindowMinimizeEnd != null) OnWindowMinimizeEnd(hWnd);
					break;
				default:
					break;
			}
		}

		~Hooks()
		{
			if (!IntPtr.Zero.Equals(pHook)) UnhookWinEvent(pHook);
			pHook = IntPtr.Zero;
			dEvent = null;

			OnWindowCreate = null;
			OnWindowDestroy = null;
			OnWindowForegroundChanged = null;
			OnWindowMinimizeStart = null;
			OnWindowMinimizeEnd = null;
		}
	}
}

And this is the code I use for mouse / keyboard hooking:

using System;
using System.Runtime.InteropServices;
using System.Reflection;
using System.Threading;
using System.Windows.Forms;
using System.ComponentModel;

namespace gma.System.Windows
{
	/// <summary>
	/// This class allows you to tap keyboard and mouse and / or to detect their activity even when an 
	/// application runes in background or does not have any user interface at all. This class raises 
	/// common .NET events with KeyEventArgs and MouseEventArgs so you can easily retrive any information you need.
	/// </summary>
	public class UserActivityHook
	{
		#region Windows structure definitions

		/// <summary>
		/// The POINT structure defines the x- and y- coordinates of a point. 
		/// </summary>
		/// <remarks>
		/// http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/rectangl_0tiq.asp
		/// </remarks>
		[StructLayout(LayoutKind.Sequential)]
		private class POINT
		{
			/// <summary>
			/// Specifies the x-coordinate of the point. 
			/// </summary>
			public int x;
			/// <summary>
			/// Specifies the y-coordinate of the point. 
			/// </summary>
			public int y;
		}

		/// <summary>
		/// The MOUSEHOOKSTRUCT structure contains information about a mouse event passed to a WH_MOUSE hook procedure, MouseProc. 
		/// </summary>
		/// <remarks>
		/// http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/windowing/hooks/hookreference/hookstructures/cwpstruct.asp
		/// </remarks>
		[StructLayout(LayoutKind.Sequential)]
		private class MouseHookStruct
		{
			/// <summary>
			/// Specifies a POINT structure that contains the x- and y-coordinates of the cursor, in screen coordinates. 
			/// </summary>
			public POINT pt;
			/// <summary>
			/// Handle to the window that will receive the mouse message corresponding to the mouse event. 
			/// </summary>
			public int hwnd;
			/// <summary>
			/// Specifies the hit-test value. For a list of hit-test values, see the description of the WM_NCHITTEST message. 
			/// </summary>
			public int wHitTestCode;
			/// <summary>
			/// Specifies extra information associated with the message. 
			/// </summary>
			public int dwExtraInfo;
		}

		/// <summary>
		/// The MSLLHOOKSTRUCT structure contains information about a low-level keyboard input event. 
		/// </summary>
		[StructLayout(LayoutKind.Sequential)]
		private class MouseLLHookStruct
		{
			/// <summary>
			/// Specifies a POINT structure that contains the x- and y-coordinates of the cursor, in screen coordinates. 
			/// </summary>
			public POINT pt;
			/// <summary>
			/// If the message is WM_MOUSEWHEEL, the high-order word of this member is the wheel delta. 
			/// The low-order word is reserved. A positive value indicates that the wheel was rotated forward, 
			/// away from the user; a negative value indicates that the wheel was rotated backward, toward the user. 
			/// One wheel click is defined as WHEEL_DELTA, which is 120. 
			///If the message is WM_XBUTTONDOWN, WM_XBUTTONUP, WM_XBUTTONDBLCLK, WM_NCXBUTTONDOWN, WM_NCXBUTTONUP,
			/// or WM_NCXBUTTONDBLCLK, the high-order word specifies which X button was pressed or released, 
			/// and the low-order word is reserved. This value can be one or more of the following values. Otherwise, mouseData is not used. 
			///XBUTTON1
			///The first X button was pressed or released.
			///XBUTTON2
			///The second X button was pressed or released.
			/// </summary>
			public int mouseData;
			/// <summary>
			/// Specifies the event-injected flag. An application can use the following value to test the mouse flags. Value Purpose 
			///LLMHF_INJECTED Test the event-injected flag.  
			///0
			///Specifies whether the event was injected. The value is 1 if the event was injected; otherwise, it is 0.
			///1-15
			///Reserved.
			/// </summary>
			public int flags;
			/// <summary>
			/// Specifies the time stamp for this message.
			/// </summary>
			public int time;
			/// <summary>
			/// Specifies extra information associated with the message. 
			/// </summary>
			public int dwExtraInfo;
		}


		/// <summary>
		/// The KBDLLHOOKSTRUCT structure contains information about a low-level keyboard input event. 
		/// </summary>
		/// <remarks>
		/// http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/windowing/hooks/hookreference/hookstructures/cwpstruct.asp
		/// </remarks>
		[StructLayout(LayoutKind.Sequential)]
		private class KeyboardHookStruct
		{
			/// <summary>
			/// Specifies a virtual-key code. The code must be a value in the range 1 to 254. 
			/// </summary>
			public int vkCode;
			/// <summary>
			/// Specifies a hardware scan code for the key. 
			/// </summary>
			public int scanCode;
			/// <summary>
			/// Specifies the extended-key flag, event-injected flag, context code, and transition-state flag.
			/// </summary>
			public int flags;
			/// <summary>
			/// Specifies the time stamp for this message.
			/// </summary>
			public int time;
			/// <summary>
			/// Specifies extra information associated with the message. 
			/// </summary>
			public int dwExtraInfo;
		}
		#endregion

		#region Windows function imports
		/// <summary>
		/// The SetWindowsHookEx function installs an application-defined hook procedure into a hook chain. 
		/// You would install a hook procedure to monitor the system for certain types of events. These events 
		/// are associated either with a specific thread or with all threads in the same desktop as the calling thread. 
		/// </summary>
		/// <param name="idHook">
		/// [in] Specifies the type of hook procedure to be installed. This parameter can be one of the following values.
		/// </param>
		/// <param name="lpfn">
		/// [in] Pointer to the hook procedure. If the dwThreadId parameter is zero or specifies the identifier of a 
		/// thread created by a different process, the lpfn parameter must point to a hook procedure in a dynamic-link 
		/// library (DLL). Otherwise, lpfn can point to a hook procedure in the code associated with the current process.
		/// </param>
		/// <param name="hMod">
		/// [in] Handle to the DLL containing the hook procedure pointed to by the lpfn parameter. 
		/// The hMod parameter must be set to NULL if the dwThreadId parameter specifies a thread created by 
		/// the current process and if the hook procedure is within the code associated with the current process. 
		/// </param>
		/// <param name="dwThreadId">
		/// [in] Specifies the identifier of the thread with which the hook procedure is to be associated. 
		/// If this parameter is zero, the hook procedure is associated with all existing threads running in the 
		/// same desktop as the calling thread. 
		/// </param>
		/// <returns>
		/// If the function succeeds, the return value is the handle to the hook procedure.
		/// If the function fails, the return value is NULL. To get extended error information, call GetLastError.
		/// </returns>
		/// <remarks>
		/// http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/windowing/hooks/hookreference/hookfunctions/setwindowshookex.asp
		/// </remarks>
		[DllImport("user32.dll", CharSet = CharSet.Auto,
		   CallingConvention = CallingConvention.StdCall, SetLastError = true)]
		private static extern int SetWindowsHookEx(
			int idHook,
			HookProc lpfn,
			IntPtr hMod,
			int dwThreadId);

		/// <summary>
		/// The UnhookWindowsHookEx function removes a hook procedure installed in a hook chain by the SetWindowsHookEx function. 
		/// </summary>
		/// <param name="idHook">
		/// [in] Handle to the hook to be removed. This parameter is a hook handle obtained by a previous call to SetWindowsHookEx. 
		/// </param>
		/// <returns>
		/// If the function succeeds, the return value is nonzero.
		/// If the function fails, the return value is zero. To get extended error information, call GetLastError.
		/// </returns>
		/// <remarks>
		/// http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/windowing/hooks/hookreference/hookfunctions/setwindowshookex.asp
		/// </remarks>
		[DllImport("user32.dll", CharSet = CharSet.Auto,
			CallingConvention = CallingConvention.StdCall, SetLastError = true)]
		private static extern int UnhookWindowsHookEx(int idHook);

		/// <summary>
		/// The CallNextHookEx function passes the hook information to the next hook procedure in the current hook chain. 
		/// A hook procedure can call this function either before or after processing the hook information. 
		/// </summary>
		/// <param name="idHook">Ignored.</param>
		/// <param name="nCode">
		/// [in] Specifies the hook code passed to the current hook procedure. 
		/// The next hook procedure uses this code to determine how to process the hook information.
		/// </param>
		/// <param name="wParam">
		/// [in] Specifies the wParam value passed to the current hook procedure. 
		/// The meaning of this parameter depends on the type of hook associated with the current hook chain. 
		/// </param>
		/// <param name="lParam">
		/// [in] Specifies the lParam value passed to the current hook procedure. 
		/// The meaning of this parameter depends on the type of hook associated with the current hook chain. 
		/// </param>
		/// <returns>
		/// This value is returned by the next hook procedure in the chain. 
		/// The current hook procedure must also return this value. The meaning of the return value depends on the hook type. 
		/// For more information, see the descriptions of the individual hook procedures.
		/// </returns>
		/// <remarks>
		/// http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/windowing/hooks/hookreference/hookfunctions/setwindowshookex.asp
		/// </remarks>
		[DllImport("user32.dll", CharSet = CharSet.Auto,
			 CallingConvention = CallingConvention.StdCall)]
		private static extern int CallNextHookEx(
			int idHook,
			int nCode,
			int wParam,
			IntPtr lParam);

		/// <summary>
		/// The CallWndProc hook procedure is an application-defined or library-defined callback 
		/// function used with the SetWindowsHookEx function. The HOOKPROC type defines a pointer 
		/// to this callback function. CallWndProc is a placeholder for the application-defined 
		/// or library-defined function name.
		/// </summary>
		/// <param name="nCode">
		/// [in] Specifies whether the hook procedure must process the message. 
		/// If nCode is HC_ACTION, the hook procedure must process the message. 
		/// If nCode is less than zero, the hook procedure must pass the message to the 
		/// CallNextHookEx function without further processing and must return the 
		/// value returned by CallNextHookEx.
		/// </param>
		/// <param name="wParam">
		/// [in] Specifies whether the message was sent by the current thread. 
		/// If the message was sent by the current thread, it is nonzero; otherwise, it is zero. 
		/// </param>
		/// <param name="lParam">
		/// [in] Pointer to a CWPSTRUCT structure that contains details about the message. 
		/// </param>
		/// <returns>
		/// If nCode is less than zero, the hook procedure must return the value returned by CallNextHookEx. 
		/// If nCode is greater than or equal to zero, it is highly recommended that you call CallNextHookEx 
		/// and return the value it returns; otherwise, other applications that have installed WH_CALLWNDPROC 
		/// hooks will not receive hook notifications and may behave incorrectly as a result. If the hook 
		/// procedure does not call CallNextHookEx, the return value should be zero. 
		/// </returns>
		/// <remarks>
		/// http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/windowing/hooks/hookreference/hookfunctions/callwndproc.asp
		/// </remarks>
		private delegate int HookProc(int nCode, int wParam, IntPtr lParam);

		/// <summary>
		/// The ToAscii function translates the specified virtual-key code and keyboard 
		/// state to the corresponding character or characters. The function translates the code 
		/// using the input language and physical keyboard layout identified by the keyboard layout handle.
		/// </summary>
		/// <param name="uVirtKey">
		/// [in] Specifies the virtual-key code to be translated. 
		/// </param>
		/// <param name="uScanCode">
		/// [in] Specifies the hardware scan code of the key to be translated. 
		/// The high-order bit of this value is set if the key is up (not pressed). 
		/// </param>
		/// <param name="lpbKeyState">
		/// [in] Pointer to a 256-byte array that contains the current keyboard state. 
		/// Each element (byte) in the array contains the state of one key. 
		/// If the high-order bit of a byte is set, the key is down (pressed). 
		/// The low bit, if set, indicates that the key is toggled on. In this function, 
		/// only the toggle bit of the CAPS LOCK key is relevant. The toggle state 
		/// of the NUM LOCK and SCROLL LOCK keys is ignored.
		/// </param>
		/// <param name="lpwTransKey">
		/// [out] Pointer to the buffer that receives the translated character or characters. 
		/// </param>
		/// <param name="fuState">
		/// [in] Specifies whether a menu is active. This parameter must be 1 if a menu is active, or 0 otherwise. 
		/// </param>
		/// <returns>
		/// If the specified key is a dead key, the return value is negative. Otherwise, it is one of the following values. 
		/// Value Meaning 
		/// 0 The specified virtual key has no translation for the current state of the keyboard. 
		/// 1 One character was copied to the buffer. 
		/// 2 Two characters were copied to the buffer. This usually happens when a dead-key character 
		/// (accent or diacritic) stored in the keyboard layout cannot be composed with the specified 
		/// virtual key to form a single character. 
		/// </returns>
		/// <remarks>
		/// http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/userinput/keyboardinput/keyboardinputreference/keyboardinputfunctions/toascii.asp
		/// </remarks>
		[DllImport("user32")]
		private static extern int ToAscii(
			int uVirtKey,
			int uScanCode,
			byte[] lpbKeyState,
			byte[] lpwTransKey,
			int fuState);

		/// <summary>
		/// The GetKeyboardState function copies the status of the 256 virtual keys to the 
		/// specified buffer. 
		/// </summary>
		/// <param name="pbKeyState">
		/// [in] Pointer to a 256-byte array that contains keyboard key states. 
		/// </param>
		/// <returns>
		/// If the function succeeds, the return value is nonzero.
		/// If the function fails, the return value is zero. To get extended error information, call GetLastError. 
		/// </returns>
		/// <remarks>
		/// http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/userinput/keyboardinput/keyboardinputreference/keyboardinputfunctions/toascii.asp
		/// </remarks>
		[DllImport("user32")]
		private static extern int GetKeyboardState(byte[] pbKeyState);

		[DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
		private static extern short GetKeyState(int vKey);

		#endregion

		#region Windows constants

		//values from Winuser.h in Microsoft SDK.
		/// <summary>
		/// Windows NT/2000/XP: Installs a hook procedure that monitors low-level mouse input events.
		/// </summary>
		private const int WH_MOUSE_LL	   = 14;
		/// <summary>
		/// Windows NT/2000/XP: Installs a hook procedure that monitors low-level keyboard  input events.
		/// </summary>
		private const int WH_KEYBOARD_LL	= 13;

		/// <summary>
		/// Installs a hook procedure that monitors mouse messages. For more information, see the MouseProc hook procedure. 
		/// </summary>
		private const int WH_MOUSE		  = 7;
		/// <summary>
		/// Installs a hook procedure that monitors keystroke messages. For more information, see the KeyboardProc hook procedure. 
		/// </summary>
		private const int WH_KEYBOARD	   = 2;

		/// <summary>
		/// The WM_MOUSEMOVE message is posted to a window when the cursor moves. 
		/// </summary>
		private const int WM_MOUSEMOVE	  = 0x200;
		/// <summary>
		/// The WM_LBUTTONDOWN message is posted when the user presses the left mouse button 
		/// </summary>
		private const int WM_LBUTTONDOWN	= 0x201;
		/// <summary>
		/// The WM_RBUTTONDOWN message is posted when the user presses the right mouse button
		/// </summary>
		private const int WM_RBUTTONDOWN	= 0x204;
		/// <summary>
		/// The WM_MBUTTONDOWN message is posted when the user presses the middle mouse button 
		/// </summary>
		private const int WM_MBUTTONDOWN	= 0x207;
		/// <summary>
		/// The WM_LBUTTONUP message is posted when the user releases the left mouse button 
		/// </summary>
		private const int WM_LBUTTONUP	  = 0x202;
		/// <summary>
		/// The WM_RBUTTONUP message is posted when the user releases the right mouse button 
		/// </summary>
		private const int WM_RBUTTONUP	  = 0x205;
		/// <summary>
		/// The WM_MBUTTONUP message is posted when the user releases the middle mouse button 
		/// </summary>
		private const int WM_MBUTTONUP	  = 0x208;
		/// <summary>
		/// The WM_LBUTTONDBLCLK message is posted when the user double-clicks the left mouse button 
		/// </summary>
		private const int WM_LBUTTONDBLCLK  = 0x203;
		/// <summary>
		/// The WM_RBUTTONDBLCLK message is posted when the user double-clicks the right mouse button 
		/// </summary>
		private const int WM_RBUTTONDBLCLK  = 0x206;
		/// <summary>
		/// The WM_RBUTTONDOWN message is posted when the user presses the right mouse button 
		/// </summary>
		private const int WM_MBUTTONDBLCLK  = 0x209;
		/// <summary>
		/// The WM_MOUSEWHEEL message is posted when the user presses the mouse wheel. 
		/// </summary>
		private const int WM_MOUSEWHEEL	 = 0x020A;

		/// <summary>
		/// The WM_KEYDOWN message is posted to the window with the keyboard focus when a nonsystem 
		/// key is pressed. A nonsystem key is a key that is pressed when the ALT key is not pressed.
		/// </summary>
		private const int WM_KEYDOWN = 0x100;
		/// <summary>
		/// The WM_KEYUP message is posted to the window with the keyboard focus when a nonsystem 
		/// key is released. A nonsystem key is a key that is pressed when the ALT key is not pressed, 
		/// or a keyboard key that is pressed when a window has the keyboard focus.
		/// </summary>
		private const int WM_KEYUP = 0x101;
		/// <summary>
		/// The WM_SYSKEYDOWN message is posted to the window with the keyboard focus when the user 
		/// presses the F10 key (which activates the menu bar) or holds down the ALT key and then 
		/// presses another key. It also occurs when no window currently has the keyboard focus; 
		/// in this case, the WM_SYSKEYDOWN message is sent to the active window. The window that 
		/// receives the message can distinguish between these two contexts by checking the context 
		/// code in the lParam parameter. 
		/// </summary>
		private const int WM_SYSKEYDOWN = 0x104;
		/// <summary>
		/// The WM_SYSKEYUP message is posted to the window with the keyboard focus when the user 
		/// releases a key that was pressed while the ALT key was held down. It also occurs when no 
		/// window currently has the keyboard focus; in this case, the WM_SYSKEYUP message is sent 
		/// to the active window. The window that receives the message can distinguish between 
		/// these two contexts by checking the context code in the lParam parameter. 
		/// </summary>
		private const int WM_SYSKEYUP = 0x105;

		private const byte VK_SHIFT	 = 0x10;
		private const byte VK_CAPITAL   = 0x14;
		private const byte VK_NUMLOCK   = 0x90;

		#endregion

		/// <summary>
		/// Creates an instance of UserActivityHook object and sets mouse and keyboard hooks.
		/// </summary>
		/// <exception cref="Win32Exception">Any windows problem.</exception>
		public UserActivityHook()
		{
			Start();
		}

		/// <summary>
		/// Creates an instance of UserActivityHook object and installs both or one of mouse and/or keyboard hooks and starts rasing events
		/// </summary>
		/// <param name="InstallMouseHook"><b>true</b> if mouse events must be monitored</param>
		/// <param name="InstallKeyboardHook"><b>true</b> if keyboard events must be monitored</param>
		/// <exception cref="Win32Exception">Any windows problem.</exception>
		/// <remarks>
		/// To create an instance without installing hooks call new UserActivityHook(false, false)
		/// </remarks>
		public UserActivityHook(bool InstallMouseHook, bool InstallKeyboardHook)
		{
			Start(InstallMouseHook, InstallKeyboardHook);
		}

		/// <summary>
		/// Destruction.
		/// </summary>
		~UserActivityHook()
		{
			//uninstall hooks and do not throw exceptions
			Stop(true, true, false);
		}

		/// <summary>
		/// Occurs when the user moves the mouse, presses any mouse button or scrolls the wheel
		/// </summary>
		public event MouseEventHandler OnMouseActivity;
		/// <summary>
		/// Occurs when the user presses a key
		/// </summary>
		public event KeyEventHandler KeyDown;
		/// <summary>
		/// Occurs when the user presses and releases 
		/// </summary>
		public event KeyPressEventHandler KeyPress;
		/// <summary>
		/// Occurs when the user releases a key
		/// </summary>
		public event KeyEventHandler KeyUp;


		/// <summary>
		/// Stores the handle to the mouse hook procedure.
		/// </summary>
		private int hMouseHook = 0;
		/// <summary>
		/// Stores the handle to the keyboard hook procedure.
		/// </summary>
		private int hKeyboardHook = 0;


		/// <summary>
		/// Declare MouseHookProcedure as HookProc type.
		/// </summary>
		private static HookProc MouseHookProcedure;
		/// <summary>
		/// Declare KeyboardHookProcedure as HookProc type.
		/// </summary>
		private static HookProc KeyboardHookProcedure;


		/// <summary>
		/// Installs both mouse and keyboard hooks and starts rasing events
		/// </summary>
		/// <exception cref="Win32Exception">Any windows problem.</exception>
		public void Start()
		{
			this.Start(true, true);
		}

		/// <summary>
		/// Installs both or one of mouse and/or keyboard hooks and starts rasing events
		/// </summary>
		/// <param name="InstallMouseHook"><b>true</b> if mouse events must be monitored</param>
		/// <param name="InstallKeyboardHook"><b>true</b> if keyboard events must be monitored</param>
		/// <exception cref="Win32Exception">Any windows problem.</exception>
		public void Start(bool InstallMouseHook, bool InstallKeyboardHook)
		{
			// install Mouse hook only if it is not installed and must be installed
			if (hMouseHook == 0 && InstallMouseHook)
			{
				// Create an instance of HookProc.
				MouseHookProcedure = new HookProc(MouseHookProc);
				//install hook
				hMouseHook = SetWindowsHookEx(
					WH_MOUSE_LL,
					MouseHookProcedure,
					Marshal.GetHINSTANCE(
						Assembly.GetExecutingAssembly().GetModules()[0]),
					0);
				//If SetWindowsHookEx fails.
				if (hMouseHook == 0)
				{
					//Returns the error code returned by the last unmanaged function called using platform invoke that has the DllImportAttribute.SetLastError flag set. 
					int errorCode = Marshal.GetLastWin32Error();
					//do cleanup
					Stop(true, false, false);
					//Initializes and throws a new instance of the Win32Exception class with the specified error. 
					throw new Win32Exception(errorCode);
				}
			}

			// install Keyboard hook only if it is not installed and must be installed
			if (hKeyboardHook == 0 && InstallKeyboardHook)
			{
				// Create an instance of HookProc.
				KeyboardHookProcedure = new HookProc(KeyboardHookProc);
				//install hook
				hKeyboardHook = SetWindowsHookEx(
					WH_KEYBOARD_LL,
					KeyboardHookProcedure,
					Marshal.GetHINSTANCE(
					Assembly.GetExecutingAssembly().GetModules()[0]),
					0);
				//If SetWindowsHookEx fails.
				if (hKeyboardHook == 0)
				{
					//Returns the error code returned by the last unmanaged function called using platform invoke that has the DllImportAttribute.SetLastError flag set. 
					int errorCode = Marshal.GetLastWin32Error();
					//do cleanup
					Stop(false, true, false);
					//Initializes and throws a new instance of the Win32Exception class with the specified error. 
					throw new Win32Exception(errorCode);
				}
			}
		}

		/// <summary>
		/// Stops monitoring both mouse and keyboard events and rasing events.
		/// </summary>
		/// <exception cref="Win32Exception">Any windows problem.</exception>
		public void Stop()
		{
			this.Stop(true, true, true);
		}

		/// <summary>
		/// Stops monitoring both or one of mouse and/or keyboard events and rasing events.
		/// </summary>
		/// <param name="UninstallMouseHook"><b>true</b> if mouse hook must be uninstalled</param>
		/// <param name="UninstallKeyboardHook"><b>true</b> if keyboard hook must be uninstalled</param>
		/// <param name="ThrowExceptions"><b>true</b> if exceptions which occured during uninstalling must be thrown</param>
		/// <exception cref="Win32Exception">Any windows problem.</exception>
		public void Stop(bool UninstallMouseHook, bool UninstallKeyboardHook, bool ThrowExceptions)
		{
			//if mouse hook set and must be uninstalled
			if (hMouseHook != 0 && UninstallMouseHook)
			{
				//uninstall hook
				int retMouse = UnhookWindowsHookEx(hMouseHook);
				//reset invalid handle
				hMouseHook = 0;
				//if failed and exception must be thrown
				if (retMouse == 0 && ThrowExceptions)
				{
					//Returns the error code returned by the last unmanaged function called using platform invoke that has the DllImportAttribute.SetLastError flag set. 
					int errorCode = Marshal.GetLastWin32Error();
					//Initializes and throws a new instance of the Win32Exception class with the specified error. 
					throw new Win32Exception(errorCode);
				}
			}

			//if keyboard hook set and must be uninstalled
			if (hKeyboardHook != 0 && UninstallKeyboardHook)
			{
				//uninstall hook
				int retKeyboard = UnhookWindowsHookEx(hKeyboardHook);
				//reset invalid handle
				hKeyboardHook = 0;
				//if failed and exception must be thrown
				if (retKeyboard == 0 && ThrowExceptions)
				{
					//Returns the error code returned by the last unmanaged function called using platform invoke that has the DllImportAttribute.SetLastError flag set. 
					int errorCode = Marshal.GetLastWin32Error();
					//Initializes and throws a new instance of the Win32Exception class with the specified error. 
					throw new Win32Exception(errorCode);
				}
			}
		}


		/// <summary>
		/// A callback function which will be called every time a mouse activity detected.
		/// </summary>
		/// <param name="nCode">
		/// [in] Specifies whether the hook procedure must process the message. 
		/// If nCode is HC_ACTION, the hook procedure must process the message. 
		/// If nCode is less than zero, the hook procedure must pass the message to the 
		/// CallNextHookEx function without further processing and must return the 
		/// value returned by CallNextHookEx.
		/// </param>
		/// <param name="wParam">
		/// [in] Specifies whether the message was sent by the current thread. 
		/// If the message was sent by the current thread, it is nonzero; otherwise, it is zero. 
		/// </param>
		/// <param name="lParam">
		/// [in] Pointer to a CWPSTRUCT structure that contains details about the message. 
		/// </param>
		/// <returns>
		/// If nCode is less than zero, the hook procedure must return the value returned by CallNextHookEx. 
		/// If nCode is greater than or equal to zero, it is highly recommended that you call CallNextHookEx 
		/// and return the value it returns; otherwise, other applications that have installed WH_CALLWNDPROC 
		/// hooks will not receive hook notifications and may behave incorrectly as a result. If the hook 
		/// procedure does not call CallNextHookEx, the return value should be zero. 
		/// </returns>
		private int MouseHookProc(int nCode, int wParam, IntPtr lParam)
		{
			// if ok and someone listens to our events
			if ((nCode >= 0) && (OnMouseActivity != null))
			{
				//Marshall the data from callback.
				MouseLLHookStruct mouseHookStruct = (MouseLLHookStruct)Marshal.PtrToStructure(lParam, typeof(MouseLLHookStruct));

				//detect button clicked
				MouseButtons button = MouseButtons.None;
				short mouseDelta = 0;
				switch (wParam)
				{
					case WM_LBUTTONDOWN:
						//case WM_LBUTTONUP: 
						//case WM_LBUTTONDBLCLK: 
						button = MouseButtons.Left;
						break;
					case WM_RBUTTONDOWN:
						//case WM_RBUTTONUP: 
						//case WM_RBUTTONDBLCLK: 
						button = MouseButtons.Right;
						break;
					case WM_MOUSEWHEEL:
						//If the message is WM_MOUSEWHEEL, the high-order word of mouseData member is the wheel delta. 
						//One wheel click is defined as WHEEL_DELTA, which is 120. 
						//(value >> 16) & 0xffff; retrieves the high-order word from the given 32-bit value
						mouseDelta = (short)((mouseHookStruct.mouseData >> 16) & 0xffff);
						//TODO: X BUTTONS (I havent them so was unable to test)
						//If the message is WM_XBUTTONDOWN, WM_XBUTTONUP, WM_XBUTTONDBLCLK, WM_NCXBUTTONDOWN, WM_NCXBUTTONUP, 
						//or WM_NCXBUTTONDBLCLK, the high-order word specifies which X button was pressed or released, 
						//and the low-order word is reserved. This value can be one or more of the following values. 
						//Otherwise, mouseData is not used. 
						break;
				}

				//double clicks
				int clickCount = 0;
				if (button != MouseButtons.None)
					if (wParam == WM_LBUTTONDBLCLK || wParam == WM_RBUTTONDBLCLK) clickCount = 2;
					else clickCount = 1;

				//generate event 
				 MouseEventArgs e = new MouseEventArgs(
													button,
													clickCount,
													mouseHookStruct.pt.x,
													mouseHookStruct.pt.y,
													mouseDelta);
				//raise it
				OnMouseActivity(this, e);
			}
			//call next hook
			return CallNextHookEx(hMouseHook, nCode, wParam, lParam);
		}

		/// <summary>
		/// A callback function which will be called every time a keyboard activity detected.
		/// </summary>
		/// <param name="nCode">
		/// [in] Specifies whether the hook procedure must process the message. 
		/// If nCode is HC_ACTION, the hook procedure must process the message. 
		/// If nCode is less than zero, the hook procedure must pass the message to the 
		/// CallNextHookEx function without further processing and must return the 
		/// value returned by CallNextHookEx.
		/// </param>
		/// <param name="wParam">
		/// [in] Specifies whether the message was sent by the current thread. 
		/// If the message was sent by the current thread, it is nonzero; otherwise, it is zero. 
		/// </param>
		/// <param name="lParam">
		/// [in] Pointer to a CWPSTRUCT structure that contains details about the message. 
		/// </param>
		/// <returns>
		/// If nCode is less than zero, the hook procedure must return the value returned by CallNextHookEx. 
		/// If nCode is greater than or equal to zero, it is highly recommended that you call CallNextHookEx 
		/// and return the value it returns; otherwise, other applications that have installed WH_CALLWNDPROC 
		/// hooks will not receive hook notifications and may behave incorrectly as a result. If the hook 
		/// procedure does not call CallNextHookEx, the return value should be zero. 
		/// </returns>
		private int KeyboardHookProc(int nCode, Int32 wParam, IntPtr lParam)
		{
			//indicates if any of underlaing events set e.Handled flag
			bool handled = false;
			//it was ok and someone listens to events
			if ((nCode >= 0) && (KeyDown != null || KeyUp != null || KeyPress != null))
			{
				//read structure KeyboardHookStruct at lParam
				KeyboardHookStruct MyKeyboardHookStruct = (KeyboardHookStruct)Marshal.PtrToStructure(lParam, typeof(KeyboardHookStruct));
				//raise KeyDown
				if (KeyDown != null && (wParam == WM_KEYDOWN || wParam == WM_SYSKEYDOWN))
				{
					Keys keyData = (Keys)MyKeyboardHookStruct.vkCode;
					KeyEventArgs e = new KeyEventArgs(keyData);
					KeyDown(this, e);
					handled = handled || e.Handled;
				}

				// raise KeyPress
				if (KeyPress != null && wParam == WM_KEYDOWN)
				{
					bool isDownShift = ((GetKeyState(VK_SHIFT) & 0x80) == 0x80 ? true : false);
					bool isDownCapslock = (GetKeyState(VK_CAPITAL) != 0 ? true : false);

					byte[] keyState = new byte[256];
					GetKeyboardState(keyState);
					byte[] inBuffer = new byte[2];
					if (ToAscii(MyKeyboardHookStruct.vkCode,
							  MyKeyboardHookStruct.scanCode,
							  keyState,
							  inBuffer,
							  MyKeyboardHookStruct.flags) == 1)
					{
						char key = (char)inBuffer[0];
						if ((isDownCapslock ^ isDownShift) && Char.IsLetter(key)) key = Char.ToUpper(key);
						KeyPressEventArgs e = new KeyPressEventArgs(key);
						KeyPress(this, e);
						handled = handled || e.Handled;
					}
				}

				// raise KeyUp
				if (KeyUp != null && (wParam == WM_KEYUP || wParam == WM_SYSKEYUP))
				{
					Keys keyData = (Keys)MyKeyboardHookStruct.vkCode;
					KeyEventArgs e = new KeyEventArgs(keyData);
					KeyUp(this, e);
					handled = handled || e.Handled;
				}

			}

			//if event handled in application do not handoff to other listeners
			if (handled)
				return 1;
			else
				return CallNextHookEx(hKeyboardHook, nCode, wParam, lParam);
		}
	}
}

Just put those two into their own .cs files and call them from your program. From there, to use the system event hook add this to your programs code:

			!<Use this as a global reference

			private Hooks hooks = new Hooks();

			 !<This goes in your Form_Load method

			hooks.OnWindowCreate += new OnWindowCreateDelegate(window_Created);

			!<Now setup the window_Create method and add in the needed coding there. A handle will be passed to the window_Create method.

And to use the mouse hook add this to your program:

			!<Use this as a global reference

			private UserActivityHook actHook = new UserActivityHook(true, false);		   


			!<This goes in your Form_Load method

		   //Create a new event for the gloabl mouse hook
			actHook.OnMouseActivity += new MouseEventHandler(actHook_OnMouseActivity);
			this.actHook.Start(true, false);

Hope it helps. If you need any more help to get it working just let me know and I'll try my best to pass on the knowledge. :)

Edited by Sranshaft
  • 0

@ebody : I`ve also implemented something similar by using Global CBT Hooks to receive Window Create and Activation notifications on a system-wide basis for all windows, so will be happy to help :)

@ Sranshaft,

Excellent bit of code ! However , i have a couple of clarifications with Hook activities :

Basically, i`m working with a group of apps (really complex forms) running as separate exe`s and need to manage their ZOrder & Activation, so that the user gets the "feel" that they are interacting with one,single UI

All these windows are Unowned,Toplevel windows and have WS_EX-TOLLWINDOW style so that they dont show up either in the taskbar or the Alt+Tab menu

In the CBT hook filter functions i basically call SetWindowPos to keep all my app windows together.

You need to setup global hooks. This is the code I use to check for system events. Included are events for window creating / destroying, minimizing and foreground changes. It should give a good example if you need to include something else.

1. Should the Filter Functions for CBT Global Hooks always be in an unmanaged DLL ? I ask this because u have used C# in the entire sample but how can this get mapped globally into the address space of other unmanaged apps ?

2. Of the two approaches - SetWinEventHookEx or Global CBT Hooks : which one would u suggest is the better alternative? I`m aiming to get stability here and be informed about a wide range of events.

3. Third really important point is that i`m somehow messing up the activation states of the open windows.

Example scenario :

a. Right-click on any of my app windows and a context menu pops up,

b. Without selecting any item on the context menu, click on the taskbar icon of some external app like notepad

c. Click back on my earlier app , but now, the keyboard/mouse focus doesn`t seem to get transferred. Also my app window doesn`t seem to get activated even if i repeatedly click on it (left,right,middle) and i`m sure my hook also doesnt receive any activate notifications.

Is there any way to sync up the activation states ?

Recall that in my hook filter function, i check to see if any of my apps are activated (HCBT_ACTIVATE) and if yes then i change the zorder to bring my windows on top(HWND_TOP) else i send them to the Bottom.

I`m not really sure what more i`m supposed to do in my Filter functions. I tried calling SetActive / Foreground window but that doesn`t really help.

I`m getting the same behavior with SetWineventHook API too, so i guess my zordering code isn`t correct

I can send u a small sample if that helps.

Looking forward to your reply.Any pointers are most appreciated.

  • 0

the documentation is such a mess, I would never expect to find system event functions in the Accessibility group... that's why I couldn't find it earlier,... all the time I was looking for some system category or something hehe... unfortunetally I had no time to test it yet but I think it won't be harder the the window hook function that I tried to use for this purpose till now

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • The comment about clock speeds not changing is actually not really true. Due to aggressive power management, clock speeds on an idle system are lower now than they have been in decades. It isn't uncommon for a laptop to be hovering right around 1GHz if it isn't working on anything. Yes you right that more work gets done with each cycle, but you are still dealing with a nearly 5x difference between low and high power states, which can change how snappy the interface feels. I totally agree with you about the action center and other Windows UI elements taking a shameful amount of CPU cycles to do basic functions, but I see that as a separate conversation. While I do agree with the "don't sweep that under the rug" concern, I also don't want to get into a debate about what things deserve a boost or not. In my opinion, boost all the things, get the full value from your CPU. Keep in mind, we are talking about milliseconds of boosting, it isn't meaningfully going to change power consumption.
    • Windows 11 gets better widgets, new Screen Tint feature, and more in the latest build by Taras Buria While we usually cover Experimental and Beta builds together, this week's Beta updates are worth a separate article, as they offer more changes and new features than the other build. If you are a Windows Insider with a computer enrolled in the Beta Channel, you can download build 26220.8680 or build 28020.2298 (26H1). Today's release introduces long-anticipated improvements to Windows Widgets, a new display accessibility feature, File Explorer, and more. [Widgets] We're working to make Widgets feel less distracting and overwhelming by making the experience quiet by default. To do this, we're releasing a new set of default settings designed to reduce unexpected alerts and visual interruptions. These changes include: Disabling Open on hover by default Turning off Taskbar badging by default Opening to widgets experience on first launch Placing Weather as the only default widget on the lockscreen Restricting the number of Taskbar alerts that can be sent daily Limiting Taskbar alerts until you choose to open and engage with the Widgets experience As we continue to make Widgets feel less distracting, we've also made a small but meaningful visual update to taskbar badging. For those that have taskbar badging on, the badge color will now match your Windows accent color instead of always appearing red, reducing the sense of urgency that something needs your immediate attention. However, we still want it to be easy to find missed information so we now support badges on the icons in the Widget navigation bar that can show you the number of missed alerts from that specific dashboard; and badges clear automatically when you leave a dashboard, making it easy to track what's new. And if you don't want badges at all in your navigation bar, there's a setting to turn them off. We're also quieting down a user's experience based on their level of engagement, so that existing users also have a less distracting experience. For example, a user who barely engages with Widgets and would benefit from having the experience quieted down with taskbar badging turned off as it is for new users who experience it as quiet by default, as compared to a user who highly engages with Widgets and likely has their settings set to a state that works best for them and don't need some adjustments. You can also easily turn features like Taskbar badging on or off through Widgets settings, which is now a full screen experience that's easier to read. In pursuit of memory savings across the system, Widgets also now leverages device characteristics and user behavior patterns to optimize memory use. This includes things like a smaller default memory footprint, giving back memory faster when not in use, and limiting pre-launch on devices with lower memory capacity. Please share your feedback to let us know how these changes are working for you or if you encounter any issues with your quieter Widgets experience. Feedback: Share your thoughts in Feedback Hub (WIN + F) under Widgets. [Accessibility] New accessibility setting: Screen tint (also available in the 26H1 build) We're introducing screen tint, a new accessibility setting that applies a color overlay across your entire display, softening its intensity so it's easier on your eyes throughout the day. If bright, saturated screens leave you with tired or sensitive eyes by the end of a long session, screen tint can help. To get started, open Settings > Accessibility (or press Win + U) and look for screen tint under the Vision section. From there you can: Pick from six preset colors or choose a custom color of your own. Adjust the tint strength slider from a subtle wash to full intensity. Night light warms your display to reduce blue light that can interfere with sleep. Screen tint reduces overall screen intensity to ease eye fatigue and light sensitivity during the day. They tackle different problems and you can use both at the same time, one working on warmth and the other on intensity. Note that turning on screen tint will disable color filters, and vice versa. If you currently rely on color filters, you may need to keep screen tint turned off. [Windows Magnifier] Magnifier now gives you more control over how you zoom. You can type an exact zoom percentage directly in the magnifier toolbar to land on precisely the level you need. We've also added preset step increments (5%, 10%, 25%, 50%, 100%, 150%, 200%, and 400%) to the Settings dropdown, so you can jump to common levels in a single click. Whether you need a subtle boost or a dramatic close-up, Magnifier adapts to how you want to zoom. Feedback: Share your thoughts in Feedback Hub (WIN + F) under Accessibility > Magnifier [Input] Update: The emoji panel (Windows key + period (.)) now uses GIPHY as the GIF provider, delivering a smoother GIF browsing and sharing experience following the deprecation of Tenor. [Remote Recovery Management] Adding recovery remote management plug-in for extending WinRE management capabilities for MDM providers [File Explorer] The address bar now supports paths containing double backslashes and quotation marks (for example, C:\Users\user or "C:\Users\user"), improving compatibility with a wider range of inputs. Improved performance when mounting large ISO files by preventing File Explorer from becoming unresponsive during SmartScreen checks. The address bar suggestion dropdown is more reliable and now consistently closes after an item is selected. This update addresses an issue on File Explorer Home where OneDrive files could appear duplicated in the Favorites section. This update includes several refinements to the Rename experience: Addresses an issue where text was repeatedly selected when renaming items in folder views. Addresses an issue where case-only name changes were not immediately reflected in folder views for items stored locally or in the cloud. [Windows Update] If you were seeing error 0x800f0843 when attempting to install the previous update, that should be resolved now. [Other] - 26H1-only Task Scheduler will now persist column width adjustments in task list view across sessions. You can find the release notes for build 26220.8680 here and build 28020.2298 here.
    • Microsoft releases big Windows 11 25H2, 24H2 Release Preview with Recovery, Update features by Sayan Sen Microsoft has released today new Release Preview channel builds for Windows 11 Insiders. The new builds, 26100.8728 and 26200.8728, are for Windows 11 24H2 and 25H2 flighters, respectively. Meanwhile 26H1 flighters get 28000.2333. The new builds include new features related to Windows Update, Recovery, and more. The full changelogs, which are quite long today, are given below. First up we have for Builds 26200.8728 and 26100.8728: Gradual rollout This section highlights some new features and enhancements for Windows 11 PCs, including AI-powered capabilities, continuous innovation, and performance improvements. [Point-in-time restore for Windows] New! This flexible recovery feature helps you quickly roll back your PC, including apps, settings, and personal files, to a recent automatic restore point. It helps reduce downtime and simplifies troubleshooting when issues occur. To learn more, see Point-in-time restore for Windows. [Windows Update] New! A calendar experience in Windows Update settings (Settings > Windows Update) lets you pause updates by choosing an end date, for up to 35 days. You can extend the pause by selecting a different end date and re-pause updates as needed. [Widgets] New! A quieter, more focused Widgets experience helps reduce interruptions and improves default settings and notification controls: Reduce distractions: Widgets no longer open on hover. Notifications and taskbar badges are minimized by default, and badges use colors that match your Windows accent. Simpler: Open to the Widgets dashboard by default on first use. New users see a simplified experience on lock screen with Weather as the only default widget. Customize: Configure Widgets the way you want by selecting Settings in the navigation bar, then changing any default settings. Stay informed: Dashboard icons show the number of alerts, and badges clear automatically when you leave a dashboard. Adjusted defaults: Some default settings are preserved based on usage, while others adjust to reduce interruptions. Performance improvements: This update provides improved reliability, responsiveness, and visual quality across the Widgets experience. [Accessibility] New! This update makes your screen easier to see and helps you customize your zoom experience: Screen tint: Apply a full-screen color overlay to help reduce eye strain and improve readability. Choose from preset tint options, adjust intensity, or turn it on automatically. Find this feature in Settings > Accessibility. Magnifier: Enter a zoom percentage directly and change it in increments in the Magnifier window for more precise, flexible control. Magnifier settings menu: Modify zoom increments directly from the Magnifier bar instead of navigating to Windows Settings each time. [File Explorer] When you hover over a file in File Explorer Home, commands such as Open file location and Ask Copilot appear as quick actions. This experience is now supported for work and school accounts (Entra ID). This feature isn't available in the European Economic Area. The address bar now supports paths containing double backslashes and quotation marks (for example, C:\Users\user or "C:\Users\user"), improving compatibility with a wider range of inputs. The address bar suggestion dropdown is more reliable and now consistently closes after an item is selected. This update addresses an issue on File Explorer Home where OneDrive files could appear duplicated in the Favorites section. This update includes several refinements to the Rename experience: Addresses an issue where text was repeatedly selected when renaming items in folder views. Addresses an issue where case-only name changes were not immediately reflected in folder views for items stored locally or in the cloud. [Bluetooth] This update improves reliability and performance when connecting to and using Bluetooth devices: New! Windows now keeps the microphone mute state in sync between the audio mixer and the Hands-Free Profile (HFP) for a more consistent experience with Bluetooth headphones with mute buttons or indicators. Device compatibility: Improves compatibility with certain Bluetooth audio devices, helping AirPods appear faster in pairing mode and improving microphone reliability on Beats Studio Pro headphones. Bluetooth audio stability and quality: Improves Bluetooth audio stability with certain PC manufacturer drivers (error code 0x9F). Improves Bluetooth audio quality and reliability for voice calls when using classic audio devices with the Hands-Free Profile (HFP). Improves reliability of LE Audio streaming after a connection is lost and restored. Reduces time for LE Audio accessories to start playing audio while using the microphone. Device management: Bluetooth device removal is now more reliable when the Bluetooth radio is disabled or changed after pairing, reducing occurrences of the "Remove failed" message. Settings experience: Improves stability when using the Bluetooth & devices settings page for a smoother, more consistent experience. Connection reliability and responsiveness: Reduces the time it takes for classic Bluetooth audio devices to reconnect after Windows resumes from hibernation. Improves reliability when LE Audio accessories disconnect, such as when another device (for example, a phone) connects. [Bluetooth and Phone Link] This update improves audio routing for calls made through a connected phone: When an outgoing call is dialed from a paired phone, audio remains on the phone while ringing and transfers to the PC only when the call is answered from the PC. When Do Not Disturb is enabled on Windows, incoming call audio from a paired phone no longer rings on the PC. [Voice access and voice typing] New! You can now use voice access and voice typing in French, German, and Spanish. As you speak, your PC improves your text in real time. It corrects grammar, punctuation, and recognition errors, and helps improve clarity, even in the presence of background noise. This makes dictation smoother and reduces the need for manual edits. Available on Copilot+ PCs. [Audio] This update improves the reliability of the inbox HD Audio driver. [Taskbar] This update improves the reliability of invoking the Start menu when clicking the left edge of the taskbar when icons in the taskbar are left-aligned. [Emoji panel] The emoji panel (Windows key + period (.)) now uses GIPHY as the GIF provider, delivering a smoother GIF browsing and sharing experience following the deprecation of Tenor. [Networking] This update includes networking improvements for virtualized environments. Confidential Virtual Machines (CVMs) now use SR-IOV hardware acceleration by default for improved network throughput, and a configuration issue in nested Hyper-V virtualization network setup has been corrected to ensure reliable VM network provisioning. This update improves the reliability of the Windows networking stack. It reduces bug checks (blue screen errors) related to Wi-Fi power and improves cellular (WWAN) connectivity, including support for IPv6 VPNs. Compatibility with third-party VPN software and SR-IOV configurations on server hardware is also improved. Network adapter settings and bindings are now preserved across OS upgrades. [Printing] New! New printer installations use Internet Printing Protocol (IPP) by default when supported, simplifying setup and improving reliability. To control this behavior, use the toggle in Settings > Bluetooth & devices > Printers & scanners > Default install printers using Windows Ready Print. [Windows Subsystem for Linux (WSL)] This update improves usage of WSL in mirrored networking mode with VPNs. [Display and graphics] Improves reliability of rendering content while scrolling for certain apps spanning across multiple monitors. Improves reliability and persistence of applying color profiles. [Location services] This update changes how some location settings are displayed in Settings > Privacy & Security > Location to help with clarity. When location services are turned off, settings like Default location and Allow location override do not immediately apply, since location information is not given to apps or services. These settings are now greyed out when location services are off to reduce confusion over when they take effect. [Search] This update improves the reliability of setting Search-related group policies. [Input] New! You can now customize the size of the right-click zone in Settings > Bluetooth & devices > Touchpad. Choose from default, small, medium, or large to control how much of the bottom-right corner responds to a single-finger right-click. This setting is only available on touchpads with a pressable surface. If your device manufacturer provides customization through their app, a Custom option appears to reflect those settings. This update also improves recognition of English characters when using Japanese handwriting. [General Reliability] This update makes underlying changes to help improve explorer.exe reliability, including addressing reliability issues on the login and lock screens related to the use of third-party credential providers, reducing the probability of taskbar icons appearing as blank gray placeholders, improving reliability of navigating to File Explorer Home during OneDrive sync, improving explorer.exe reliability when switching between multiple desktops, improving app launch reliability when shell extensions are installed, and addressing reliability issues related to acrylic blur effects in Start menu, Settings, and the lock screen. Normal rollout This non-security update includes quality improvements. The following summary outlines key issues addressed by the KB update after you install it. Also, included are available new features. The bold text within the brackets indicates the item or area of the change. [Secure Boot] With this update, Windows quality updates include additional high confidence device targeting data, increasing coverage of devices eligible to automatically receive new Secure Boot certificates. Devices receive the new certificates only after demonstrating sufficient successful update signals, maintaining a controlled and phased rollout. [Authentication] This update improves Netlogon secure channel connections between domain controllers, enabling successful connections from member servers to domain controllers set up before 2025. [Networking] This update improves how your device connects to shared network resources. Connections used by apps and system features, such as the NetUseAdd function, now work more reliably, including unauthenticated (null session) connections. [Start Menu] This update improves the Start menu experience, allowing newly installed or removed apps to appear without requiring sign-out or restart. This mainly affects apps that create a Start menu folder with multiple shortcuts. [Taskbar] This update improves notification badge display across your apps. Notification counts and badge visuals now update correctly, helping you stay up to date with new activity. Up next we have build 28000.2333: Gradual rollout Windows 11 PC experiences This section highlights some new features and enhancements for Windows 11 PCs, including AI-powered capabilities, continuous innovation, and performance improvements. [Magnifier in Windows] New! Magnifier now provides clearer and more consistent announcements when working with a screen reader. You'll hear helpful announcements when you zoom in or out, switch views, turn color inversion on or off, or turn Magnifier On or Off. This makes it easy to stay oriented while you work. New! Magnifier now supports magnification of permitted protected content. This update improves smoothness when moving Magnifier in lens mode. [Task Manager] New! Task Manager now offers improved visibility into NPU usage on PCs with an NPU. New optional NPU and NPU Engine columns are available on the Processes, Users, and Details pages, along with NPU Dedicated Memory and NPU Shared Memory optional columns on the Details page. Neural engines that are part of a GPU now appear on the Performance page, providing a more complete view of AI-related activity. A new optional Isolation column on the Processes and Details pages shows which apps are running in an AppContainer. You can add any of the new columns by right-clicking a column header in Task Manager and selecting them from the menu. This update improves CPU speed display on the Performance page of Task Manager for VMs, so it doesn't show higher than unexpected numbers after resuming from hibernate. [Camera] New! Windows 11's Multi-App Camera feature allows multiple applications to access your camera stream at the same time. Basic Camera mode in Windows 11 enables simplified camera functionality, useful for troubleshooting or improving stability when your camera is not working correctly. Enterprise admin can now set Multi-App Camera mode or Basic Camera mode through Group Policy, under Computer Configuration > Administrative Templates > Windows Components > Camera > Configure Camera Options. [Windows Setup] New! You can now choose a custom name for your user folder on the Device Name page during Windows setup. The updated experience makes it easier to select a custom name during setup only. If this step is skipped, Windows uses the default folder name and continues setup as usual. User folder names must follow standard Windows naming requirements. [General Performance] This update accelerates app launch and core shell experiences such as Start menu, Search, and Action Center. [Personalization] This update improves: Color selection accuracy when adjusting your accent color to match your wallpaper when the automatic accent color selection is enabled in Personalization settings. Wallpaper persistence reliability across restarts and upgrades, including better support for large-resolution wallpapers and other scenarios to prevent solid color wallpaper fallback. [Windows Hello] This update improves: This update optimizes the Windows Biometric service (WinBio) to help improve performance when your device resumes from Modern Standby. This update reduces unexpected authentication blocks in Windows Hello Enhanced Sign-in Security by resolving missing secure enrollment metadata. This update improves sign-in behavior on the lock screen and sign-in screen. When Windows Hello face or fingerprint is set up and available, it is now the default sign-in method every time you sign in, even if you used a different method previously. If you need to use your Windows PIN instead and use it three times in a row, Windows will stay with PIN until you switch to another sign-in method. [Windows Search Box] Windows Search will now find and prioritize files with as few as two characters. [Storage] The dialog box for creating a Dev Drive now supports specifying the size in gigabytes (GB) instead of only megabytes (MB). This option is also available when resizing volumes in Settings > System > Storage. In Settings > System > Storage, you now see a User Account Control (UAC) prompt only when you choose to view temporary files, instead of immediately when opening the page. [USB] This update improves reliability for displays attached to USB4 docks and hubs. These displays now light up more consistently, particularly when coming out of standby. The USB3 stack is updated to have additional resiliency and recovery measures in place against certain unexpected hardware faults and conditions. Users will experience higher reliability with USB devices. [Sensors] This update improves resiliency against apps that could keep the sensor hub powered on and drain power, impacting battery life. [Human Interface Device (HID)] This update improves battery life related to the HID and Input stack for failed HID devices. Power hygiene is also improved against applications that might initiate HID transfers during standby. [Input] The update improves: Reliability of the touch keyboard on the sign-in screen, including when entering or changing a password. Reliability of explorer.exe when closing the input switcher. Performance when opening or navigating to clipboard history. [Fonts] The Times New Roman font family is updated to improve the rendering of combining diacritical marks across Greek and Cyrillic scripts. This update provides more accurate and visually consistent text by addressing mark positioning issues. These changes improve readability, reduce rendering inconsistencies, and better support global language users working with Greek and Cyrillic content. [Task Scheduler] Task Scheduler now saves column width adjustments in task list view across sessions. [Desktop icons] This update improves reliability of loading desktop app shortcuts. [Microsoft Store] This update includes underlying changes that improve download performance and bandwidth usage. This update improves error reporting when downloads fail due to Windows Update group policy settings being enabled. [Reliability] This update improves Windows reliability on the sign-in and lock screens, in File Explorer, when using touch gestures on touchscreen devices, and when changing themes in Settings. Normal rollout This non-security update includes quality improvements. The following summary outlines key issues addressed by the KB update after you install it. Also, included are available new features. The bold text within the brackets indicates the item or area of the change. [Authentication] This update improves Netlogon secure channel connections between domain controllers, enabling successful connections from member servers to domain controllers set up before 2025. [BitLocker] This update improves BitLocker testing reliability by ensuring the required files are available for the BitLocker Drive Encryption USB BIOS Logo Test. You can find the blog post for builds 26100.8728/26200.8728 here and build 28000.2333 here.
    • Maybe it became sentient and realized how useless it is, and thus shut itself down.
  • Recent Achievements

    • Veteran
      Taliseian went up a rank
      Veteran
    • One Month Later
      Clizby earned a badge
      One Month Later
    • One Month Later
      Timaximus earned a badge
      One Month Later
    • Week One Done
      Timaximus earned a badge
      Week One Done
    • Rookie
      FBSPL went up a rank
      Rookie
  • Popular Contributors

    1. 1
      +primortal
      498
    2. 2
      PsYcHoKiLLa
      170
    3. 3
      +Edouard
      163
    4. 4
      Steven P.
      86
    5. 5
      ATLien_0
      77
  • Tell a friend

    Love Neowin? Tell a friend!