{"id":13200,"date":"2023-10-30T12:26:32","date_gmt":"2023-10-30T12:26:32","guid":{"rendered":"https:\/\/www.qec.tw\/?p=13200"},"modified":"2023-10-30T12:26:35","modified_gmt":"2023-10-30T12:26:35","slug":"mouse-controller-example","status":"publish","type":"post","link":"https:\/\/www.qec.tw\/zh\/86duino-reference\/usb\/mouse-controller-example\/","title":{"rendered":"\u6ed1\u9f20\u63a7\u5236\u5668\u7bc4\u4f8b"},"content":{"rendered":"<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>\/*\n Mouse Controller Example\n \n Shows the output of a USB Mouse connected to \n the Native USB port on an Arduino Due Board.\n \n created 8 Oct 2012\n by Cristian Maglie\n \n http:\/\/arduino.cc\/en\/Tutorial\/MouseController\n \n This sample code is part of the public domain.\n *\/\n\n\/\/ Require mouse control library\n#include &lt;MouseController.h&gt;\n\n\/\/ Initialize USB Controller\nUSBHost usb;\n\n\/\/ Attach mouse controller to USB\nMouseController mouse(usb);\n\n\/\/ variables for mouse button states\nboolean leftButton = false;\nboolean middleButton = false;\nboolean rightButton = false;\n\n\/\/ This function intercepts mouse movements\nvoid mouseMoved() {\n  Serial.print(&quot;Move: &quot;);\n  Serial.print(mouse.getXChange());\n  Serial.print(&quot;, &quot;);\n  Serial.println(mouse.getYChange());\n}\n\n\/\/ This function intercepts mouse movements while a button is pressed\nvoid mouseDragged() {\n  Serial.print(&quot;DRAG: &quot;);\n  Serial.print(mouse.getXChange());\n  Serial.print(&quot;, &quot;);\n  Serial.println(mouse.getYChange());\n}\n\n\/\/ This function intercepts mouse button press\nvoid mousePressed() {\n  Serial.print(&quot;Pressed: &quot;);\n  if (mouse.getButton(LEFT_BUTTON)){\n    Serial.print(&quot;L&quot;);\n    leftButton = true;\n  }\n  if (mouse.getButton(MIDDLE_BUTTON)){\n    Serial.print(&quot;M&quot;);\n    middleButton = true;\n  }\n  if (mouse.getButton(RIGHT_BUTTON)){\n    Serial.print(&quot;R&quot;);\n    Serial.println();\n    rightButton = true;\n  }\n}\n\n\/\/ This function intercepts mouse button release\nvoid mouseReleased() {\n  Serial.print(&quot;Released: &quot;);\n  if (!mouse.getButton(LEFT_BUTTON) &amp;&amp; leftButton == true) {\n    Serial.print(&quot;L&quot;);\n    leftButton = false;\n  }\n  if (!mouse.getButton(MIDDLE_BUTTON) &amp;&amp; middleButton == true) {\n    Serial.print(&quot;M&quot;);\n    middleButton = false;\n  }\n  if (!mouse.getButton(RIGHT_BUTTON) &amp;&amp; rightButton == true) {\n    Serial.print(&quot;R&quot;);\n    rightButton = false;\n  }\n  Serial.println();\n}\n\nvoid setup()\n{\n  Serial.begin(9600);\n  Serial.println(&quot;Program started&quot;);\n  delay(200);\n}\n\nvoid loop()\n{\n  \/\/ Process USB tasks\n  usb.Task();\n}\n<\/pre><\/div>","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":13201,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"set","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[215],"tags":[162],"class_list":["post-13200","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-usb","tag-86duino"],"_links":{"self":[{"href":"https:\/\/www.qec.tw\/zh\/wp-json\/wp\/v2\/posts\/13200","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.qec.tw\/zh\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.qec.tw\/zh\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.qec.tw\/zh\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.qec.tw\/zh\/wp-json\/wp\/v2\/comments?post=13200"}],"version-history":[{"count":0,"href":"https:\/\/www.qec.tw\/zh\/wp-json\/wp\/v2\/posts\/13200\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.qec.tw\/zh\/wp-json\/wp\/v2\/media\/13201"}],"wp:attachment":[{"href":"https:\/\/www.qec.tw\/zh\/wp-json\/wp\/v2\/media?parent=13200"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.qec.tw\/zh\/wp-json\/wp\/v2\/categories?post=13200"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.qec.tw\/zh\/wp-json\/wp\/v2\/tags?post=13200"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}