{"id":24753,"date":"2007-10-17T10:00:00","date_gmt":"2007-10-17T10:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2007\/10\/17\/the-wrong-way-to-check-whether-the-mouse-buttons-have-been-swapped\/"},"modified":"2007-10-17T10:00:00","modified_gmt":"2007-10-17T10:00:00","slug":"the-wrong-way-to-check-whether-the-mouse-buttons-have-been-swapped","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20071017-00\/?p=24753","title":{"rendered":"The wrong way to check whether the mouse buttons have been swapped"},"content":{"rendered":"<p>\nBack in the late 1990&#8217;s, the window manager team received a bug\nthat said that sometimes the mouse button state\ngot messed up and the computer acted\nas if the buttons were stuck down.\nFurther investigation revealed that it occurred only when one\nparticular program was running, and only if the user had enabled mouse\nbutton swapping.\n<\/p>\n<p>\nThe reason is that the program in question detected whether the\nmouse buttons were swapped with a function like this:\n<\/p>\n<pre>\n<i>\/\/ do not use this function\nBOOL AreMouseButtonsSwapped()\n{\n BOOL fWasSwapped = SwapMouseButton(FALSE);\n if (fWasSwapped) SwapMouseButton(TRUE);\n return fWasSwapped;\n}<\/i>\n<\/pre>\n<p>\nThe <code>SwapMouseButton<\/code> function changes the button swap state\nand returns the old state.\nThe way the program checked whether the buttons were swapped\nwas by unswapping the buttons and using the return value to\ndetermine what the previous setting was,\nthen re-swapping the buttons if the previous setting was\n&#8220;Yes, they were swapped.&#8221;\n<\/p>\n<p>\nIf you started with the buttons swapped, running this function\ncreated a tiny window where the buttons were momentarily unswapped.\nAnd if you were unlucky enough to click the mouse during this\nwindow of vulnerability, the program saw one mouse button go down\nand a different button come up!\nEven though it was the same physical button each time,\nit was a different logical button, since the meanings of the buttons\nhad changed.\n<\/p>\n<p>\nThe correct way of detecting whether mouse buttons are swapped\nis just to ask non-intrusively.\n<\/p>\n<pre>\nBOOL AreMouseButtonsSwapped()\n{\n return GetSystemMetrics(SM_SWAPBUTTON);\n}\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Back in the late 1990&#8217;s, the window manager team received a bug that said that sometimes the mouse button state got messed up and the computer acted as if the buttons were stuck down. Further investigation revealed that it occurred only when one particular program was running, and only if the user had enabled mouse [&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-24753","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>Back in the late 1990&#8217;s, the window manager team received a bug that said that sometimes the mouse button state got messed up and the computer acted as if the buttons were stuck down. Further investigation revealed that it occurred only when one particular program was running, and only if the user had enabled mouse [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/24753","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=24753"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/24753\/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=24753"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=24753"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=24753"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}