| 1 |
/* |
| 2 |
* Copyright (c) 2002-2016, the original author or authors. |
| 3 |
* |
| 4 |
* This software is distributable under the BSD license. See the terms of the |
| 5 |
* BSD license in the documentation provided with this software. |
| 6 |
* |
| 7 |
* http://www.opensource.org/licenses/bsd-license.php |
| 8 |
*/ |
| 9 |
package org.jline.terminal.impl.jna.win; |
| 10 |
|
| 11 |
import com.sun.jna.LastErrorException; |
| 12 |
import com.sun.jna.Native; |
| 13 |
import com.sun.jna.Pointer; |
| 14 |
import com.sun.jna.Structure; |
| 15 |
import com.sun.jna.Union; |
| 16 |
import com.sun.jna.ptr.IntByReference; |
| 17 |
import com.sun.jna.win32.StdCallLibrary; |
| 18 |
import com.sun.jna.win32.W32APIOptions; |
| 19 |
|
| 20 |
interface Kernel32 extends StdCallLibrary { |
| 21 |
|
| 22 |
Kernel32 INSTANCE = (Kernel32) Native.loadLibrary("kernel32", Kernel32.class, W32APIOptions.UNICODE_OPTIONS); |
| 23 |
|
| 24 |
Pointer INVALID_HANDLE_VALUE = Pointer.createConstant(-1L); |
| 25 |
|
| 26 |
int STD_INPUT_HANDLE = -10; |
| 27 |
int STD_OUTPUT_HANDLE = -11; |
| 28 |
int STD_ERROR_HANDLE = -12; |
| 29 |
|
| 30 |
int ENABLE_PROCESSED_INPUT = 0x0001; |
| 31 |
int ENABLE_LINE_INPUT = 0x0002; |
| 32 |
int ENABLE_ECHO_INPUT = 0x0004; |
| 33 |
int ENABLE_WINDOW_INPUT = 0x0008; |
| 34 |
int ENABLE_MOUSE_INPUT = 0x0010; |
| 35 |
int ENABLE_INSERT_MODE = 0x0020; |
| 36 |
int ENABLE_QUICK_EDIT_MODE = 0x0040; |
| 37 |
int ENABLE_EXTENDED_FLAGS = 0x0080; |
| 38 |
|
| 39 |
int RIGHT_ALT_PRESSED = 0x0001; |
| 40 |
int LEFT_ALT_PRESSED = 0x0002; |
| 41 |
int RIGHT_CTRL_PRESSED = 0x0004; |
| 42 |
int LEFT_CTRL_PRESSED = 0x0008; |
| 43 |
int SHIFT_PRESSED = 0x0010; |
| 44 |
|
| 45 |
int FOREGROUND_BLUE = 0x0001; |
| 46 |
int FOREGROUND_GREEN = 0x0002; |
| 47 |
int FOREGROUND_RED = 0x0004; |
| 48 |
int FOREGROUND_INTENSITY = 0x0008; |
| 49 |
int BACKGROUND_BLUE = 0x0010; |
| 50 |
int BACKGROUND_GREEN = 0x0020; |
| 51 |
int BACKGROUND_RED = 0x0040; |
| 52 |
int BACKGROUND_INTENSITY = 0x0080; |
| 53 |
|
| 54 |
// Button state |
| 55 |
int FROM_LEFT_1ST_BUTTON_PRESSED = 0x0001; |
| 56 |
int RIGHTMOST_BUTTON_PRESSED = 0x0002; |
| 57 |
int FROM_LEFT_2ND_BUTTON_PRESSED = 0x0004; |
| 58 |
int FROM_LEFT_3RD_BUTTON_PRESSED = 0x0008; |
| 59 |
int FROM_LEFT_4TH_BUTTON_PRESSED = 0x0010; |
| 60 |
|
| 61 |
// Event flags |
| 62 |
int MOUSE_MOVED = 0x0001; |
| 63 |
int DOUBLE_CLICK = 0x0002; |
| 64 |
int MOUSE_WHEELED = 0x0004; |
| 65 |
int MOUSE_HWHEELED = 0x0008; |
| 66 |
|
| 67 |
// HANDLE WINAPI GetStdHandle( |
| 68 |
// __in DWORD nStdHandle |
| 69 |
// ); |
| 70 |
Pointer GetStdHandle(int nStdHandle); |
| 71 |
|
| 72 |
// BOOL WINAPI AllocConsole(void); |
| 73 |
void AllocConsole() throws LastErrorException; |
| 74 |
|
| 75 |
// BOOL WINAPI FreeConsole(void); |
| 76 |
void FreeConsole() throws LastErrorException; |
| 77 |
|
| 78 |
// HWND WINAPI GetConsoleWindow(void); |
| 79 |
Pointer GetConsoleWindow(); |
| 80 |
|
| 81 |
// UINT WINAPI GetConsoleOutputCP(void) |
| 82 |
int GetConsoleOutputCP(); |
| 83 |
|
| 84 |
// BOOL WINAPI FillConsoleOutputCharacter( |
| 85 |
// _In_ HANDLE hConsoleOutput, |
| 86 |
// _In_ TCHAR cCharacter, |
| 87 |
// _In_ DWORD nLength, |
| 88 |
// _In_ COORD dwWriteCoord, |
| 89 |
// _Out_ LPDWORD lpNumberOfCharsWritten); |
| 90 |
void FillConsoleOutputCharacter(Pointer in_hConsoleOutput, |
| 91 |
char in_cCharacter, int in_nLength, COORD in_dwWriteCoord, |
| 92 |
IntByReference out_lpNumberOfCharsWritten) |
| 93 |
throws LastErrorException; |
| 94 |
|
| 95 |
// BOOL WINAPI FillConsoleOutputAttribute( |
| 96 |
// _In_ HANDLE hConsoleOutput, |
| 97 |
// _In_ WORD wAttribute, |
| 98 |
// _In_ DWORD nLength, |
| 99 |
// _In_ COORD dwWriteCoord, |
| 100 |
// _Out_ LPDWORD lpNumberOfAttrsWritten); |
| 101 |
void FillConsoleOutputAttribute(Pointer in_hConsoleOutput, |
| 102 |
short in_wAttribute, int in_nLength, COORD in_dwWriteCoord, |
| 103 |
IntByReference out_lpNumberOfAttrsWritten) |
| 104 |
throws LastErrorException; |
| 105 |
|
| 106 |
// BOOL WINAPI GetConsoleCursorInfo( |
| 107 |
// _In_ HANDLE hConsoleOutput, |
| 108 |
// _Out_ PCONSOLE_CURSOR_INFO lpConsoleCursorInfo); |
| 109 |
void GetConsoleCursorInfo(Pointer in_hConsoleOutput, |
| 110 |
CONSOLE_CURSOR_INFO.ByReference out_lpConsoleCursorInfo) |
| 111 |
throws LastErrorException; |
| 112 |
|
| 113 |
// BOOL WINAPI GetConsoleMode( |
| 114 |
// _In_ HANDLE hConsoleHandle, |
| 115 |
// _Out_ LPDWORD lpMode); |
| 116 |
void GetConsoleMode( |
| 117 |
Pointer in_hConsoleOutput, |
| 118 |
IntByReference out_lpMode) |
| 119 |
throws LastErrorException; |
| 120 |
|
| 121 |
// BOOL WINAPI GetConsoleScreenBufferInfo( |
| 122 |
// _In_ HANDLE hConsoleOutput, |
| 123 |
// _Out_ PCONSOLE_SCREEN_BUFFER_INFO lpConsoleScreenBufferInfo); |
| 124 |
void GetConsoleScreenBufferInfo( |
| 125 |
Pointer in_hConsoleOutput, |
| 126 |
CONSOLE_SCREEN_BUFFER_INFO out_lpConsoleScreenBufferInfo) |
| 127 |
throws LastErrorException; |
| 128 |
|
| 129 |
// BOOL WINAPI GetNumberOfConsoleInputEvents( |
| 130 |
// _In_ HANDLE hConsoleInput, |
| 131 |
// _Out_ LPDWORD lpcNumberOfEvents); |
| 132 |
void GetNumberOfConsoleInputEvents(Pointer in_hConsoleOutput, |
| 133 |
IntByReference out_lpcNumberOfEvents) throws LastErrorException; |
| 134 |
|
| 135 |
// BOOL WINAPI ReadConsoleInput( |
| 136 |
// _In_ HANDLE hConsoleInput, |
| 137 |
// _Out_ PINPUT_RECORD lpBuffer, |
| 138 |
// _In_ DWORD nLength, |
| 139 |
// _Out_ LPDWORD lpNumberOfEventsRead); |
| 140 |
void ReadConsoleInput(Pointer in_hConsoleOutput, |
| 141 |
INPUT_RECORD[] out_lpBuffer, int in_nLength, |
| 142 |
IntByReference out_lpNumberOfEventsRead) throws LastErrorException; |
| 143 |
|
| 144 |
// BOOL WINAPI SetConsoleCtrlHandler( |
| 145 |
// _In_opt_ PHANDLER_ROUTINE HandlerRoutine, |
| 146 |
// _In_ BOOL Add); |
| 147 |
void SetConsoleCtrlHandler( |
| 148 |
Pointer in_opt_HandlerRoutine, |
| 149 |
boolean in_Add) |
| 150 |
throws LastErrorException; |
| 151 |
|
| 152 |
// BOOL WINAPI ReadConsoleOutput( |
| 153 |
// _In_ HANDLE hConsoleOutput, |
| 154 |
// _Out_ PCHAR_INFO lpBuffer, |
| 155 |
// _In_ COORD dwBufferSize, |
| 156 |
// _In_ COORD dwBufferCoord, |
| 157 |
// _Inout_ PSMALL_RECT lpReadRegion); |
| 158 |
void ReadConsoleOutput(Pointer in_hConsoleOutput, CHAR_INFO[] out_lpBuffer, |
| 159 |
COORD in_dwBufferSize, COORD in_dwBufferCoord, |
| 160 |
SMALL_RECT inout_lpReadRegion) throws LastErrorException; |
| 161 |
void ReadConsoleOutputA(Pointer in_hConsoleOutput, CHAR_INFO[] out_lpBuffer, |
| 162 |
COORD in_dwBufferSize, COORD in_dwBufferCoord, |
| 163 |
SMALL_RECT inout_lpReadRegion) throws LastErrorException; |
| 164 |
|
| 165 |
// BOOL WINAPI ReadConsoleOutputCharacter( |
| 166 |
// _In_ HANDLE hConsoleOutput, |
| 167 |
// _Out_ LPTSTR lpCharacter, |
| 168 |
// _In_ DWORD nLength, |
| 169 |
// _In_ COORD dwReadCoord, |
| 170 |
// _Out_ LPDWORD lpNumberOfCharsRead); |
| 171 |
void ReadConsoleOutputCharacter(Pointer in_hConsoleOutput, |
| 172 |
char[] ouy_lpCharacter, int in_nLength, COORD in_dwReadCoord, |
| 173 |
IntByReference out_lpNumberOfCharsRead) |
| 174 |
throws LastErrorException; |
| 175 |
void ReadConsoleOutputCharacterA(Pointer in_hConsoleOutput, |
| 176 |
byte[] ouy_lpCharacter, int in_nLength, COORD in_dwReadCoord, |
| 177 |
IntByReference out_lpNumberOfCharsRead) |
| 178 |
throws LastErrorException; |
| 179 |
|
| 180 |
// BOOL WINAPI SetConsoleCursorInfo( |
| 181 |
// _In_ HANDLE hConsoleOutput, |
| 182 |
// _In_ const CONSOLE_CURSOR_INFO *lpConsoleCursorInfo); |
| 183 |
void SetConsoleCursorInfo(Pointer in_hConsoleOutput, |
| 184 |
CONSOLE_CURSOR_INFO in_lpConsoleCursorInfo) |
| 185 |
throws LastErrorException; |
| 186 |
|
| 187 |
// BOOL WINAPI SetConsoleCP( |
| 188 |
// _In_ UINT wCodePageID); |
| 189 |
void SetConsoleCP(int in_wCodePageID) throws LastErrorException; |
| 190 |
|
| 191 |
// BOOL WINAPI SetConsoleCursorPosition( |
| 192 |
// _In_ HANDLE hConsoleOutput, |
| 193 |
// _In_ COORD dwCursorPosition); |
| 194 |
void SetConsoleCursorPosition(Pointer in_hConsoleOutput, |
| 195 |
COORD in_dwCursorPosition) throws LastErrorException; |
| 196 |
|
| 197 |
// BOOL WINAPI SetConsoleMode( |
| 198 |
// _In_ HANDLE hConsoleHandle, |
| 199 |
// _In_ DWORD dwMode); |
| 200 |
void SetConsoleMode( |
| 201 |
Pointer in_hConsoleOutput, |
| 202 |
int in_dwMode) throws LastErrorException; |
| 203 |
|
| 204 |
// BOOL WINAPI SetConsoleScreenBufferSize( |
| 205 |
// __in HANDLE hConsoleOutput, |
| 206 |
// __in COORD dwSize |
| 207 |
// ); |
| 208 |
void SetConsoleScreenBufferSize(Pointer in_hConsoleOutput, |
| 209 |
COORD in_dwSize) throws LastErrorException; |
| 210 |
|
| 211 |
// BOOL WINAPI SetConsoleTextAttribute( |
| 212 |
// _In_ HANDLE hConsoleOutput, |
| 213 |
// _In_ WORD wAttributes |
| 214 |
// ); |
| 215 |
void SetConsoleTextAttribute(Pointer in_hConsoleOutput, |
| 216 |
short in_wAttributes) |
| 217 |
throws LastErrorException; |
| 218 |
|
| 219 |
// BOOL WINAPI SetConsoleTitle( |
| 220 |
// _In_ LPCTSTR lpConsoleTitle |
| 221 |
// ); |
| 222 |
void SetConsoleTitle(String in_lpConsoleTitle) |
| 223 |
throws LastErrorException; |
| 224 |
|
| 225 |
// BOOL WINAPI SetConsoleWindowInfo( |
| 226 |
// _In_ HANDLE hConsoleOutput, |
| 227 |
// _In_ BOOL bAbsolute, |
| 228 |
// _In_ const SMALL_RECT *lpConsoleWindow); |
| 229 |
void SetConsoleWindowInfo(Pointer in_hConsoleOutput, |
| 230 |
boolean in_bAbsolute, SMALL_RECT in_lpConsoleWindow) |
| 231 |
throws LastErrorException; |
| 232 |
|
| 233 |
// BOOL WINAPI WriteConsoleOutput( |
| 234 |
// _In_ HANDLE hConsoleOutput, |
| 235 |
// _In_ const CHAR_INFO *lpBuffer, |
| 236 |
// _In_ COORD dwBufferSize, |
| 237 |
// _In_ COORD dwBufferCoord, |
| 238 |
// _Inout_ PSMALL_RECT lpWriteRegion); |
| 239 |
void WriteConsoleOutput(Pointer in_hConsoleOutput, CHAR_INFO[] in_lpBuffer, |
| 240 |
COORD in_dwBufferSize, COORD in_dwBufferCoord, |
| 241 |
SMALL_RECT inout_lpWriteRegion) throws LastErrorException; |
| 242 |
void WriteConsoleOutputA(Pointer in_hConsoleOutput, CHAR_INFO[] in_lpBuffer, |
| 243 |
COORD in_dwBufferSize, COORD in_dwBufferCoord, |
| 244 |
SMALL_RECT inout_lpWriteRegion) throws LastErrorException; |
| 245 |
|
| 246 |
// BOOL WINAPI WriteConsoleOutputCharacter( |
| 247 |
// _In_ HANDLE hConsoleOutput, |
| 248 |
// _In_ LPCTSTR lpCharacter, |
| 249 |
// _In_ DWORD nLength, |
| 250 |
// _In_ COORD dwWriteCoord, |
| 251 |
// _Out_ LPDWORD lpNumberOfCharsWritten); |
| 252 |
void WriteConsoleOutputCharacter(Pointer in_hConsoleOutput, |
| 253 |
char[] in_lpCharacter, int in_nLength, COORD in_dwWriteCoord, |
| 254 |
IntByReference out_lpNumberOfCharsWritten) |
| 255 |
throws LastErrorException; |
| 256 |
void WriteConsoleOutputCharacterA(Pointer in_hConsoleOutput, |
| 257 |
byte[] in_lpCharacter, int in_nLength, COORD in_dwWriteCoord, |
| 258 |
IntByReference out_lpNumberOfCharsWritten) |
| 259 |
throws LastErrorException; |
| 260 |
|
| 261 |
// BOOL WINAPI ScrollConsoleScreenBuffer( |
| 262 |
// _In_ HANDLE hConsoleOutput, |
| 263 |
// _In_ const SMALL_RECT *lpScrollRectangle, |
| 264 |
// _In_opt_ const SMALL_RECT *lpClipRectangle, |
| 265 |
// _In_ COORD dwDestinationOrigin, |
| 266 |
// _In_ const CHAR_INFO *lpFill); |
| 267 |
void ScrollConsoleScreenBuffer(Pointer in_hConsoleOutput, |
| 268 |
SMALL_RECT in_lpScrollRectangle, |
| 269 |
SMALL_RECT in_lpClipRectangle, |
| 270 |
COORD in_dwDestinationOrigin, |
| 271 |
CHAR_INFO in_lpFill) |
| 272 |
throws LastErrorException; |
| 273 |
|
| 274 |
// typedef struct _CHAR_INFO { |
| 275 |
// union { |
| 276 |
// WCHAR UnicodeChar; |
| 277 |
// CHAR AsciiChar; |
| 278 |
// } Char; |
| 279 |
// WORD Attributes; |
| 280 |
// } CHAR_INFO, *PCHAR_INFO; |
| 281 |
class CHAR_INFO extends Structure { |
| 282 |
public CHAR_INFO() { |
| 283 |
} |
| 284 |
|
| 285 |
public CHAR_INFO(char c, short attr) { |
| 286 |
uChar = new UnionChar(c); |
| 287 |
Attributes = attr; |
| 288 |
} |
| 289 |
|
| 290 |
public CHAR_INFO(byte c, short attr) { |
| 291 |
uChar = new UnionChar(c); |
| 292 |
Attributes = attr; |
| 293 |
} |
| 294 |
|
| 295 |
public UnionChar uChar; |
| 296 |
public short Attributes; |
| 297 |
|
| 298 |
public static CHAR_INFO[] createArray(int size) { |
| 299 |
return (CHAR_INFO[]) new CHAR_INFO().toArray(size); |
| 300 |
} |
| 301 |
|
| 302 |
private static String[] fieldOrder = { "uChar", "Attributes" }; |
| 303 |
|
| 304 |
@Override |
| 305 |
protected java.util.List<String> getFieldOrder() { |
| 306 |
return java.util.Arrays.asList(fieldOrder); |
| 307 |
} |
| 308 |
} |
| 309 |
|
| 310 |
// typedef struct _CONSOLE_CURSOR_INFO { |
| 311 |
// DWORD dwSize; |
| 312 |
// BOOL bVisible; |
| 313 |
// } CONSOLE_CURSOR_INFO, *PCONSOLE_CURSOR_INFO; |
| 314 |
class CONSOLE_CURSOR_INFO extends Structure { |
| 315 |
public int dwSize; |
| 316 |
public boolean bVisible; |
| 317 |
|
| 318 |
public static class ByReference extends CONSOLE_CURSOR_INFO implements |
| 319 |
Structure.ByReference { |
| 320 |
} |
| 321 |
|
| 322 |
private static String[] fieldOrder = { "dwSize", "bVisible" }; |
| 323 |
|
| 324 |
@Override |
| 325 |
protected java.util.List<String> getFieldOrder() { |
| 326 |
return java.util.Arrays.asList(fieldOrder); |
| 327 |
} |
| 328 |
} |
| 329 |
|
| 330 |
// typedef struct _CONSOLE_SCREEN_BUFFER_INFO { |
| 331 |
// COORD dwSize; |
| 332 |
// COORD dwCursorPosition; |
| 333 |
// WORD wAttributes; |
| 334 |
// SMALL_RECT srWindow; |
| 335 |
// COORD dwMaximumWindowSize; |
| 336 |
// } CONSOLE_SCREEN_BUFFER_INFO; |
| 337 |
class CONSOLE_SCREEN_BUFFER_INFO extends Structure { |
| 338 |
public COORD dwSize; |
| 339 |
public COORD dwCursorPosition; |
| 340 |
public short wAttributes; |
| 341 |
public SMALL_RECT srWindow; |
| 342 |
public COORD dwMaximumWindowSize; |
| 343 |
|
| 344 |
private static String[] fieldOrder = { "dwSize", "dwCursorPosition", "wAttributes", "srWindow", "dwMaximumWindowSize" }; |
| 345 |
|
| 346 |
@Override |
| 347 |
protected java.util.List<String> getFieldOrder() { |
| 348 |
return java.util.Arrays.asList(fieldOrder); |
| 349 |
} |
| 350 |
|
| 351 |
public int windowWidth() { |
| 352 |
return this.srWindow.width() + 1; |
| 353 |
} |
| 354 |
|
| 355 |
public int windowHeight() { |
| 356 |
return this.srWindow.height() + 1; |
| 357 |
} |
| 358 |
} |
| 359 |
|
| 360 |
// typedef struct _COORD { |
| 361 |
// SHORT X; |
| 362 |
// SHORT Y; |
| 363 |
// } COORD, *PCOORD; |
| 364 |
class COORD extends Structure implements Structure.ByValue { |
| 365 |
public COORD() { |
| 366 |
} |
| 367 |
|
| 368 |
public COORD(short X, short Y) { |
| 369 |
this.X = X; |
| 370 |
this.Y = Y; |
| 371 |
} |
| 372 |
|
| 373 |
public short X; |
| 374 |
public short Y; |
| 375 |
|
| 376 |
private static String[] fieldOrder = { "X", "Y" }; |
| 377 |
|
| 378 |
@Override |
| 379 |
protected java.util.List<String> getFieldOrder() { |
| 380 |
return java.util.Arrays.asList(fieldOrder); |
| 381 |
} |
| 382 |
} |
| 383 |
|
| 384 |
// typedef struct _INPUT_RECORD { |
| 385 |
// WORD EventType; |
| 386 |
// union { |
| 387 |
// KEY_EVENT_RECORD KeyEvent; |
| 388 |
// MOUSE_EVENT_RECORD MouseEvent; |
| 389 |
// WINDOW_BUFFER_SIZE_RECORD WindowBufferSizeEvent; |
| 390 |
// MENU_EVENT_RECORD MenuEvent; |
| 391 |
// FOCUS_EVENT_RECORD FocusEvent; |
| 392 |
// } Event; |
| 393 |
// } INPUT_RECORD; |
| 394 |
class INPUT_RECORD extends Structure { |
| 395 |
public static final short KEY_EVENT = 0x0001; |
| 396 |
public static final short MOUSE_EVENT = 0x0002; |
| 397 |
public static final short WINDOW_BUFFER_SIZE_EVENT = 0x0004; |
| 398 |
public static final short MENU_EVENT = 0x0008; |
| 399 |
public static final short FOCUS_EVENT = 0x0010; |
| 400 |
|
| 401 |
public short EventType; |
| 402 |
public EventUnion Event; |
| 403 |
|
| 404 |
public static class EventUnion extends Union { |
| 405 |
public KEY_EVENT_RECORD KeyEvent; |
| 406 |
public MOUSE_EVENT_RECORD MouseEvent; |
| 407 |
public WINDOW_BUFFER_SIZE_RECORD WindowBufferSizeEvent; |
| 408 |
// MENU_EVENT_RECORD MenuEvent; |
| 409 |
// FOCUS_EVENT_RECORD FocusEvent; |
| 410 |
} |
| 411 |
|
| 412 |
@Override |
| 413 |
public void read() { |
| 414 |
readField("EventType"); |
| 415 |
switch (EventType) { |
| 416 |
case KEY_EVENT: |
| 417 |
Event.setType(KEY_EVENT_RECORD.class); |
| 418 |
break; |
| 419 |
case MOUSE_EVENT: |
| 420 |
Event.setType(MOUSE_EVENT_RECORD.class); |
| 421 |
break; |
| 422 |
case WINDOW_BUFFER_SIZE_EVENT: |
| 423 |
Event.setType(WINDOW_BUFFER_SIZE_RECORD.class); |
| 424 |
break; |
| 425 |
} |
| 426 |
super.read(); |
| 427 |
} |
| 428 |
|
| 429 |
private static String[] fieldOrder = {"EventType", "Event"}; |
| 430 |
|
| 431 |
@Override |
| 432 |
protected java.util.List<String> getFieldOrder() { |
| 433 |
return java.util.Arrays.asList(fieldOrder); |
| 434 |
} |
| 435 |
} |
| 436 |
|
| 437 |
// typedef struct _KEY_EVENT_RECORD { |
| 438 |
// BOOL bKeyDown; |
| 439 |
// WORD wRepeatCount; |
| 440 |
// WORD wVirtualKeyCode; |
| 441 |
// WORD wVirtualScanCode; |
| 442 |
// union { |
| 443 |
// WCHAR UnicodeChar; |
| 444 |
// CHAR AsciiChar; |
| 445 |
// } uChar; |
| 446 |
// DWORD dwControlKeyState; |
| 447 |
// } KEY_EVENT_RECORD; |
| 448 |
class KEY_EVENT_RECORD extends Structure { |
| 449 |
public boolean bKeyDown; |
| 450 |
public short wRepeatCount; |
| 451 |
public short wVirtualKeyCode; |
| 452 |
public short wVirtualScanCode; |
| 453 |
public UnionChar uChar; |
| 454 |
public int dwControlKeyState; |
| 455 |
|
| 456 |
private static String[] fieldOrder = {"bKeyDown", "wRepeatCount", "wVirtualKeyCode", "wVirtualScanCode", "uChar", "dwControlKeyState"}; |
| 457 |
|
| 458 |
@Override |
| 459 |
protected java.util.List<String> getFieldOrder() { |
| 460 |
return java.util.Arrays.asList(fieldOrder); |
| 461 |
} |
| 462 |
} |
| 463 |
|
| 464 |
// typedef struct _MOUSE_EVENT_RECORD { |
| 465 |
// COORD dwMousePosition; |
| 466 |
// DWORD dwButtonState; |
| 467 |
// DWORD dwControlKeyState; |
| 468 |
// DWORD dwEventFlags; |
| 469 |
// } MOUSE_EVENT_RECORD; |
| 470 |
class MOUSE_EVENT_RECORD extends Structure { |
| 471 |
public COORD dwMousePosition; |
| 472 |
public int dwButtonState; |
| 473 |
public int dwControlKeyState; |
| 474 |
public int dwEventFlags; |
| 475 |
|
| 476 |
private static String[] fieldOrder = { "dwMousePosition", "dwButtonState", "dwControlKeyState", "dwEventFlags"}; |
| 477 |
|
| 478 |
@Override |
| 479 |
protected java.util.List<String> getFieldOrder() { |
| 480 |
return java.util.Arrays.asList(fieldOrder); |
| 481 |
} |
| 482 |
} |
| 483 |
|
| 484 |
// typedef struct _WINDOW_BUFFER_SIZE_RECORD { |
| 485 |
// COORD dwSize; |
| 486 |
// } WINDOW_BUFFER_SIZE_RECORD; |
| 487 |
class WINDOW_BUFFER_SIZE_RECORD extends Structure { |
| 488 |
public COORD dwSize; |
| 489 |
|
| 490 |
private static String[] fieldOrder = {"dwSize"}; |
| 491 |
|
| 492 |
@Override |
| 493 |
protected java.util.List<String> getFieldOrder() { |
| 494 |
return java.util.Arrays.asList(fieldOrder); |
| 495 |
} |
| 496 |
} |
| 497 |
|
| 498 |
// typedef struct _SMALL_RECT { |
| 499 |
// SHORT Left; |
| 500 |
// SHORT Top; |
| 501 |
// SHORT Right; |
| 502 |
// SHORT Bottom; |
| 503 |
// } SMALL_RECT; |
| 504 |
class SMALL_RECT extends Structure { |
| 505 |
public SMALL_RECT() { |
| 506 |
} |
| 507 |
|
| 508 |
public SMALL_RECT(SMALL_RECT org) { |
| 509 |
this(org.Top, org.Left, org.Bottom, org.Right); |
| 510 |
} |
| 511 |
|
| 512 |
public SMALL_RECT(short Top, short Left, short Bottom, short Right) { |
| 513 |
this.Top = Top; |
| 514 |
this.Left = Left; |
| 515 |
this.Bottom = Bottom; |
| 516 |
this.Right = Right; |
| 517 |
} |
| 518 |
|
| 519 |
public short Left; |
| 520 |
public short Top; |
| 521 |
public short Right; |
| 522 |
public short Bottom; |
| 523 |
|
| 524 |
private static String[] fieldOrder = { "Left", "Top", "Right", "Bottom" }; |
| 525 |
|
| 526 |
@Override |
| 527 |
protected java.util.List<String> getFieldOrder() { |
| 528 |
return java.util.Arrays.asList(fieldOrder); |
| 529 |
} |
| 530 |
|
| 531 |
public short width() { |
| 532 |
return (short)(this.Right - this.Left); |
| 533 |
} |
| 534 |
|
| 535 |
public short height() { |
| 536 |
return (short)(this.Bottom - this.Top); |
| 537 |
} |
| 538 |
|
| 539 |
} |
| 540 |
|
| 541 |
class UnionChar extends Union { |
| 542 |
public UnionChar() { |
| 543 |
} |
| 544 |
|
| 545 |
public UnionChar(char c) { |
| 546 |
setType(char.class); |
| 547 |
UnicodeChar = c; |
| 548 |
} |
| 549 |
|
| 550 |
public UnionChar(byte c) { |
| 551 |
setType(byte.class); |
| 552 |
AsciiChar = c; |
| 553 |
} |
| 554 |
|
| 555 |
public void set(char c) { |
| 556 |
setType(char.class); |
| 557 |
UnicodeChar = c; |
| 558 |
} |
| 559 |
|
| 560 |
public void set(byte c) { |
| 561 |
setType(byte.class); |
| 562 |
AsciiChar = c; |
| 563 |
} |
| 564 |
|
| 565 |
public char UnicodeChar; |
| 566 |
public byte AsciiChar; |
| 567 |
} |
| 568 |
} |