キーを押す間に少しの遅延を持たせる方法を探していました。私は、JIntellitype ライブラリを使用してグローバル ホットキーを読み取り、numpad1 を押すと AB C のシーケンスが実行されるなど、割り当てられたキープレスのシーケンスを起動するこのプログラムを作成しています。私の問題は、Thread.sleep を使用する場合です。 X時間だけ遅延してから、割り当てられたすべてのキーをキープレスの間に遅延なくキープレスします。この問題を解決する方法について誰か提案がありますか? ありがとうございます!
これは、Robot クラスでキープレスを送信するために使用しているものです。
public void onHotKey(int identifier) {
try {
Robot bot = new Robot();
if (output.elementAt(identifier - 1).length() == 1) {
ch = output.elementAt(identifier - 1).charAt(0);
bot.keyPress(ch);
} else {
int cmdSize = output.elementAt(identifier - 1).length();
for (int c = 0; c < cmdSize; c++) {
bot.keyPress((int) output.elementAt(identifier - 1).charAt(c));
try {
Thread.sleep(50);
} catch (InterruptedException ex) {
Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
} catch (AWTException ex) {
Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE, null, ex);
}
}