|
24 | 24 | package com.sun.jna.platform.win32; |
25 | 25 |
|
26 | 26 | import com.sun.jna.Native; |
| 27 | +import com.sun.jna.Structure; |
| 28 | +import com.sun.jna.Structure.FieldOrder; |
| 29 | +import com.sun.jna.Union; |
27 | 30 | import com.sun.jna.platform.win32.WinDef.HWND; |
| 31 | +import com.sun.jna.platform.win32.WinDef.LPVOID; |
28 | 32 | import com.sun.jna.platform.win32.WinNT.HANDLE; |
29 | 33 | import com.sun.jna.ptr.IntByReference; |
30 | 34 |
|
@@ -182,6 +186,9 @@ public interface Wincon { |
182 | 186 | int ENABLE_INSERT_MODE=0x0020; |
183 | 187 | int ENABLE_QUICK_EDIT_MODE=0x0040; |
184 | 188 | int ENABLE_EXTENDED_FLAGS=0x0080; |
| 189 | + int ENABLE_VIRTUAL_TERMINAL_PROCESSING = 0x0004; |
| 190 | + int DISABLE_NEWLINE_AUTO_RETURN = 0x0008; |
| 191 | + int ENABLE_VIRTUAL_TERMINAL_INPUT = 0x0200; |
185 | 192 |
|
186 | 193 | /* If the hConsoleHandle parameter is a screen buffer handle, the mode |
187 | 194 | * can be one or more of the following values |
@@ -249,4 +256,181 @@ public interface Wincon { |
249 | 256 | * @see <a href="https://msdn.microsoft.com/en-us/library/ms686050(v=vs.85).aspx">SetConsoleTitle documentation</a> |
250 | 257 | */ |
251 | 258 | boolean SetConsoleTitle(String lpConsoleTitle); |
| 259 | + |
| 260 | + /** |
| 261 | + * Retrieves information about the specified console screen buffer. |
| 262 | + * @param hConsoleOutput A handle to the console screen buffer. |
| 263 | + * @param lpConsoleScreenBufferInfo A pointer to a CONSOLE_SCREEN_BUFFER_INFO structure that receives the console screen buffer information. |
| 264 | + * @return {@code true} if successful - if {@code false} then use |
| 265 | + * {@code GetLastError()} to get extended error information |
| 266 | + * @see <a href="https://docs.microsoft.com/en-us/windows/console/getconsolescreenbufferinfo">GetConsoleScreenBufferInfo documentation</a> |
| 267 | + */ |
| 268 | + boolean GetConsoleScreenBufferInfo(HANDLE hConsoleOutput, CONSOLE_SCREEN_BUFFER_INFO lpConsoleScreenBufferInfo); |
| 269 | + |
| 270 | + /** |
| 271 | + * Reads data from a console input buffer and removes it from the buffer. |
| 272 | + * @param hConsoleInput A handle to the console input buffer. |
| 273 | + * @param lpBuffer A pointer to an array of INPUT_RECORD structures that receives the input buffer data. |
| 274 | + * @param nLength The size of the array pointed to by the lpBuffer parameter, in array elements. |
| 275 | + * @param lpNumberOfEventsRead A pointer to a variable that receives the number of input records read. |
| 276 | + * @return {@code true} if successful - if {@code false} then use |
| 277 | + * {@code GetLastError()} to get extended error information |
| 278 | + * @see <a href="https://docs.microsoft.com/en-us/windows/console/readconsoleinput">ReadConsoleInput documentation</a> |
| 279 | + */ |
| 280 | + boolean ReadConsoleInput(HANDLE hConsoleInput, INPUT_RECORD[] lpBuffer, int nLength, IntByReference lpNumberOfEventsRead); |
| 281 | + |
| 282 | + /** |
| 283 | + * Writes a character string to a console screen buffer beginning at the current cursor location. |
| 284 | + * @param hConsoleOutput A handle to the console screen buffer. |
| 285 | + * @param lpBuffer A pointer to a buffer that contains characters to be written to the console screen buffer. |
| 286 | + * @param nNumberOfCharsToWrite The number of characters to be written. |
| 287 | + * @param lpNumberOfCharsWritten A pointer to a variable that receives the number of characters actually written. |
| 288 | + * @param lpReserved Reserved; must be NULL. |
| 289 | + * @return {@code true} if successful - if {@code false} then use |
| 290 | + * {@code GetLastError()} to get extended error information |
| 291 | + * @see <a href="https://docs.microsoft.com/en-us/windows/console/writeconsole">WriteConsole documentation</a> |
| 292 | + */ |
| 293 | + boolean WriteConsole(HANDLE hConsoleOutput, String lpBuffer, int nNumberOfCharsToWrite, IntByReference lpNumberOfCharsWritten, LPVOID lpReserved); |
| 294 | + |
| 295 | + /** |
| 296 | + * COORD structure |
| 297 | + */ |
| 298 | + @FieldOrder({ "X", "Y" }) |
| 299 | + public static class COORD extends Structure { |
| 300 | + |
| 301 | + public short X; |
| 302 | + public short Y; |
| 303 | + |
| 304 | + @Override |
| 305 | + public String toString() { |
| 306 | + return String.format("COORD(%s,%s)", X, Y); |
| 307 | + } |
| 308 | + } |
| 309 | + |
| 310 | + /** |
| 311 | + * SMALL_RECT structure |
| 312 | + */ |
| 313 | + @FieldOrder({ "Left", "Top", "Right", "Bottom" }) |
| 314 | + public static class SMALL_RECT extends Structure { |
| 315 | + |
| 316 | + public short Left; |
| 317 | + public short Top; |
| 318 | + public short Right; |
| 319 | + public short Bottom; |
| 320 | + |
| 321 | + @Override |
| 322 | + public String toString() { |
| 323 | + return String.format("SMALL_RECT(%s,%s)(%s,%s)", Left, Top, Right, Bottom); |
| 324 | + } |
| 325 | + } |
| 326 | + |
| 327 | + /** |
| 328 | + * CONSOLE_SCREEN_BUFFER_INFO structure |
| 329 | + */ |
| 330 | + @FieldOrder({ "dwSize", "dwCursorPosition", "wAttributes", "srWindow", "dwMaximumWindowSize" }) |
| 331 | + public static class CONSOLE_SCREEN_BUFFER_INFO extends Structure { |
| 332 | + |
| 333 | + public COORD dwSize; |
| 334 | + public COORD dwCursorPosition; |
| 335 | + public short wAttributes; |
| 336 | + public SMALL_RECT srWindow; |
| 337 | + public COORD dwMaximumWindowSize; |
| 338 | + |
| 339 | + @Override |
| 340 | + public String toString() { |
| 341 | + return String.format("CONSOLE_SCREEN_BUFFER_INFO(%s,%s,%s,%s,%s)", dwSize, dwCursorPosition, wAttributes, srWindow, dwMaximumWindowSize); |
| 342 | + } |
| 343 | + } |
| 344 | + |
| 345 | + /** |
| 346 | + * INPUT_RECORD structure |
| 347 | + */ |
| 348 | + @FieldOrder({ "EventType", "Event" }) |
| 349 | + public static class INPUT_RECORD extends Structure { |
| 350 | + |
| 351 | + public static final short KEY_EVENT = 0x01; |
| 352 | + public static final short MOUSE_EVENT = 0x02; |
| 353 | + public static final short WINDOW_BUFFER_SIZE_EVENT = 0x04; |
| 354 | + |
| 355 | + public short EventType; |
| 356 | + public Event Event; |
| 357 | + |
| 358 | + public static class Event extends Union { |
| 359 | + public KEY_EVENT_RECORD KeyEvent; |
| 360 | + public MOUSE_EVENT_RECORD MouseEvent; |
| 361 | + public WINDOW_BUFFER_SIZE_RECORD WindowBufferSizeEvent; |
| 362 | + } |
| 363 | + |
| 364 | + @Override |
| 365 | + public void read() { |
| 366 | + super.read(); |
| 367 | + switch (EventType) { |
| 368 | + case KEY_EVENT: |
| 369 | + Event.setType("KeyEvent"); |
| 370 | + break; |
| 371 | + case MOUSE_EVENT: |
| 372 | + Event.setType("MouseEvent"); |
| 373 | + break; |
| 374 | + case WINDOW_BUFFER_SIZE_EVENT: |
| 375 | + Event.setType("WindowBufferSizeEvent"); |
| 376 | + break; |
| 377 | + } |
| 378 | + Event.read(); |
| 379 | + } |
| 380 | + |
| 381 | + @Override |
| 382 | + public String toString() { |
| 383 | + return String.format("INPUT_RECORD(%s)", EventType); |
| 384 | + } |
| 385 | + } |
| 386 | + |
| 387 | + /** |
| 388 | + * KEY_EVENT_RECORD structure |
| 389 | + */ |
| 390 | + @FieldOrder({ "bKeyDown", "wRepeatCount", "wVirtualKeyCode", "wVirtualScanCode", "uChar", "dwControlKeyState" }) |
| 391 | + public static class KEY_EVENT_RECORD extends Structure { |
| 392 | + |
| 393 | + public boolean bKeyDown; |
| 394 | + public short wRepeatCount; |
| 395 | + public short wVirtualKeyCode; |
| 396 | + public short wVirtualScanCode; |
| 397 | + public char uChar; |
| 398 | + public int dwControlKeyState; |
| 399 | + |
| 400 | + @Override |
| 401 | + public String toString() { |
| 402 | + return String.format("KEY_EVENT_RECORD(%s,%s,%s,%s,%s,%s)", bKeyDown, wRepeatCount, wVirtualKeyCode, wVirtualKeyCode, wVirtualScanCode, uChar, dwControlKeyState); |
| 403 | + } |
| 404 | + } |
| 405 | + |
| 406 | + /** |
| 407 | + * MOUSE_EVENT_RECORD structure |
| 408 | + */ |
| 409 | + @FieldOrder({ "dwMousePosition", "dwButtonState", "dwControlKeyState", "dwEventFlags" }) |
| 410 | + public static class MOUSE_EVENT_RECORD extends Structure { |
| 411 | + |
| 412 | + public COORD dwMousePosition; |
| 413 | + public int dwButtonState; |
| 414 | + public int dwControlKeyState; |
| 415 | + public int dwEventFlags; |
| 416 | + |
| 417 | + @Override |
| 418 | + public String toString() { |
| 419 | + return String.format("MOUSE_EVENT_RECORD(%s,%s,%s,%s)", dwMousePosition, dwButtonState, dwControlKeyState, dwEventFlags); |
| 420 | + } |
| 421 | + } |
| 422 | + |
| 423 | + /** |
| 424 | + * WINDOW_BUFFER_SIZE_RECORD structure |
| 425 | + */ |
| 426 | + @FieldOrder({ "dwSize" }) |
| 427 | + public static class WINDOW_BUFFER_SIZE_RECORD extends Structure { |
| 428 | + |
| 429 | + public COORD dwSize; |
| 430 | + |
| 431 | + @Override |
| 432 | + public String toString() { |
| 433 | + return String.format("WINDOW_BUFFER_SIZE_RECORD(%s)", dwSize); |
| 434 | + } |
| 435 | + } |
252 | 436 | } |
0 commit comments