ESP32-S2-Saola-1 模拟鼠标画圈
<div class='showpostmsg'><p>使用usb hid,模拟鼠标的动作。并用GPIO0(板子的BOOT引脚)作为按钮,按下后模拟鼠标左键。</p><p> </p>
<pre>
<code class="language-python"># 在这里写上你的代码 :-)
from math import sin, cos, pi
import usb_hid
from adafruit_hid.mouse import Mouse
import time
import board
import digitalio
mouse = Mouse(usb_hid.devices)
button = digitalio.DigitalInOut(board.IO0)
button.direction = digitalio.Direction.INPUT
n = 0
while 1:
t = n * pi / 180
x, y = round(20*cos(t)), round(20*sin(t))
mouse.move(x, y)
n += 10
if not button.value:
mouse.click(Mouse.LEFT_BUTTON)
time.sleep(0.03)
</code></pre>
<p> </p>
</div><script> var loginstr = '<div class="locked">查看本帖全部内容,请<a href="javascript:;" style="color:#e60000" class="loginf">登录</a>或者<a href="https://bbs.eeworld.com.cn/member.php?mod=register_eeworld.php&action=wechat" style="color:#e60000" target="_blank">注册</a></div>';
if(parseInt(discuz_uid)==0){
(function($){
var postHeight = getTextHeight(400);
$(".showpostmsg").html($(".showpostmsg").html());
$(".showpostmsg").after(loginstr);
$(".showpostmsg").css({height:postHeight,overflow:"hidden"});
})(jQuery);
} </script><script type="text/javascript">(function(d,c){var a=d.createElement("script"),m=d.getElementsByTagName("script"),eewurl="//counter.eeworld.com.cn/pv/count/";a.src=eewurl+c;m.parentNode.insertBefore(a,m)})(document,523)</script> <p>运行前需要先将adafruit_hid库复制到CIRCUITPY磁盘的lib目录中,py文件或者mpy格式文件都可以。库文件需要到adafruit的网站下载。</p>
页:
[1]