以下是一个使用Apple脚本将按键发送到通过Java程序调用的程序的解决方法:
on run argv
tell application "System Events"
keystroke item 1 of argv
end tell
end run
#!/bin/bash
# 要发送的按键
key=$1
# 调用Apple脚本发送按键
osascript send_key.scpt "$key"
ProcessBuilder
类调用Shell脚本。import java.io.IOException;
public class SendKey {
public static void main(String[] args) {
// 要发送的按键
String key = "A";
try {
// 调用Shell脚本
ProcessBuilder processBuilder = new ProcessBuilder("sh", "send_key.sh", key);
processBuilder.start();
} catch (IOException e) {
e.printStackTrace();
}
}
}
请注意,上述代码中的按键示例为"A",您可以根据需要更改为任何按键或组合键。
这是一个简单的示例,您可以根据自己的需求进行修改和扩展。