Created
May 19, 2022 07:36
-
-
Save jimmy947788/520bab31ccbc0fd6edcccbd7e8ea02ed to your computer and use it in GitHub Desktop.
this is arduino micro press button and exeute command
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Keyboard.h> | |
const int BTN2_PIN = 2; // input pin for pushbutto | |
const int BTN3_PIN = 3; // input pin for pushbutton | |
int btn2_prevState; //紀錄按紐2上次一次狀態 | |
int btn3_prevState; //紀錄按紐3上次一次狀態 | |
// 叫出執行視窗 win + R 執行 | |
void WinRun(String cmd){ | |
Keyboard.press(KEY_LEFT_GUI); // WIN鍵 | |
delay(50); | |
Keyboard.press('r'); | |
delay(50); | |
Keyboard.release(KEY_LEFT_GUI); | |
Keyboard.release('r'); | |
delay(300); | |
// 執行視窗輸入指令 : 叫出[命令列]視窗 | |
Keyboard.println(cmd); | |
} | |
//Arduino 初始化函數(只跑一次) *必要 | |
void setup() { | |
// put your setup code here, to run once: | |
pinMode(BTN2_PIN, INPUT); | |
pinMode(BTN3_PIN, INPUT); | |
Keyboard.begin(); // initialize control over the keyboard: | |
btn2_prevState = digitalRead(BTN2_PIN); | |
btn3_prevState = digitalRead(BTN3_PIN); | |
} | |
//Arduino 重複執行函數 *必要 | |
void loop() { | |
// put your main code here, to run repeatedly: | |
int btn2_State = digitalRead(BTN2_PIN); | |
if (btn2_State == LOW && btn2_prevState == HIGH) | |
{ | |
//模擬按下 Win + R 執行命令 | |
WinRun("chcp 437 "); //切換輸入法到英文 確保後面指令都是正確 | |
delay(300); | |
//模擬按下 Win + R 執行命令 | |
WinRun("cmd "); //叫出命令視窗 | |
delay(1000); | |
// 執行 ping 命令 | |
//Keyboard.println("ping 8.8.8.8 -t "); | |
Keyboard.println("start notepad.exe "); | |
delay(1500); | |
Keyboard.println("Hello, I am Jimmy~~ \n\nEmai:[email protected]"); | |
delay(500); | |
} | |
btn2_prevState = digitalRead(BTN2_PIN); | |
int btn3_State = digitalRead(BTN3_PIN); | |
if (btn3_State == LOW && btn3_prevState == HIGH) | |
{ | |
//模擬按下 Win + R 執行命令 | |
WinRun("chcp 437 "); //切換輸入法到英文 確保後面指令都是正確 | |
delay(300); | |
//模擬按下 Win + R 執行命令 | |
WinRun("cmd "); //叫出命令視窗 | |
delay(1000); | |
// 執行 start 開啟網頁 | |
Keyboard.println("start https://github.com/jimmy947788 & exit "); | |
delay(500); | |
} | |
btn3_prevState = digitalRead(BTN3_PIN); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment