{"id":236,"date":"2009-10-11T17:05:40","date_gmt":"2009-10-11T11:35:40","guid":{"rendered":"http:\/\/live-42gears-site.pantheonsite.io\/blog\/?p=236"},"modified":"2023-01-04T05:52:53","modified_gmt":"2023-01-04T05:52:53","slug":"simulating-key-presses-with-keybd_event-function","status":"publish","type":"post","link":"https:\/\/www.42gears.com\/nl\/blog\/simulating-key-presses-with-keybd_event-function\/","title":{"rendered":"Simulating key presses in your program with keybd_event function"},"content":{"rendered":"<p>Out of need or curiosity you might want to know how to send key presses from your native application. The core of the solution involves calling keybd_event() function which has the following prototype.<\/p>\n<p><em>VOID keybd_event(BYTE bVk, BYTE bScan, DWORD dwFlags, DWORD dwExtraInfo);<\/em><\/p>\n<p>bVk is the virtual-key code of the character.  bScan is the hardware scan code. dwFlags is an important field. If KEYEVENTF_KEYUP is specified in dwFlags field, the key is being released. If not specified, the key is being pressed.<\/p>\n<p>Here is a function which simulates pressing of alphanumeric characters. See winuser.h for all available virtual key codes.<\/p>\n<blockquote><p>void SendStringKeys(char* pszChars)<br \/>\n{<br \/>\nwhile (*pszChars != NULL)<br \/>\n{<br \/>\nif ( (*pszChars &gt;= &#8216;A&#8217;) &amp;&amp; (*pszChars &lt;= &#8216;Z&#8217;) )<br \/>\n\t\t\tkeybd_event(VK_SHIFT, 0, KEYEVENTF_SILENT, 0); <\/p>\n<p>\t\tkeybd_event(toupper(*pszChars), 0, KEYEVENTF_SILENT, 0);<br \/>\n\t\tkeybd_event(toupper(*pszChars), 0, KEYEVENTF_KEYUP|KEYEVENTF_SILENT, 0);<\/p>\n<p>\t\tif ( (*pszChars &gt;= &#8216;A&#8217;) &amp;&amp; (*pszChars &lt;= &#8216;Z&#8217;) )<br \/>\n\t\t\tkeybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP|KEYEVENTF_SILENT, 0); <\/p>\n<p>\t\tpszChars++;<br \/>\n\t}<br \/>\n}<\/p><\/blockquote>\n<p>And here is an example of how to call <em>SendStringKeys<\/em> function.<\/p>\n<blockquote><p>int _tmain(int argc, _TCHAR* argv[])<br \/>\n{<br \/>\nSendStringKeys(&#8220;Hello World.&#8221;);<br \/>\nreturn 0;<br \/>\n}<\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>Out of need or curiosity you might want to know how to send key presses from your native application. The core of the solution involves calling keybd_event() function which has the following prototype. VOID keybd_event(BYTE bVk, BYTE bScan, DWORD dwFlags, DWORD dwExtraInfo); bVk is the virtual-key code of the character. bScan is the hardware scan&hellip;<\/p>\n","protected":false},"author":7,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[39,8,31],"tags":[54,47],"class_list":["post-236","post","type-post","status-publish","format-standard","hentry","category-development","category-general","category-windows-mobile","tag-programming","tag-windows-mobile"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v24.6 (Yoast SEO v24.6) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Simulating key presses in your program with keybd_event function - 42Gears Mobility Systems<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.42gears.com\/blog\/simulating-key-presses-with-keybd_event-function\/\" \/>\n<meta property=\"og:locale\" content=\"nl_NL\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Simulating key presses in your program with keybd_event function\" \/>\n<meta property=\"og:description\" content=\"Out of need or curiosity you might want to know how to send key presses from your native application. The core of the solution involves calling keybd_event() function which has the following prototype. VOID keybd_event(BYTE bVk, BYTE bScan, DWORD dwFlags, DWORD dwExtraInfo); bVk is the virtual-key code of the character. bScan is the hardware scan&hellip;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.42gears.com\/blog\/simulating-key-presses-with-keybd_event-function\/\" \/>\n<meta property=\"og:site_name\" content=\"42Gears Mobility Systems\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/42gears\" \/>\n<meta property=\"article:published_time\" content=\"2009-10-11T11:35:40+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-01-04T05:52:53+00:00\" \/>\n<meta name=\"author\" content=\"42Gears Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@42Gears\" \/>\n<meta name=\"twitter:site\" content=\"@42Gears\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"42Gears Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.42gears.com\/blog\/simulating-key-presses-with-keybd_event-function\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.42gears.com\/es\/blog\/simulating-key-presses-with-keybd_event-function\/\"},\"author\":{\"name\":\"42Gears Team\",\"@id\":\"https:\/\/www.42gears.com\/#\/schema\/person\/28a14f2c32de4a7903ac672579a88a2d\"},\"headline\":\"Simulating key presses in your program with keybd_event function\",\"datePublished\":\"2009-10-11T11:35:40+00:00\",\"dateModified\":\"2023-01-04T05:52:53+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.42gears.com\/es\/blog\/simulating-key-presses-with-keybd_event-function\/\"},\"wordCount\":189,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.42gears.com\/#organization\"},\"keywords\":[\"programming\",\"Windows Mobile\"],\"articleSection\":[\"Development\",\"General\",\"Windows Mobile\"],\"inLanguage\":\"nl\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.42gears.com\/blog\/simulating-key-presses-with-keybd_event-function\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.42gears.com\/es\/blog\/simulating-key-presses-with-keybd_event-function\/\",\"url\":\"https:\/\/www.42gears.com\/blog\/simulating-key-presses-with-keybd_event-function\/\",\"name\":\"Simulating key presses in your program with keybd_event function - 42Gears Mobility Systems\",\"isPartOf\":{\"@id\":\"https:\/\/www.42gears.com\/#website\"},\"datePublished\":\"2009-10-11T11:35:40+00:00\",\"dateModified\":\"2023-01-04T05:52:53+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/www.42gears.com\/blog\/simulating-key-presses-with-keybd_event-function\/#breadcrumb\"},\"inLanguage\":\"nl\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.42gears.com\/blog\/simulating-key-presses-with-keybd_event-function\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.42gears.com\/blog\/simulating-key-presses-with-keybd_event-function\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.42gears.com\/nl\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Simulating key presses in your program with keybd_event function\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.42gears.com\/#website\",\"url\":\"https:\/\/www.42gears.com\/\",\"name\":\"42Gears Mobility Systems\",\"description\":\"Mobile Device Management (MDM), Mobile Security &amp; Mobile Device Lockdown\",\"publisher\":{\"@id\":\"https:\/\/www.42gears.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.42gears.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"nl\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.42gears.com\/#organization\",\"name\":\"MDM - 42Gears\",\"url\":\"https:\/\/www.42gears.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"nl\",\"@id\":\"https:\/\/www.42gears.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.42gears.com\/wp-content\/uploads\/2018\/12\/Featured-Image-42Gears-logo.png\",\"contentUrl\":\"https:\/\/www.42gears.com\/wp-content\/uploads\/2018\/12\/Featured-Image-42Gears-logo.png\",\"width\":499,\"height\":330,\"caption\":\"MDM - 42Gears\"},\"image\":{\"@id\":\"https:\/\/www.42gears.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/42gears\",\"https:\/\/x.com\/42Gears\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.42gears.com\/#\/schema\/person\/28a14f2c32de4a7903ac672579a88a2d\",\"name\":\"42Gears Team\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"nl\",\"@id\":\"https:\/\/www.42gears.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/7d257fb658a429b8607872336eac3833a8314ca3ca67d72c90ceeddc7700c42e?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/7d257fb658a429b8607872336eac3833a8314ca3ca67d72c90ceeddc7700c42e?s=96&d=mm&r=g\",\"caption\":\"42Gears Team\"}}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Simulating key presses in your program with keybd_event function - 42Gears Mobility Systems","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.42gears.com\/blog\/simulating-key-presses-with-keybd_event-function\/","og_locale":"nl_NL","og_type":"article","og_title":"Simulating key presses in your program with keybd_event function","og_description":"Out of need or curiosity you might want to know how to send key presses from your native application. The core of the solution involves calling keybd_event() function which has the following prototype. VOID keybd_event(BYTE bVk, BYTE bScan, DWORD dwFlags, DWORD dwExtraInfo); bVk is the virtual-key code of the character. bScan is the hardware scan&hellip;","og_url":"https:\/\/www.42gears.com\/blog\/simulating-key-presses-with-keybd_event-function\/","og_site_name":"42Gears Mobility Systems","article_publisher":"https:\/\/www.facebook.com\/42gears","article_published_time":"2009-10-11T11:35:40+00:00","article_modified_time":"2023-01-04T05:52:53+00:00","author":"42Gears Team","twitter_card":"summary_large_image","twitter_creator":"@42Gears","twitter_site":"@42Gears","twitter_misc":{"Written by":"42Gears Team","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.42gears.com\/blog\/simulating-key-presses-with-keybd_event-function\/#article","isPartOf":{"@id":"https:\/\/www.42gears.com\/es\/blog\/simulating-key-presses-with-keybd_event-function\/"},"author":{"name":"42Gears Team","@id":"https:\/\/www.42gears.com\/#\/schema\/person\/28a14f2c32de4a7903ac672579a88a2d"},"headline":"Simulating key presses in your program with keybd_event function","datePublished":"2009-10-11T11:35:40+00:00","dateModified":"2023-01-04T05:52:53+00:00","mainEntityOfPage":{"@id":"https:\/\/www.42gears.com\/es\/blog\/simulating-key-presses-with-keybd_event-function\/"},"wordCount":189,"commentCount":0,"publisher":{"@id":"https:\/\/www.42gears.com\/#organization"},"keywords":["programming","Windows Mobile"],"articleSection":["Development","General","Windows Mobile"],"inLanguage":"nl","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.42gears.com\/blog\/simulating-key-presses-with-keybd_event-function\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.42gears.com\/es\/blog\/simulating-key-presses-with-keybd_event-function\/","url":"https:\/\/www.42gears.com\/blog\/simulating-key-presses-with-keybd_event-function\/","name":"Simulating key presses in your program with keybd_event function - 42Gears Mobility Systems","isPartOf":{"@id":"https:\/\/www.42gears.com\/#website"},"datePublished":"2009-10-11T11:35:40+00:00","dateModified":"2023-01-04T05:52:53+00:00","breadcrumb":{"@id":"https:\/\/www.42gears.com\/blog\/simulating-key-presses-with-keybd_event-function\/#breadcrumb"},"inLanguage":"nl","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.42gears.com\/blog\/simulating-key-presses-with-keybd_event-function\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.42gears.com\/blog\/simulating-key-presses-with-keybd_event-function\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.42gears.com\/nl\/"},{"@type":"ListItem","position":2,"name":"Simulating key presses in your program with keybd_event function"}]},{"@type":"WebSite","@id":"https:\/\/www.42gears.com\/#website","url":"https:\/\/www.42gears.com\/","name":"42Gears Mobility Systems","description":"Mobile Device Management (MDM), Mobile Security &amp; Mobile Device Lockdown","publisher":{"@id":"https:\/\/www.42gears.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.42gears.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"nl"},{"@type":"Organization","@id":"https:\/\/www.42gears.com\/#organization","name":"MDM - 42Gears","url":"https:\/\/www.42gears.com\/","logo":{"@type":"ImageObject","inLanguage":"nl","@id":"https:\/\/www.42gears.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.42gears.com\/wp-content\/uploads\/2018\/12\/Featured-Image-42Gears-logo.png","contentUrl":"https:\/\/www.42gears.com\/wp-content\/uploads\/2018\/12\/Featured-Image-42Gears-logo.png","width":499,"height":330,"caption":"MDM - 42Gears"},"image":{"@id":"https:\/\/www.42gears.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/42gears","https:\/\/x.com\/42Gears"]},{"@type":"Person","@id":"https:\/\/www.42gears.com\/#\/schema\/person\/28a14f2c32de4a7903ac672579a88a2d","name":"42Gears Team","image":{"@type":"ImageObject","inLanguage":"nl","@id":"https:\/\/www.42gears.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/7d257fb658a429b8607872336eac3833a8314ca3ca67d72c90ceeddc7700c42e?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/7d257fb658a429b8607872336eac3833a8314ca3ca67d72c90ceeddc7700c42e?s=96&d=mm&r=g","caption":"42Gears Team"}}]}},"author_meta":{"ID":"7","user_nicename":"42gears","user_email":"42gears@gmail.com","user_registered":"2015-07-15 04:55:37","display_name":"42Gears Team","first_name":"42Gears","last_name":"Team"},"_links":{"self":[{"href":"https:\/\/www.42gears.com\/nl\/wp-json\/wp\/v2\/posts\/236","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.42gears.com\/nl\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.42gears.com\/nl\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.42gears.com\/nl\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/www.42gears.com\/nl\/wp-json\/wp\/v2\/comments?post=236"}],"version-history":[{"count":2,"href":"https:\/\/www.42gears.com\/nl\/wp-json\/wp\/v2\/posts\/236\/revisions"}],"predecessor-version":[{"id":84900,"href":"https:\/\/www.42gears.com\/nl\/wp-json\/wp\/v2\/posts\/236\/revisions\/84900"}],"wp:attachment":[{"href":"https:\/\/www.42gears.com\/nl\/wp-json\/wp\/v2\/media?parent=236"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.42gears.com\/nl\/wp-json\/wp\/v2\/categories?post=236"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.42gears.com\/nl\/wp-json\/wp\/v2\/tags?post=236"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}