{"id":35513,"date":"2005-05-30T09:03:11","date_gmt":"2005-05-30T09:03:11","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2005\/05\/30\/you-cant-simulate-keyboard-input-with-postmessage\/"},"modified":"2005-05-30T09:03:11","modified_gmt":"2005-05-30T09:03:11","slug":"you-cant-simulate-keyboard-input-with-postmessage","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20050530-11\/?p=35513","title":{"rendered":"You can&#039;t simulate keyboard input with PostMessage"},"content":{"rendered":"<p>Some people attempt to simulate keyboard input to an application by posting keyboard input messages, but this is not reliable for many reasons.\n First of all, keyboard input is a more complicated matter than those who imprinted on the English keyboard realize. Languages with accent marks have dead keys, Far East languages have a variety of Input Method Editors, and I have no idea how complex script languages handle input. There&#8217;s more to typing a character than just pressing a key.\n Second, even if you manage to post the input messages into the target window&#8217;s queue, that doesn&#8217;t update the keyboard shift states.  When the code behind the window calls <a href=\"http:\/\/msdn.microsoft.com\/library\/en-us\/winui\/winui\/windowsuserinterface\/userinput\/keyboardinput\/keyboardinputreference\/keyboardinputfunctions\/getkeystate.asp\"> the <code>GetKeyState<\/code> function<\/a> or <a href=\"http:\/\/msdn.microsoft.com\/library\/en-us\/winui\/winui\/windowsuserinterface\/userinput\/keyboardinput\/keyboardinputreference\/keyboardinputfunctions\/getasynckeystate.asp\"> the <code>GetAsyncKeyState<\/code> function<\/a>, it&#8217;s going to see the &#8220;real&#8221; shift state and not the fake state that your posted messages have generated.<\/p>\n<p> <a href=\"http:\/\/msdn.microsoft.com\/library\/en-us\/winui\/winui\/windowsuserinterface\/userinput\/keyboardinput\/keyboardinputreference\/keyboardinputfunctions\/sendinput.asp\"> The <code>SendInput<\/code> function<\/a> was designed for injecting input into Windows. If you use that function, then at least the shift states will be reported correctly.  (I can&#8217;t help you with the complex input problem, though.) <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Some people attempt to simulate keyboard input to an application by posting keyboard input messages, but this is not reliable for many reasons. First of all, keyboard input is a more complicated matter than those who imprinted on the English keyboard realize. Languages with accent marks have dead keys, Far East languages have a variety [&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":[25],"class_list":["post-35513","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>Some people attempt to simulate keyboard input to an application by posting keyboard input messages, but this is not reliable for many reasons. First of all, keyboard input is a more complicated matter than those who imprinted on the English keyboard realize. Languages with accent marks have dead keys, Far East languages have a variety [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/35513","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=35513"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/35513\/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=35513"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=35513"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=35513"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}