我如何从Arduino写入CMD?

问题描述 投票:-3回答:1

我需要从Arduino发送一些要在cmd上打印的语法。

语法应该是以下行:

"bartend.exe /F=C:\Users\feniger\Desktop\BarTenderFiles\PSLableV03.btw /P"

谢谢你,亚伦

cmd arduino
1个回答
0
投票

这需要您通过Arduino模拟键盘。为此,最简单的方法是使用Arduino Leonardo或Arduino Leonardo Pro Micro。有了这个,你可以输入任何字符串到任何地方,终端,文本编辑器等

如果您无法找到这些主板,请使用Atmega32u4控制器搜索Arduino。 Atmega32u4控制具有USB功能,可以解决您的问题。

对于Windows cmd,您可以使用以下代码打开命令提示符并自动键入所需的命令。

#include "Keyboard.h"

void setup() {
    // initialize control over the keyboard:
    Keyboard.begin();

    // first open run by windows + r
    Keyboard.press(KEY_LEFT_GUI);
    Keyboard.press('r');
    Keyboard.releaseAll();

    // adjust delay according to your requierment
    delay(4000);

    // press enter to open cmd
    Keyboard.press(KEY_RETURN);
    Keyboard.releaseAll();

    // adjust delay according to your requierment
    delay(4000);

    // commond to be entered
    char* cmd = "bartend.exe /F=C:\Users\feniger\Desktop\BarTenderFiles\PSLableV03.btw /P";
    // print command to cmd
    Keyboard.print(cmd);
    delay(50);

    // press enter to run cmd
    Keyboard.press(KEY_RETURN);
    Keyboard.releaseAll();
}

void loop() {

}
© www.soinside.com 2019 - 2024. All rights reserved.