-
Notifications
You must be signed in to change notification settings - Fork 2
/
Console.xs
1140 lines (1024 loc) · 24.3 KB
/
Console.xs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Console.CPP
* 20 Jan 97 by Aldo Calpini <dada@perl.it>
*
* XS interface to the Win32 Console API
* based on Registry.CPP written by Jesse Dougherty
*
* Version: 0.05 06 Jun 03
*
*/
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#define __TEMP_WORD WORD /* perl defines a WORD, yikes! */
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
#undef Top /* some devel version pollutes */
#undef WORD
#define WORD __TEMP_WORD
// Section for the constant definitions.
#define CROAK croak
/*------------------------------------------------------------------*/
#define SMALL_ICON_SIZE 16
#define TITLE_SIZE 128
static HANDLE wndBigIcon = NULL;
static HANDLE wndSmallIcon = NULL;
/* Return a handle to the current console window */
static HWND GetConsoleHwnd(void)
{
HWND hwnd;
char tmpTitle[TITLE_SIZE];
char oldTitle[TITLE_SIZE];
sprintf(tmpTitle, "SeArChInG FoR WiNdOw %ld", GetCurrentThreadId());
if (!GetConsoleTitle(oldTitle, TITLE_SIZE) ||
!SetConsoleTitle(tmpTitle))
return NULL;
Sleep(40); /* Ensure window title has been updated */
hwnd = FindWindow("ConsoleWindowClass", tmpTitle);
SetConsoleTitle(oldTitle);
return hwnd;
} /* end GetConsoleHwnd */
/*------------------------------------------------------------------*/
DWORD
constant(char *name, int arg)
{
errno = 0;
switch (*name) {
case 'A':
break;
case 'B':
if (strEQ(name, "BACKGROUND_BLUE"))
#ifdef BACKGROUND_BLUE
return BACKGROUND_BLUE;
#else
goto not_there;
#endif
if (strEQ(name, "BACKGROUND_GREEN"))
#ifdef BACKGROUND_GREEN
return BACKGROUND_GREEN;
#else
goto not_there;
#endif
if (strEQ(name, "BACKGROUND_INTENSITY"))
#ifdef BACKGROUND_INTENSITY
return BACKGROUND_INTENSITY;
#else
goto not_there;
#endif
if (strEQ(name, "BACKGROUND_RED"))
#ifdef BACKGROUND_RED
return BACKGROUND_RED;
#else
goto not_there;
#endif
break;
case 'C':
if (strEQ(name, "CAPSLOCK_ON"))
#ifdef CAPSLOCK_ON
return CAPSLOCK_ON;
#else
goto not_there;
#endif
if (strEQ(name, "CONSOLE_TEXTMODE_BUFFER"))
#ifdef CONSOLE_TEXTMODE_BUFFER
return CONSOLE_TEXTMODE_BUFFER;
#else
goto not_there;
#endif
if (strEQ(name, "CTRL_BREAK_EVENT"))
#ifdef CTRL_BREAK_EVENT
return CTRL_BREAK_EVENT;
#else
goto not_there;
#endif
if (strEQ(name, "CTRL_C_EVENT"))
#ifdef CTRL_C_EVENT
return CTRL_C_EVENT;
#else
goto not_there;
#endif
break;
case 'D':
break;
case 'E':
if (strEQ(name, "ENABLE_ECHO_INPUT"))
#ifdef ENABLE_ECHO_INPUT
return ENABLE_ECHO_INPUT;
#else
goto not_there;
#endif
if (strEQ(name, "ENABLE_LINE_INPUT"))
#ifdef ENABLE_LINE_INPUT
return ENABLE_LINE_INPUT;
#else
goto not_there;
#endif
if (strEQ(name, "ENABLE_MOUSE_INPUT"))
#ifdef ENABLE_MOUSE_INPUT
return ENABLE_MOUSE_INPUT;
#else
goto not_there;
#endif
if (strEQ(name, "ENABLE_PROCESSED_INPUT"))
#ifdef ENABLE_PROCESSED_INPUT
return ENABLE_PROCESSED_INPUT;
#else
goto not_there;
#endif
if (strEQ(name, "ENABLE_PROCESSED_OUTPUT"))
#ifdef ENABLE_PROCESSED_OUTPUT
return ENABLE_PROCESSED_OUTPUT;
#else
goto not_there;
#endif
if (strEQ(name, "ENABLE_WINDOW_INPUT"))
#ifdef ENABLE_WINDOW_INPUT
return ENABLE_WINDOW_INPUT;
#else
goto not_there;
#endif
if (strEQ(name, "ENABLE_WRAP_AT_EOL_OUTPUT"))
#ifdef ENABLE_WRAP_AT_EOL_OUTPUT
return ENABLE_WRAP_AT_EOL_OUTPUT;
#else
goto not_there;
#endif
if (strEQ(name, "ENHANCED_KEY"))
#ifdef ENHANCED_KEY
return ENHANCED_KEY;
#else
goto not_there;
#endif
break;
case 'F':
if (strEQ(name, "FILE_SHARE_READ"))
#ifdef FILE_SHARE_READ
return FILE_SHARE_READ;
#else
goto not_there;
#endif
if (strEQ(name, "FILE_SHARE_WRITE"))
#ifdef FILE_SHARE_WRITE
return FILE_SHARE_WRITE;
#else
goto not_there;
#endif
if (strEQ(name, "FOREGROUND_BLUE"))
#ifdef FOREGROUND_BLUE
return FOREGROUND_BLUE;
#else
goto not_there;
#endif
if (strEQ(name, "FOREGROUND_GREEN"))
#ifdef FOREGROUND_GREEN
return FOREGROUND_GREEN;
#else
goto not_there;
#endif
if (strEQ(name, "FOREGROUND_INTENSITY"))
#ifdef FOREGROUND_INTENSITY
return FOREGROUND_INTENSITY;
#else
goto not_there;
#endif
if (strEQ(name, "FOREGROUND_RED"))
#ifdef FOREGROUND_RED
return FOREGROUND_RED;
#else
goto not_there;
#endif
break;
case 'G':
if (strEQ(name, "GENERIC_READ"))
#ifdef GENERIC_READ
return GENERIC_READ;
#else
goto not_there;
#endif
if (strEQ(name, "GENERIC_WRITE"))
#ifdef GENERIC_WRITE
return GENERIC_WRITE;
#else
goto not_there;
#endif
break;
case 'H':
break;
case 'I':
break;
case 'J':
break;
case 'K':
if (strEQ(name, "KEY_EVENT"))
#ifdef KEY_EVENT
return KEY_EVENT;
#else
goto not_there;
#endif
break;
case 'L':
if (strEQ(name, "LEFT_ALT_PRESSED"))
#ifdef LEFT_ALT_PRESSED
return LEFT_ALT_PRESSED;
#else
goto not_there;
#endif
if (strEQ(name, "LEFT_CTRL_PRESSED"))
#ifdef LEFT_CTRL_PRESSED
return LEFT_CTRL_PRESSED;
#else
goto not_there;
#endif
break;
case 'M':
break;
case 'N':
if (strEQ(name, "NUMLOCK_ON"))
#ifdef NUMLOCK_ON
return NUMLOCK_ON;
#else
goto not_there;
#endif
break;
case 'O':
break;
case 'P':
break;
case 'Q':
break;
case 'R':
if (strEQ(name, "RIGHT_ALT_PRESSED"))
#ifdef RIGHT_ALT_PRESSED
return RIGHT_ALT_PRESSED;
#else
goto not_there;
#endif
if (strEQ(name, "RIGHT_CTRL_PRESSED"))
#ifdef RIGHT_CTRL_PRESSED
return RIGHT_CTRL_PRESSED;
#else
goto not_there;
#endif
break;
case 'S':
if (strEQ(name, "SCROLLLOCK_ON"))
#ifdef SCROLLLOCK_ON
return SCROLLLOCK_ON;
#else
goto not_there;
#endif
if (strEQ(name, "SHIFT_PRESSED"))
#ifdef SHIFT_PRESSED
return SHIFT_PRESSED;
#else
goto not_there;
#endif
if (strEQ(name, "STD_ERROR_HANDLE"))
#ifdef STD_ERROR_HANDLE
return STD_ERROR_HANDLE;
#else
goto not_there;
#endif
if (strEQ(name, "STD_INPUT_HANDLE"))
#ifdef STD_INPUT_HANDLE
return STD_INPUT_HANDLE;
#else
goto not_there;
#endif
if (strEQ(name, "STD_OUTPUT_HANDLE"))
#ifdef STD_OUTPUT_HANDLE
return STD_OUTPUT_HANDLE;
#else
goto not_there;
#endif
break;
case 'T':
break;
case 'U':
break;
case 'V':
break;
case 'W':
break;
case 'X':
break;
case 'Y':
break;
case 'Z':
break;
}
errno = EINVAL;
return 0;
not_there:
errno = ENOENT;
return 0;
}
/*
BOOL HandlerRoutine(DWORD dwCtrlType) {
int count;
int result;
// printf("HandlerRoutine: CtrlType=%d\n", dwCtrlType);
dSP;
ENTER;
SAVETMPS;
PUSHMARK(sp);
XPUSHs(sv_2mortal(newSViv(dwCtrlType)));
PUTBACK;
count = perl_call_pv("Win32::Console::CtrlHandler", G_EVAL|G_SCALAR);
SPAGAIN;
// Check the eval first
//if (SvTRUE(GvSV(lerrgv))) {
// POPs ;
// PUTBACK ;
// FREETMPS ;
// LEAVE ;
// // ExitProcess(0);
// return(TRUE);
//} else {
if (count < 1) {
result = 0;
} else {
result = POPi;
}
PUTBACK ;
FREETMPS ;
LEAVE ;
printf("HandlerRoutine: result=%d\n", result);
if (result == 0) {
printf("HandlerRoutine: returning FALSE\n");
return(FALSE);
} else {
printf("HandlerRoutine: returning TRUE\n");
// ExitProcess(0);
return(TRUE);
}
//}
}
void
_SetConsoleCtrlHandler(...)
PPCODE:
if (SetConsoleCtrlHandler((PHANDLER_ROUTINE)HandlerRoutine,(BOOL)TRUE))
XSRETURN_YES;
else
XSRETURN_NO;
*/
MODULE = Win32::Console PACKAGE = Win32::Console
PROTOTYPES: DISABLE
DWORD
constant(name,arg)
char *name
int arg
CODE:
RETVAL = constant(name, arg);
OUTPUT:
RETVAL
void
_GetStdHandle(fd)
DWORD fd
PPCODE:
#ifdef _WIN64
XSRETURN_IV((DWORD_PTR)GetStdHandle(fd));
#else
XSRETURN_IV((DWORD)GetStdHandle(fd));
#endif
void
_SetStdHandle(fd,handle)
DWORD fd
HANDLE handle
PPCODE:
if (SetStdHandle(fd, handle))
XSRETURN_YES;
else
XSRETURN_NO;
void
MouseButtons(...)
PPCODE:
DWORD buttons;
if (GetNumberOfConsoleMouseButtons(&buttons))
XSRETURN_IV(buttons);
else
XSRETURN_NO;
void
_SetConsoleCursorPosition(handle,x,y)
HANDLE handle
SHORT x
SHORT y
PPCODE:
COORD coords;
coords.X=x;
coords.Y=y;
if (SetConsoleCursorPosition(handle, coords))
XSRETURN_YES;
else
XSRETURN_NO;
void
_WriteConsoleOutputAttribute(handle, string,x,y)
HANDLE handle
char * string
SHORT x
SHORT y
PPCODE:
DWORD i;
COORD coords;
DWORD written;
unsigned short buffer[80*999*sizeof(unsigned short)];
DWORD towrite = (DWORD)strlen(string);
for(i=0; i<towrite; i++) {
buffer[i] = (unsigned short)(string[i]);
}
coords.X=x;
coords.Y=y;
if (WriteConsoleOutputAttribute(handle,
(const unsigned short *)&buffer,
towrite,
coords,
&written))
XSRETURN_IV(written);
else
XSRETURN_NO;
void
_WriteConsoleOutputCharacter(handle,string,x,y)
HANDLE handle
char * string
SHORT x
SHORT y
PPCODE:
COORD coords;
DWORD written;
coords.X=x;
coords.Y=y;
if (WriteConsoleOutputCharacter(handle,
(LPCTSTR)string,
(DWORD)strlen(string),
coords,
&written))
XSRETURN_IV(written);
else
XSRETURN_NO;
void
_ReadConsoleOutputCharacter(handle,charbuf,len,x,y)
HANDLE handle
char * charbuf
DWORD len
SHORT x
SHORT y
PPCODE:
COORD coords;
DWORD nofread;
coords.X=x;
coords.Y=y;
if (ReadConsoleOutputCharacter(handle,charbuf,len,coords,&nofread))
XSRETURN_YES;
else
XSRETURN_NO;
void
_ReadConsoleOutputAttribute(handle,len,x,y)
HANDLE handle
DWORD len
SHORT x
SHORT y
PPCODE:
DWORD i;
COORD coords;
DWORD nofread;
unsigned short abuffer[80*999*sizeof(unsigned short)];
char cbuffer[80*999];
coords.X=x;
coords.Y=y;
if (ReadConsoleOutputAttribute(handle,abuffer,len,coords,&nofread)) {
for(i=0;i<nofread;i++) {
cbuffer[i]=(char)abuffer[i];
}
ST(0)=sv_2mortal(newSVpv(cbuffer,nofread));
XSRETURN(1);
}
else
XSRETURN_NO;
void
_WriteConsole(handle,buffer)
HANDLE handle
char * buffer
PPCODE:
DWORD written;
if (WriteConsole(handle,(VOID *)buffer,(DWORD)strlen(buffer),&written,NULL))
XSRETURN_IV(written);
else
XSRETURN_NO;
void
_ScrollConsoleScreenBuffer(handle,l1,t1,r1,b1,col,row,chr,attr,l2,t2,r2,b2)
HANDLE handle
SHORT l1
SHORT t1
SHORT r1
SHORT b1
SHORT col
SHORT row
WCHAR chr
unsigned short attr
SHORT l2
SHORT t2
SHORT r2
SHORT b2
PPCODE:
COORD dest;
SMALL_RECT area;
SMALL_RECT clip;
CHAR_INFO fill;
area.Left = l1;
area.Top = t1;
area.Right = r1;
area.Bottom = b1;
dest.X=col;
dest.Y=row;
#ifdef UNICODE
fill.Char.UnicodeChar=chr;
#else
fill.Char.AsciiChar=(CHAR)chr;
#endif
fill.Attributes=attr;
if (items > 9) {
clip.Left = l2;
clip.Top = t2;
clip.Right = r2;
clip.Bottom = b2;
if (ScrollConsoleScreenBuffer(handle,&area,&clip,dest,&fill))
XSRETURN_YES;
else
XSRETURN_NO;
}
else {
if (ScrollConsoleScreenBuffer(handle,&area,NULL,dest,&fill))
XSRETURN_YES;
else
XSRETURN_NO;
}
void
_WriteConsoleOutput(handle,buffer,srcwid,srcht,startx,starty,l,t,r,b)
HANDLE handle
char * buffer
SHORT srcwid
SHORT srcht
SHORT startx
SHORT starty
SHORT l
SHORT t
SHORT r
SHORT b
PPCODE:
COORD coords;
COORD size;
SMALL_RECT to;
size.X=srcwid;
size.Y=srcht;
coords.X=startx;
coords.Y=starty;
to.Left = l;
to.Top = t;
to.Right = r;
to.Bottom = b;
if (WriteConsoleOutput(handle,(CHAR_INFO *)buffer,size,coords,&to)) {
XST_mIV(0,to.Left);
XST_mIV(1,to.Top);
XST_mIV(2,to.Right);
XST_mIV(3,to.Bottom);
XSRETURN(4);
}
else
XSRETURN_NO;
void
_ReadConsoleOutput(handle,buffer,srcwid,srcht,startx,starty,l,t,r,b)
HANDLE handle
char * buffer
SHORT srcwid
SHORT srcht
SHORT startx
SHORT starty
SHORT l
SHORT t
SHORT r
SHORT b
PPCODE:
COORD coords;
COORD size;
SMALL_RECT from;
size.X=srcwid;
size.Y=srcht;
coords.X=startx;
coords.Y=starty;
from.Left = l;
from.Top = t;
from.Right = r;
from.Bottom = b;
if (ReadConsoleOutput(handle,(CHAR_INFO *)buffer,size,coords,&from)) {
XST_mIV(0,from.Left);
XST_mIV(1,from.Top);
XST_mIV(2,from.Right);
XST_mIV(3,from.Bottom);
XSRETURN(4);
}
else
XSRETURN_NO;
void
_SetConsoleWindowInfo(handle,flag,l,t,r,b)
HANDLE handle
BOOL flag
SHORT l
SHORT t
SHORT r
SHORT b
PPCODE:
SMALL_RECT newwin;
newwin.Left = l;
newwin.Top = t;
newwin.Right = r;
newwin.Bottom = b;
if (SetConsoleWindowInfo(handle,flag,&newwin))
XSRETURN_YES;
else
XSRETURN_NO;
void
_GetNumberOfConsoleInputEvents(handle)
HANDLE handle
PPCODE:
DWORD nofevents;
if (GetNumberOfConsoleInputEvents(handle, &nofevents))
XSRETURN_IV(nofevents);
else
XSRETURN_NO;
void
_FlushConsoleInputBuffer(handle)
HANDLE handle
PPCODE:
if (FlushConsoleInputBuffer(handle))
XSRETURN_YES;
else
XSRETURN_NO;
void
_ReadConsole(handle,buffer,numread)
HANDLE handle
char * buffer
DWORD numread
PPCODE:
DWORD nofread;
if (ReadConsole(handle,(void *)buffer,numread,&nofread,NULL))
XSRETURN_IV(nofread);
else
XSRETURN_NO;
void
_ReadConsoleInput(handle)
HANDLE handle
PPCODE:
DWORD nofread;
INPUT_RECORD event;
KEY_EVENT_RECORD * kevent;
MOUSE_EVENT_RECORD * mevent;
if (ReadConsoleInput(handle,&event,1,&nofread)) {
switch(event.EventType) {
case KEY_EVENT:
EXTEND(SP,7);
kevent=(KEY_EVENT_RECORD *)&(event.Event);
XST_mIV(0,KEY_EVENT);
XST_mIV(1,kevent->bKeyDown);
XST_mIV(2,kevent->wRepeatCount);
XST_mIV(3,kevent->wVirtualKeyCode);
XST_mIV(4,kevent->wVirtualScanCode);
#ifdef UNICODE
XST_mIV(5,kevent->uChar.UnicodeChar);
#else
XST_mIV(5,kevent->uChar.AsciiChar);
#endif
XST_mIV(6,kevent->dwControlKeyState);
XSRETURN(7);
break;
case MOUSE_EVENT:
EXTEND(SP,6);
mevent=(MOUSE_EVENT_RECORD *)&(event.Event);
XST_mIV(0,MOUSE_EVENT);
XST_mIV(1,mevent->dwMousePosition.X);
XST_mIV(2,mevent->dwMousePosition.Y);
XST_mIV(3,mevent->dwButtonState);
XST_mIV(4,mevent->dwControlKeyState);
XST_mIV(5,mevent->dwEventFlags);
XSRETURN(6);
break;
}
}
else {
XSRETURN_NO;
}
void
_WriteConsoleInput(handle,type,...)
HANDLE handle
int type
PPCODE:
DWORD written;
INPUT_RECORD event;
KEY_EVENT_RECORD * kevent;
MOUSE_EVENT_RECORD * mevent;
event.EventType = type;
switch(event.EventType) {
case KEY_EVENT:
kevent = (KEY_EVENT_RECORD *)&(event.Event);
kevent->bKeyDown = (BOOL)SvIV(ST(2));
kevent->wRepeatCount = (WORD)SvIV(ST(3));
kevent->wVirtualKeyCode = (WORD)SvIV(ST(4));
kevent->wVirtualScanCode = (WORD)SvIV(ST(5));
#ifdef UNICODE
kevent->uChar.UnicodeChar = (WCHAR)SvIV(ST(6));
#else
kevent->uChar.AsciiChar = (CHAR)SvIV(ST(7));
#endif
break;
case MOUSE_EVENT:
mevent = (MOUSE_EVENT_RECORD *)&(event.Event);
mevent->dwMousePosition.X = (SHORT)SvIV(ST(2));
mevent->dwMousePosition.Y = (SHORT)SvIV(ST(3));
mevent->dwButtonState = (DWORD)SvIV(ST(4));
mevent->dwControlKeyState = (DWORD)SvIV(ST(5));
mevent->dwEventFlags = (DWORD)SvIV(ST(6));
break;
default:
XSRETURN_NO;
break;
}
if (WriteConsoleInput(handle,&event,1,&written))
XSRETURN_YES;
else
XSRETURN_NO;
void
_PeekConsoleInput(handle)
HANDLE handle
PPCODE:
DWORD nofread;
INPUT_RECORD event;
KEY_EVENT_RECORD * kevent;
MOUSE_EVENT_RECORD * mevent;
if (PeekConsoleInput(handle,&event,1,&nofread)) {
switch(event.EventType) {
case KEY_EVENT:
EXTEND(SP,7);
kevent=(KEY_EVENT_RECORD *)&(event.Event);
XST_mIV(0,KEY_EVENT);
XST_mIV(1,kevent->bKeyDown);
XST_mIV(2,kevent->wRepeatCount);
XST_mIV(3,kevent->wVirtualKeyCode);
XST_mIV(4,kevent->wVirtualScanCode);
#ifdef UNICODE
XST_mIV(5,kevent->uChar.UnicodeChar);
#else
XST_mIV(5,kevent->uChar.AsciiChar);
#endif
XST_mIV(6,kevent->dwControlKeyState);
XSRETURN(7);
break;
case MOUSE_EVENT:
EXTEND(SP,6);
mevent=(MOUSE_EVENT_RECORD *)&(event.Event);
XST_mIV(0,MOUSE_EVENT);
XST_mIV(1,mevent->dwMousePosition.X);
XST_mIV(2,mevent->dwMousePosition.Y);
XST_mIV(3,mevent->dwButtonState);
XST_mIV(4,mevent->dwControlKeyState);
XST_mIV(5,mevent->dwEventFlags);
XSRETURN(6);
break;
}
}
else
XSRETURN_NO;
void
_SetConsoleMode(handle,mode)
HANDLE handle
DWORD mode
PPCODE:
if (SetConsoleMode(handle, mode))
XSRETURN_YES;
else
XSRETURN_NO;
void
_GetConsoleMode(handle)
HANDLE handle
PPCODE:
DWORD flags;
if (GetConsoleMode(handle, &flags))
XSRETURN_IV(flags);
else
XSRETURN_NO;
void
_SetConsoleTextAttribute(handle,attr)
HANDLE handle
WORD attr
PPCODE:
if (SetConsoleTextAttribute(handle,attr))
XSRETURN_YES;
else
XSRETURN_NO;
void
_GetConsoleScreenBufferInfo(handle)
HANDLE handle
PPCODE:
CONSOLE_SCREEN_BUFFER_INFO info;
if (GetConsoleScreenBufferInfo(handle,&info)) {
EXTEND(SP,11);
XST_mIV( 0,info.dwSize.X);
XST_mIV( 1,info.dwSize.Y);
XST_mIV( 2,info.dwCursorPosition.X);
XST_mIV( 3,info.dwCursorPosition.Y);
XST_mIV( 4,info.wAttributes);
XST_mIV( 5,info.srWindow.Left);
XST_mIV( 6,info.srWindow.Top);
XST_mIV( 7,info.srWindow.Right);
XST_mIV( 8,info.srWindow.Bottom);
XST_mIV( 9,info.dwMaximumWindowSize.X);
XST_mIV(10,info.dwMaximumWindowSize.Y);
XSRETURN(11);
}
else
XSRETURN_NO;
void
_SetConsoleScreenBufferSize(handle,x,y)
HANDLE handle
SHORT x
SHORT y
PPCODE:
COORD size;
size.X=x;
size.Y=y;
if (SetConsoleScreenBufferSize(handle, size))
XSRETURN_YES;
else
XSRETURN_NO;
void
_GetConsoleCursorInfo(handle)
HANDLE handle
PPCODE:
CONSOLE_CURSOR_INFO info;
if (GetConsoleCursorInfo(handle, &info)) {
EXTEND(SP,2);
XST_mIV(0,info.dwSize);
XST_mIV(1,info.bVisible);
XSRETURN(2);
}
else
XSRETURN_NO;
void
_SetConsoleCursorInfo(handle,size,visible)
HANDLE handle
DWORD size
BOOL visible
PPCODE:
CONSOLE_CURSOR_INFO info;
info.dwSize=size;
info.bVisible=visible;
if (SetConsoleCursorInfo(handle, &info))
XSRETURN_YES;
else
XSRETURN_NO;
void
_FillConsoleOutputAttribute(handle,attr,len,x,y)
HANDLE handle
WORD attr
DWORD len
SHORT x
SHORT y
PPCODE:
COORD coords;
DWORD written;
coords.X=x;
coords.Y=y;
if (FillConsoleOutputAttribute(handle,attr,len,coords,&written))
XSRETURN_IV(written);
else
XSRETURN_NO;
void
_FillConsoleOutputCharacter(handle,chr,len,x,y)
HANDLE handle
char * chr
DWORD len
SHORT x
SHORT y
PPCODE:
COORD coords;
DWORD written;
coords.X=x;
coords.Y=y;
if (FillConsoleOutputCharacter(handle, *chr, len, coords, &written))
XSRETURN_IV(written);
else
XSRETURN_NO;
void
_CreateConsoleScreenBuffer(access,sharemode,flags)
DWORD access
DWORD sharemode
DWORD flags