MCPcopy Create free account
hub / github.com/AutoHotkey/AutoHotkey / GetFocusedCtrlThread

Function GetFocusedCtrlThread

source/keyboard_mouse.cpp:3728–3755  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3726
3727
3728DWORD GetFocusedCtrlThread(HWND *apControl, HWND aWindow)
3729{
3730 // Determine the thread for which we want the keyboard layout.
3731 // When no foreground window, the script's own layout seems like the safest default.
3732 DWORD thread_id = 0;
3733 if (aWindow)
3734 {
3735 // Get thread of aWindow (which should be the foreground window).
3736 thread_id = GetWindowThreadProcessId(aWindow, NULL);
3737 // Get focus. Benchmarks showed this additional step added only 6% to the time,
3738 // and the total was only around 4µs per iteration anyway (on a Core i5-4460).
3739 // It is necessary for UWP apps such as Microsoft Edge, and any others where
3740 // the top-level window belongs to a different thread than the focused control.
3741 GUITHREADINFO thread_info;
3742 thread_info.cbSize = sizeof(thread_info);
3743 if (GetGUIThreadInfo(thread_id, &thread_info))
3744 {
3745 if (thread_info.hwndFocus)
3746 {
3747 // Use the focused control's thread.
3748 thread_id = GetWindowThreadProcessId(thread_info.hwndFocus, NULL);
3749 if (apControl)
3750 *apControl = thread_info.hwndFocus;
3751 }
3752 }
3753 }
3754 return thread_id;
3755}
3756
3757
3758

Callers 3

SendKeysFunction · 0.85
GetFocusedKeybdLayoutFunction · 0.85
CollectInputFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected