[SWT windows]GetAsyncKeyStateでキーイベント処理 2008/09/25

Windowsです。SWTです。
GetAsyncKeyStateを使ってキーイベントを取得します。
下記のコードは、ALT + SHITFTキーの同時押しを念頭において作成しています。
ALTキーはVK_MENUなのかと勝手に類推して作成しています。

参考



import org.eclipse.swt.internal.win32.OS;

public class TestEvent {

public static void main(String[] args) {

key_alt_shift();
}

static void key_alt_shift() {

while (true) {

int s1 = OS.GetAsyncKeyState(OS.VK_MENU) & 0x8000;// alt key???
int s2 = OS.GetAsyncKeyState(OS.VK_SHIFT) & 0x8000;

System.out.println(s1 + " " + s2);

/*
* 同時押しかどうか....
*/
if (0 < s1 && 0 < s2) {
System.out.println("*** BINGO!!");
}

try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
}

}
}

: