package TT;
import com.sun.jna.platform.win32.BaseTSD;
import com.sun.jna.platform.win32.User32;
import com.sun.jna.platform.win32.WinDef;
import com.sun.jna.platform.win32.WinUser;
public class UDEUtil {
public static void sendChar(char ch) {
WinUser.INPUT input = new WinUser.INPUT();
input.type = new WinDef.DWORD(WinUser.INPUT.INPUT_KEYBOARD);
input.input.setType("ki"); // Because setting INPUT_INPUT_KEYBOARD is not enough: https://groups.google.com/d/msg/jna-users/NDBGwC1VZbU/cjYCQ1CjBwAJ
input.input.ki.wScan = new WinDef.WORD(0);
input.input.ki.time = new WinDef.DWORD(0);
input.input.ki.dwExtraInfo = new BaseTSD.ULONG_PTR(0);
// Press
input.input.ki.wScan = new WinDef.WORD(Character.toUpperCase(ch)); // 0x41
input.input.ki.wVk = new WinDef.WORD(Character.toUpperCase(ch)); // 0x41
input.input.ki.dwFlags = new WinDef.DWORD(0); // keydown
User32.INSTANCE.SendInput(new WinDef.DWORD(1), (WinUser.INPUT[]) input.toArray(1), input.size());
// Release
input.input.ki.dwFlags = new WinDef.DWORD(2); // keyup
User32.INSTANCE.SendInput(new WinDef.DWORD(1), (WinUser.INPUT[]) input.toArray(1), input.size());
}
public static void mouse(int x, int y, int botton, boolean abslute) {
WinUser.INPUT input = new WinUser.INPUT();
input.type = new WinDef.DWORD(WinUser.INPUT.INPUT_MOUSE);
input.input.setType("mi");
if(abslute) {
x = 65536/User32.INSTANCE.GetSystemMetrics(0)*x;
y = 65536/User32.INSTANCE.GetSystemMetrics(1)*y;
}
if(x!=0)input.input.mi.dx = new WinDef.LONG(x);
if(y!=0)input.input.mi.dy = new WinDef.LONG(y);
input.input.mi.dwFlags = new WinDef.DWORD(botton);
User32.INSTANCE.SendInput(new WinDef.DWORD(1), (WinUser.INPUT[]) input.toArray(1), input.size());
}
}
07-29
1924