{"id":2373,"date":"2013-12-16T07:00:00","date_gmt":"2013-12-16T07:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2013\/12\/16\/disabling-the-prtsc-key-by-blocking-input\/"},"modified":"2013-12-16T07:00:00","modified_gmt":"2013-12-16T07:00:00","slug":"disabling-the-prtsc-key-by-blocking-input","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20131216-00\/?p=2373","title":{"rendered":"Disabling the PrtSc key by blocking input"},"content":{"rendered":"<p>\nA customer asked how to disable the\n<kbd>PrtSc<\/kbd> key in the On-Screen Keyboard.\n<\/p>\n<p>\nThere is no way to disable the\n<kbd>PrtSc<\/kbd> key in the On-Screen Keyboard.\nThe On-Screen Keyboard shows a keyboard, and you can click any\nvirtual key you like.\nThere is no policy to remove specific keys from the On-Screen Keyboard.\n<\/p>\n<p>\nBut this was a case of a customer breaking down a problem and\nasking a question about a specific part of the problem\ninstead of presenting the entire problem so that a\nsolution to the overall problem could be developed.\n<\/p>\n<p>\nThe customer&#8217;s real goal was to disable the\n<kbd>PrtSc<\/kbd> key in general.\nThey had figured out how to disable it on their physical keyboards\nby using the PS\/2\n<a HREF=\"http:\/\/msdn.microsoft.com\/en-us\/windows\/hardware\/gg463447\">\nscan code mapper<\/a>,\nbut they found that users could circumvent the feature by\nusing the On-Screen Keyboard, so they asked if there was something\nthey could do about the\nOn-Screen Keyboard.\n<\/p>\n<p>\nThey didn&#8217;t mention this when they asked the original question,\nso I replied by saying,\n&#8220;The mechanism for blocking the screen capture functionality\nin the window manager should work regardless of whether the\nrequest came from the physical keyboard or the virtual keyboard.&#8221;\n<\/p>\n<p>\nNaturally, the customer liaison decided to direct follow-up questions\nto me directly,\neven though I was replying from my phone while doing a quick\nemail check while on vacation,\nand I had to remind him that\n<a HREF=\"http:\/\/blogs.msdn.com\/b\/oldnewthing\/archive\/2006\/10\/19\/844008.aspx\">\nmy response to your message should not be interpreted as meaning\nthat I had taken responsibility for driving your issue to resolution<\/a>.\nI had to steer the thread back to the distribution list so that\nsomebody else could pick up the ball while I was out of the office.\n(Either that, or the customer ends up waiting until the next time\nI feel like checking email while on vacation, which could be quite\na while.)\n<\/p>\n<p>\nThe solution to the original problem is not to try to identify\nevery possible source of a\n<kbd>PrtSc<\/kbd> keypress and block it there,\nbecause even a simple script can\n<a HREF=\"http:\/\/msdn.microsoft.com\/library\/8c6yea83\">\nuse the <code>Send&shy;Keys<\/code> method to inject the\n<kbd>PrtSc<\/kbd> key<\/a>.\n<\/p>\n<p>\nYou block the message in the window manager by installing\na low-level keyboard hook that rejects the\n<code>VK_SNAP&shy;SHOT<\/code> key.\n<\/p>\n<p>\nToday&#8217;s Little Program is a printscreen blocker.\nRemember, Little Programs have little to no error checking,\nbecause that&#8217;s the way they roll.\n<\/p>\n<p>\nTake our\n<a HREF=\"http:\/\/blogs.msdn.com\/b\/oldnewthing\/archive\/2003\/07\/23\/54576.aspx\">\nscratch program<\/a>\nand add the following lines of code:\n<\/p>\n<pre>\n<font COLOR=\"blue\">HHOOK g_hhk;\nLRESULT CALLBACK KHook(int nCode, WPARAM wParam, LPARAM lParam)\n{\n if (nCode == HC_ACTION) {\n if (wParam == WM_KEYDOWN || wParam == WM_SYSKEYDOWN) {\n  PKBDLLHOOKSTRUCT phs = (PKBDLLHOOKSTRUCT)lParam;\n  if (phs-&gt;vkCode == VK_SNAPSHOT) {\n   MessageBeep(0); \/\/ annoying beep\n   return 1; \/\/ block the key\n  }\n }\n }\n return CallNextHookEx(g_hhk, nCode, wParam, lParam);\n}<\/font>\n...\n    ShowWindow(hwnd, nShowCmd);\n    <font COLOR=\"blue\">g_hhk = SetWindowsHookEx(WH_KEYBOARD_LL, KHook,\n                             NULL, 0);<\/font>\n    while (GetMessage(&amp;msg, NULL, 0, 0)) {\n        TranslateMessage(&amp;msg);\n        DispatchMessage(&amp;msg);\n    }\n    <font COLOR=\"blue\">UnhookWindowsHookEx(g_hhk);<\/font>\n<\/pre>\n<p>\nThis program installs a low-level keyboard hook which\nlistens for presses of the <code>VK_SNAP&shy;SHOT<\/code> key,\nand if it sees one, it beeps and then returns <code>1<\/code>\nto block further processing.\n<\/p>\n<p>\nNote that we are using a global solution to a local problem.\nIf you want to block <kbd>PrtSc<\/kbd> because you have sensitive\ninformation in your application that you don&#8217;t want captured,\nthen\n<a HREF=\"http:\/\/blogs.msdn.com\/b\/oldnewthing\/archive\/2013\/06\/03\/10422964.aspx\">\ntag your window to be excluded from screen capturing<\/a>.\nThat way, the user can still capture other windows.\nIt also tells other screen capturing programs\nto exclude your window from the capture.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A customer asked how to disable the PrtSc key in the On-Screen Keyboard. There is no way to disable the PrtSc key in the On-Screen Keyboard. The On-Screen Keyboard shows a keyboard, and you can click any virtual key you like. There is no policy to remove specific keys from the On-Screen Keyboard. But this [&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-2373","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>A customer asked how to disable the PrtSc key in the On-Screen Keyboard. There is no way to disable the PrtSc key in the On-Screen Keyboard. The On-Screen Keyboard shows a keyboard, and you can click any virtual key you like. There is no policy to remove specific keys from the On-Screen Keyboard. But this [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/2373","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=2373"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/2373\/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=2373"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=2373"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=2373"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}