下面列出了怎么用com.sun.jna.platform.win32.BaseTSD的API类实例代码及写法,或者点击链接到github查看源代码。
private void doKeyRelease(int keyCode) {
logRobot(stdAutoDelay, "KeyRelease: WaitForIdle: %s - Delay: %d");
setAutoDelay(stdAutoDelay);
// on Windows we detect the current layout in KeyboardLayout.
// Since this layout is not compatible to AWT Robot, we have to use
// the User32 API to simulate the key release
if (Settings.AutoDetectKeyboardLayout && Settings.isWindows()) {
int scanCode = SXUser32.INSTANCE.MapVirtualKeyW(keyCode, 0);
SXUser32.INSTANCE.keybd_event((byte)keyCode, (byte)scanCode, new WinDef.DWORD(WinUser.KEYBDINPUT.KEYEVENTF_KEYUP), new BaseTSD.ULONG_PTR(0));
}else{
keyRelease(keyCode);
}
if (stdAutoDelay == 0) {
delay(stdDelay);
}
logRobot("KeyRelease: extended delay: %d", stdMaxElapsed);
}
private void doKeyPress(int keyCode) {
Highlight fakeHighlight = null;
if (RunTime.get().needsRobotFake()) {
fakeHighlight = Highlight.fakeHighlight();
}
logRobot(stdAutoDelay, "KeyPress: WaitForIdle: %s - Delay: %d");
setAutoDelay(stdAutoDelay);
if (null != fakeHighlight) {
delay(20);
fakeHighlight.close();
delay(20);
}
// on Windows we detect the current layout in KeyboardLayout.
// Since this layout is not compatible to AWT Robot, we have to use
// the User32 API to simulate the key press
if (Settings.AutoDetectKeyboardLayout && Settings.isWindows()) {
int scanCode = SXUser32.INSTANCE.MapVirtualKeyW(keyCode, 0);
SXUser32.INSTANCE.keybd_event((byte)keyCode, (byte)scanCode, new WinDef.DWORD(0), new BaseTSD.ULONG_PTR(0));
}else{
keyPress(keyCode);
}
if (stdAutoDelay == 0) {
delay(stdDelay);
}
logRobot("KeyPress: extended delay: %d", stdMaxElapsed);
}
/**
* Create keyboard input event.
*
* @param character character to print
* @param flags flags
* @return keyboard input event
*/
private static WinUser.INPUT createKeyboardInput(char character, long flags) {
WinUser.INPUT input = new WinUser.INPUT();
input.type = new WinDef.DWORD(WinUser.INPUT.INPUT_KEYBOARD);
input.input.setType("ki");
input.input.ki = new WinUser.KEYBDINPUT();
input.input.ki.wVk = new WinDef.WORD(0);
input.input.ki.wScan = new WinDef.WORD(character);
input.input.ki.time = new WinDef.DWORD(0);
input.input.ki.dwFlags = new WinDef.DWORD(flags);
input.input.ki.dwExtraInfo = new BaseTSD.ULONG_PTR();
return input;
}
public static BufferedImage getShellIcon(String path) {
SHFILEINFO fi = new SHFILEINFO();
BaseTSD.DWORD_PTR r = Shell32.INSTANCE.SHGetFileInfo(path, 0, fi, fi.size(), Shell32.SHGFI_ICON | Shell32.SHGFI_SMALLICON);
if (r.intValue() == 0) {
return null;
}
return iconToImage(fi.hIcon);
}
BaseTSD.LONG_PTR GetWindowLongPtr(Pointer hWnd, int index);
BaseTSD.LONG_PTR GetWindowLong(Pointer hWnd, int index);