The case of the hang when the user changed keyboard layouts

The Old New Thing (Raymond Chen) News

Summary

A debugging story about a Windows program hanging when the user changes keyboard layouts due to a background thread that created a window but wasn't pumping messages. The fix is to either pump messages or destroy the window.

<p>A customer reported that their program hung when the user changed keyboard layouts, say by using the <kbd>Win</kbd>+<kbd>Space</kbd> hotkey sequence. They debugged it as far as observing that the foreground window in their application received a <code>WM_<wbr />INPUT­LANG­CHANGE­REQUEST</code>, and when that message was passed to <code>Def­Window­Proc</code>, the call never returned. What&#8217;s so haunted about the <code>WM_<wbr />INPUT­LANG­CHANGE­REQUEST</code> message?</p> <p>What&#8217;s so haunted about it is that the default behavior of the <code>WM_<wbr />INPUT­LANG­CHANGE­REQUEST</code> message is to change input language!</p> <p>For historical (and therefore now compatibility) reasons, when a hotkey-initiated input language change request is accepted, the system applies the change to all threads of that process. This means that all UI threads of the process need to be pumping messages so that they can receive the notification that their keyboard state has changed.</p> <p>In this case, the customer had a background thread that created a window but was not pumping messages. That prevented the language change from completing and caused the main UI thread to hang.</p> <p>The customer wanted to know if there was a way to configure their program so that hotkey-initiated input language changes don&#8217;t require all threads to be pumping messages. But that&#8217;s trying to solve too narrow a problem. If your thread has created a window, then it must pump messages. Today it&#8217;s causing trouble with input language changes. Tomorrow, it&#8217;s going to cause problems with DDE, and the day after tomorrow, it&#8217;s going to cause problems with theme changes.</p> <p>Even if you had a way to change the way language changes work, that&#8217;s just one of the problems that your non-responding thread is causing. You should fix the root cause: Either pump messages or destroy the window so that it is no longer a UI thread and is no longer obligated to pump messages.</p> <p>The post <a href="https://devblogs.microsoft.com/oldnewthing/20260513-00/?p=112318">The case of the hang when the user changed keyboard layouts</a> appeared first on <a href="https://devblogs.microsoft.com/oldnewthing">The Old New Thing</a>.</p>
Original Article
View Cached Full Text

Cached at: 05/16/26, 03:31 AM

# The case of the hang when the user changed keyboard layouts - The Old New Thing Source: [https://devblogs.microsoft.com/oldnewthing/20260513-00?p=112318](https://devblogs.microsoft.com/oldnewthing/20260513-00?p=112318) A customer reported that their program hung when the user changed keyboard layouts, say by using theWin\+Spacehotkey sequence\. They debugged it as far as observing that the foreground window in their application received a`WM\_INPUT­LANG­CHANGE­REQUEST`, and when that message was passed to`Def­Window­Proc`, the call never returned\. What’s so haunted about the`WM\_INPUT­LANG­CHANGE­REQUEST`message? What’s so haunted about it is that the default behavior of the`WM\_INPUT­LANG­CHANGE­REQUEST`message is to change input language\! For historical \(and therefore now compatibility\) reasons, when a hotkey\-initiated input language change request is accepted, the system applies the change to all threads of that process\. This means that all UI threads of the process need to be pumping messages so that they can receive the notification that their keyboard state has changed\. In this case, the customer had a background thread that created a window but was not pumping messages\. That prevented the language change from completing and caused the main UI thread to hang\. The customer wanted to know if there was a way to configure their program so that hotkey\-initiated input language changes don’t require all threads to be pumping messages\. But that’s trying to solve too narrow a problem\. If your thread has created a window, then it must pump messages\. Today it’s causing trouble with input language changes\. Tomorrow, it’s going to cause problems with DDE, and the day after tomorrow, it’s going to cause problems with theme changes\. Even if you had a way to change the way language changes work, that’s just one of the problems that your non\-responding thread is causing\. You should fix the root cause: Either pump messages or destroy the window so that it is no longer a UI thread and is no longer obligated to pump messages\. ### Category ### Topics ## Author ![Raymond Chen](https://devblogs.microsoft.com/oldnewthing/wp-content/uploads/sites/38/2019/02/RaymondChen_5in-150x150.jpg) Raymond has been involved in the evolution of Windows for more than 30 years\. In 2003, he began a Web site known as The Old New Thing which has grown in popularity far beyond his wildest imagination, a development which still gives him the heebie\-jeebies\. The Web site spawned a book, coincidentally also titled The Old New Thing \(Addison Wesley 2007\)\. He occasionally appears on the Windows Dev Docs Twitter account to tell stories which convey no useful information\.

Similar Articles

Understanding the rationale behind a rule when trying to circumvent it

The Old New Thing (Raymond Chen)

This article from Microsoft's Old New Thing blog explains the rationale behind best practices for Windows kernel callback functions, particularly why blocking or waiting on work items defeats their purpose, using a cautionary tale about drivers causing system hangs.