私は、ユーザーがキーボードのキーに値を再割り当てできる「マクロシステム」を備えたテキストエディタを開発中です。これにより、文字aを押すと、文字「z」が出力されるようになります。代わりは。(実際には、他の文字ではなく、数学記号に使用されます)。
誰かが私にJavaコードを使い始めて、JTextPane内のキーに値を再割り当てすることはできますか?
詳細が必要な場合は、お知らせください。
ありがとうございました!
これまでのところ、これは私が持っているものです:
public void keyPressed(KeyEvent evt) {
//Called when a key is pressed.
//Intercept the key before the default value is printed.
//1. Suppress the original character. Do this in the KeyEvent object
//by setting the doit property to false in your listener if the key
//matches a macro.
jTextPane1.addKeyListener(new KeyAdapter() {
public void keyPressed(keyEvent event) {
if (event.getKeyCode() == KeyEvent.VK_A) {
//Perform an action when A is pressed and there is a macro.
if(macroA == true)
{
keyPressed.doit() = false;
}
}
}
else if (event.getKeyCode() == KeyEvent.VK_B) {
//Perform an action when B is pressed if there is a macro.
if(macroB == true)
{
keyPressed.doit() = false;
}
}
}
});
マクロを「作成」して、マクロが存在するかどうかを確認しながら、それを実装する方法に取り組んでいます。
他にアドバイスがありましたら、よろしくお願いします。
ありがとうございました。