{"id":7723,"date":"2012-05-02T07:00:00","date_gmt":"2012-05-02T07:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2012\/05\/02\/why-is-there-sometimes-a-long-delay-between-pressing-a-hotkey-for-a-shortcut-and-opening-the-shortcut\/"},"modified":"2020-04-24T17:08:35","modified_gmt":"2020-04-25T00:08:35","slug":"why-is-there-sometimes-a-long-delay-between-pressing-a-hotkey-for-a-shortcut-and-opening-the-shortcut","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20120502-00\/?p=7723\/","title":{"rendered":"Why is there sometimes a long delay between pressing a hotkey for a shortcut and opening the shortcut?"},"content":{"rendered":"<p>Via a customer liaison, we received a problem report from a customer.<\/p>\n<blockquote class=\"q\">\n<p>The customer is facing issues with delayed desponses to opening a .lnk file by pressing its keyboard shortcut hotkey. This delay does not appear when the shortcut is double-clicked.<\/p>\n<p>For example, the customer has created a shortcut to Notepad and assigned it the shortcut <kbd>Ctrl<\/kbd>+<kbd>Alt<\/kbd>+<kbd>X<\/kbd>. Pressing the keyboard combination sometimes takes 5 or 6 seconds for Notepad to open. As noted above, double-clicking on the shortcut causes Notepad to open without delay.<\/p>\n<p>This issue is not consistently reproducible, but it appears to be independent of the shortcut file itself. Any shortcut with a hotkey exhibits this problem.<\/p>\n<p>All the shortcuts in question are on the desktop.<\/p>\n<\/blockquote>\n<p>The short answer is &#8220;There is a program running on your machine that occasionally stops responding to messages. If you press a shortcut hotkey during those moments, you will experience this problem. Identify the program that stops responding to messages and fix it.&#8221;<\/p>\n<p>Okay, that sort of cuts to the chase, but the interesting part is the journey, not the destination.<\/p>\n<p>First, observe that if you associate a hotkey with a shortcut to say Notepad, and you press the hotkey twice, you do <i>not<\/i> get two copies of Notepad. The first time you press the hotkey, Notepad launches, but the second time you press the hotkey, focus is put on the <i>existing<\/i> copy of Notepad. This is one of those things that&#8217;s so natural you may not even realize that it&#8217;s happening.<\/p>\n<p>When you press the hotkey assigned to a shortcut, Explorer receives the hotkey and needs to decide what to do about it. Before it can launch the shortcut, it needs to see if the shortcut target already has a window open, in which case it should just switch to that window.<\/p>\n<p>Finding out whether a window has a hotkey is done by sending the window the <code>WM_GETHOTKEY<\/code> message. When you press a hotkey that is assigned to a shortcut, Explorer goes to all the windows already on the screen and asks each one, &#8220;Hey, what&#8217;s your hotkey?&#8221; If any window says, &#8220;My hotkey is <kbd>Ctrl<\/kbd>+<kbd>Alt<\/kbd>+<kbd>X<\/kbd>,&#8221; then Explorer says, &#8220;Oh, sorry to step on your toes. The user pressed your hotkey, so here, go ahead and take focus.&#8221;<\/p>\n<p>If no window cops to having <kbd>Ctrl<\/kbd>+<kbd>Alt<\/kbd>+<kbd>X<\/kbd> as its hotkey, Explorer says, &#8220;Okay, well, then I guess I have to make one.&#8221; It launches Notepad and tells it, &#8220;Oh, and your hotkey is <kbd>Ctrl<\/kbd>+<kbd>Alt<\/kbd>+<kbd>X<\/kbd>.&#8221;<\/p>\n<p>If there is a window that is not responding to messages, then when Explorer asks it, &#8220;Hey, what&#8217;s your hotkey?&#8221;, the window just sits there and doesn&#8217;t answer. After about three seconds, Explorer gives up. &#8220;Yeesh, I was just asking a question. Don&#8217;t have to give me the silent treatment.&#8221;<\/p>\n<p>And that petulant window is the source of the 3-second delay. It takes Explorer 3 seconds before it finally gives up and says, &#8220;Forget it. Even if that was somebody&#8217;s hotkey, they&#8217;re being a jerk, so I&#8217;m just going to pretend they didn&#8217;t have a hotkey. Let me open a new window instead and just deal with the hotkey conflict.&#8221;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Via a customer liaison, we received a problem report from a customer. The customer is facing issues with delayed desponses to opening a .lnk file by pressing its keyboard shortcut hotkey. This delay does not appear when the shortcut is double-clicked. For example, the customer has created a shortcut to Notepad and assigned it the [&hellip;]<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[26],"class_list":["post-7723","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-other"],"acf":[],"blog_post_summary":"<p>Via a customer liaison, we received a problem report from a customer. The customer is facing issues with delayed desponses to opening a .lnk file by pressing its keyboard shortcut hotkey. This delay does not appear when the shortcut is double-clicked. For example, the customer has created a shortcut to Notepad and assigned it the [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/7723","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=7723"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/7723\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=7723"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=7723"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=7723"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}