forked from vpinball/vpinball
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pininput.cpp
2140 lines (1976 loc) · 86.3 KB
/
pininput.cpp
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
#include "stdafx.h"
// from dinput.h, modernized to please clang
#undef DIJOFS_X
#undef DIJOFS_Y
#undef DIJOFS_Z
#undef DIJOFS_RX
#undef DIJOFS_RY
#undef DIJOFS_RZ
#undef DIJOFS_SLIDER
#undef DIJOFS_POV
#undef DIJOFS_BUTTON
#define DIJOFS_X offsetof(DIJOYSTATE, lX)
#define DIJOFS_Y offsetof(DIJOYSTATE, lY)
#define DIJOFS_Z offsetof(DIJOYSTATE, lZ)
#define DIJOFS_RX offsetof(DIJOYSTATE, lRx)
#define DIJOFS_RY offsetof(DIJOYSTATE, lRy)
#define DIJOFS_RZ offsetof(DIJOYSTATE, lRz)
#define DIJOFS_SLIDER(n) (offsetof(DIJOYSTATE, rglSlider) + (n) * sizeof(LONG))
#define DIJOFS_POV(n) (offsetof(DIJOYSTATE, rgdwPOV) + (n) * sizeof(DWORD))
#define DIJOFS_BUTTON(n) (offsetof(DIJOYSTATE, rgbButtons) + (n))
// end
#define INPUT_BUFFER_SIZE MAX_KEYQUEUE_SIZE
#define BALLCONTROL_DOUBLECLICK_THRESHOLD_USEC (500 * 1000)
PinInput::PinInput()
{
ZeroMemory(this, sizeof(PinInput));
#ifdef _WIN32
m_pDI = nullptr;
#ifdef USE_DINPUT_FOR_KEYBOARD
m_pKeyboard = nullptr;
#endif
m_pMouse = nullptr;
#endif
m_leftMouseButtonDown = false;
m_rightMouseButtonDown = false;
m_middleMouseButtonDown = false;
m_head = m_tail = 0;
ZeroMemory(m_diq, sizeof(m_diq));
m_num_joy = 0;
#ifdef _WIN32
for (int k = 0; k < PININ_JOYMXCNT; ++k)
m_pJoystick[k] = nullptr;
#endif
uShockType = 0;
m_plunger_axis = 3;
m_lr_axis = 1;
m_ud_axis = 2;
m_plunger_reverse = false;
m_plunger_retract = false;
m_lr_axis_reverse = false;
m_ud_axis_reverse = false;
m_override_default_buttons = false;
m_disable_esc = false;
m_joylflipkey = 0;
m_joyrflipkey = 0;
m_joystagedlflipkey = 0;
m_joystagedrflipkey = 0;
m_joylmagnasave = 0;
m_joyrmagnasave = 0;
m_joyplungerkey = 0;
m_joystartgamekey = 0;
m_joyexitgamekey = 0;
m_joyaddcreditkey = 0;
m_joyaddcreditkey2 = 0;
m_joyframecount = 0;
m_joyvolumeup = 0;
m_joyvolumedown = 0;
m_joylefttilt = 0;
m_joycentertilt = 0;
m_joyrighttilt = 0;
m_joypmbuyin = 0;
m_joypmcoin3 = 0;
m_joypmcoin4 = 0;
m_joypmcoindoor = 0;
m_joypmcancel = 0;
m_joypmdown = 0;
m_joypmup = 0;
m_joypmenter = 0;
m_joycustom1 = 0;
m_joycustom2 = 0;
m_joycustom3 = 0;
m_joycustom4 = 0;
m_joydebugballs = 0;
m_joydebugger = 0;
m_joylockbar = 0;
m_joypause = 0;
m_joytweak = 0;
m_joymechtilt = 0;
m_joytablerecenter = 0;
m_joytableup = 0;
m_joytabledown = 0;
m_firedautostart = 0;
m_pressed_start = false;
m_enableMouseInPlayer = true;
m_enableCameraModeFlyAround = false;
m_enable_nudge_filter = false;
m_cameraModeAltKey = false;
m_cameraMode = 0;
m_exit_stamp = 0;
m_first_stamp = msec();
m_as_down = false;
m_as_didonce = false;
m_tilt_updown = false;
m_linearPlunger = false;
m_mixerKeyDown = false;
m_mixerKeyUp = false;
}
PinInput::~PinInput()
{
#ifdef ENABLE_SDL_INPUT
#ifndef ENABLE_SDL_GAMECONTROLLER
if (m_rumbleDeviceSDL)
SDL_HapticClose(m_rumbleDeviceSDL);
if (m_inputDeviceSDL)
SDL_JoystickClose(m_inputDeviceSDL);
#else
SDL_GameControllerClose(m_gameController);
#endif
#endif
}
void PinInput::LoadSettings(const Settings& settings)
{
m_lr_axis = settings.LoadValueWithDefault(Settings::Player, "LRAxis"s, m_lr_axis);
m_ud_axis = settings.LoadValueWithDefault(Settings::Player, "UDAxis"s, m_ud_axis);
m_lr_axis_reverse = settings.LoadValueWithDefault(Settings::Player, "LRAxisFlip"s, m_lr_axis_reverse);
m_ud_axis_reverse = settings.LoadValueWithDefault(Settings::Player, "UDAxisFlip"s, m_ud_axis_reverse);
m_plunger_axis = settings.LoadValueWithDefault(Settings::Player, "PlungerAxis"s, m_plunger_axis);
m_plunger_reverse = settings.LoadValueWithDefault(Settings::Player, "ReversePlungerAxis"s, m_plunger_reverse);
m_plunger_retract = settings.LoadValueWithDefault(Settings::Player, "PlungerRetract"s, m_plunger_retract);
m_override_default_buttons = settings.LoadValueWithDefault(Settings::Player, "PBWDefaultLayout"s, m_override_default_buttons);
m_disable_esc = settings.LoadValueWithDefault(Settings::Player, "DisableESC"s, m_disable_esc);
m_joylflipkey = settings.LoadValueWithDefault(Settings::Player, "JoyLFlipKey"s, m_joylflipkey);
m_joyrflipkey = settings.LoadValueWithDefault(Settings::Player, "JoyRFlipKey"s, m_joyrflipkey);
m_joystagedlflipkey = settings.LoadValueWithDefault(Settings::Player, "JoyStagedLFlipKey"s, m_joystagedlflipkey);
m_joystagedrflipkey = settings.LoadValueWithDefault(Settings::Player, "JoyStagedRFlipKey"s, m_joystagedrflipkey);
m_joyplungerkey = settings.LoadValueWithDefault(Settings::Player, "JoyPlungerKey"s, m_joyplungerkey);
m_joyaddcreditkey = settings.LoadValueWithDefault(Settings::Player, "JoyAddCreditKey"s, m_joyaddcreditkey);
m_joyaddcreditkey2 = settings.LoadValueWithDefault(Settings::Player, "JoyAddCredit2Key"s, m_joyaddcreditkey2);
m_joylmagnasave = settings.LoadValueWithDefault(Settings::Player, "JoyLMagnaSave"s, m_joylmagnasave);
m_joyrmagnasave = settings.LoadValueWithDefault(Settings::Player, "JoyRMagnaSave"s, m_joyrmagnasave);
m_joystartgamekey = settings.LoadValueWithDefault(Settings::Player, "JoyStartGameKey"s, m_joystartgamekey);
m_joyframecount = settings.LoadValueWithDefault(Settings::Player, "JoyFrameCount"s, m_joyframecount);
m_joyexitgamekey = settings.LoadValueWithDefault(Settings::Player, "JoyExitGameKey"s, m_joyexitgamekey);
m_joyvolumeup = settings.LoadValueWithDefault(Settings::Player, "JoyVolumeUp"s, m_joyvolumeup);
m_joyvolumedown = settings.LoadValueWithDefault(Settings::Player, "JoyVolumeDown"s, m_joyvolumedown);
m_joylefttilt = settings.LoadValueWithDefault(Settings::Player, "JoyLTiltKey"s, m_joylefttilt);
m_joycentertilt = settings.LoadValueWithDefault(Settings::Player, "JoyCTiltKey"s, m_joycentertilt);
m_joyrighttilt = settings.LoadValueWithDefault(Settings::Player, "JoyRTiltKey"s, m_joyrighttilt);
m_joypmbuyin = settings.LoadValueWithDefault(Settings::Player, "JoyPMBuyIn"s, m_joypmbuyin);
m_joypmcoin3 = settings.LoadValueWithDefault(Settings::Player, "JoyPMCoin3"s, m_joypmcoin3);
m_joypmcoin4 = settings.LoadValueWithDefault(Settings::Player, "JoyPMCoin4"s, m_joypmcoin4);
m_joypmcoindoor = settings.LoadValueWithDefault(Settings::Player, "JoyPMCoinDoor"s, m_joypmcoindoor);
m_joypmcancel = settings.LoadValueWithDefault(Settings::Player, "JoyPMCancel"s, m_joypmcancel);
m_joypmdown = settings.LoadValueWithDefault(Settings::Player, "JoyPMDown"s, m_joypmdown);
m_joypmup = settings.LoadValueWithDefault(Settings::Player, "JoyPMUp"s, m_joypmup);
m_joypmenter = settings.LoadValueWithDefault(Settings::Player, "JoyPMEnter"s, m_joypmenter);
m_joycustom1 = settings.LoadValueWithDefault(Settings::Player, "JoyCustom1"s, m_joycustom1);
m_joycustom1key = settings.LoadValueWithDefault(Settings::Player, "JoyCustom1Key"s, m_joycustom1key);
m_joycustom2 = settings.LoadValueWithDefault(Settings::Player, "JoyCustom2"s, m_joycustom2);
m_joycustom2key = settings.LoadValueWithDefault(Settings::Player, "JoyCustom2Key"s, m_joycustom2key);
m_joycustom3 = settings.LoadValueWithDefault(Settings::Player, "JoyCustom3"s, m_joycustom3);
m_joycustom3key = settings.LoadValueWithDefault(Settings::Player, "JoyCustom3Key"s, m_joycustom3key);
m_joycustom4 = settings.LoadValueWithDefault(Settings::Player, "JoyCustom4"s, m_joycustom4);
m_joycustom4key = settings.LoadValueWithDefault(Settings::Player, "JoyCustom4Key"s, m_joycustom4key);
m_joymechtilt = settings.LoadValueWithDefault(Settings::Player, "JoyMechTiltKey"s, m_joymechtilt);
m_joydebugballs = settings.LoadValueWithDefault(Settings::Player, "JoyDebugKey"s, m_joydebugballs);
m_joydebugger = settings.LoadValueWithDefault(Settings::Player, "JoyDebuggerKey"s, m_joydebugger);
m_joylockbar = settings.LoadValueWithDefault(Settings::Player, "JoyLockbarKey"s, m_joylockbar);
m_joypause = settings.LoadValueWithDefault(Settings::Player, "JoyPauseKey"s, m_joypause);
m_joytweak = settings.LoadValueWithDefault(Settings::Player, "JoyTweakKey"s, m_joytweak);
m_joytablerecenter = settings.LoadValueWithDefault(Settings::Player, "JoyTableRecenterKey"s, m_joytablerecenter);
m_joytableup = settings.LoadValueWithDefault(Settings::Player, "JoyTableUpKey"s, m_joytableup);
m_joytabledown = settings.LoadValueWithDefault(Settings::Player, "JoyTableDownKey"s, m_joytabledown);
m_enableMouseInPlayer = settings.LoadValueWithDefault(Settings::Player, "EnableMouseInPlayer"s, m_enableMouseInPlayer);
m_enableCameraModeFlyAround = settings.LoadValueWithDefault(Settings::Player, "EnableCameraModeFlyAround"s, m_enableCameraModeFlyAround);
m_enable_nudge_filter = settings.LoadValueWithDefault(Settings::Player, "EnableNudgeFilter"s, m_enable_nudge_filter);
m_deadz = settings.LoadValueWithDefault(Settings::Player, "DeadZone"s, 0);
m_deadz = m_deadz*JOYRANGEMX / 100;
}
#ifdef ENABLE_SDL_GAMECONTROLLER
void PinInput::SetupSDLGameController()
{
if (m_gameController != nullptr) {
SDL_GameControllerClose(m_gameController);
m_gameController = nullptr;
}
if(SDL_NumJoysticks() < 1) {
PLOGI.printf("No joysticks connected!");
}
else {
for (int idx = 0; idx < SDL_NumJoysticks(); idx++) {
if (!SDL_IsGameController(idx)) {
PLOGI.printf("Joystick %d is not a game controller", idx);
}
else {
#if defined(__APPLE__) && ((defined(TARGET_OS_IOS) && TARGET_OS_IOS) || (defined(TARGET_OS_TV) && TARGET_OS_TV))
if (!lstrcmpi(SDL_GameControllerNameForIndex(idx), "Remote"))
continue;
#endif
m_gameController = SDL_GameControllerOpen(idx);
PLOGI.printf("Game controller added: name=%s, rumble=%s",
SDL_GameControllerName(m_gameController),
SDL_GameControllerHasRumble(m_gameController) ? "true" : "false");
break;
}
}
}
}
#endif
//
// DirectInput:
//
//-----------------------------------------------------------------------------
// Name: EnumObjectsCallbackDI()
// Desc: Callback function for enumerating objects (axes, buttons, POVs) on a
// joystick. This function enables user interface elements for objects
// that are found to exist, and scales axes min/max values.
//-----------------------------------------------------------------------------
#ifdef _WIN32
BOOL CALLBACK EnumObjectsCallbackDI(const DIDEVICEOBJECTINSTANCE* pdidoi,
VOID* pContext)
{
const PinInput * const ppinput = (PinInput *)pContext;
#ifdef _DEBUG
static int nAxis = 0;
static int nButtons = 0;
static int nSliderCount = 0; // Number of returned slider controls
static int nPOVCount = 0; // Number of returned POV controls
static int nKey = 0;
static int nUnknown = 0;
#endif
// For axes that are returned, set the DIPROP_RANGE property for the
// enumerated axis in order to scale min/max values.
if (pdidoi->dwType & DIDFT_AXIS)
{
DIPROPRANGE diprg;
diprg.diph.dwSize = sizeof(DIPROPRANGE);
diprg.diph.dwHeaderSize = sizeof(DIPROPHEADER);
diprg.diph.dwObj = pdidoi->dwType; // Specify the enumerated axis
diprg.diph.dwHow = DIPH_BYID;
diprg.lMin = JOYRANGEMN;
diprg.lMax = JOYRANGEMX;
// Set the range for the axis
if (FAILED(ppinput->m_pJoystick[ppinput->m_num_joy]->SetProperty(DIPROP_RANGE, &diprg.diph)))
return DIENUM_STOP;
// set DEADBAND to Zero
DIPROPDWORD dipdw;
dipdw.diph.dwSize = sizeof(DIPROPDWORD);
dipdw.diph.dwHeaderSize = sizeof(DIPROPHEADER);
dipdw.diph.dwObj = pdidoi->dwType; // Specify the enumerated axis
dipdw.diph.dwHow = DIPH_BYID;
dipdw.dwData = 0; // no dead zone at joystick level
// Set the deadzone
if (FAILED(ppinput->m_pJoystick[ppinput->m_num_joy]->SetProperty(DIPROP_DEADZONE, &dipdw.diph)))
return DIENUM_STOP;
}
#ifdef _DEBUG
if (pdidoi->guidType == GUID_XAxis) { ++nAxis; }
else if (pdidoi->guidType == GUID_YAxis) { ++nAxis; }
else if (pdidoi->guidType == GUID_ZAxis) { ++nAxis; }
else if (pdidoi->guidType == GUID_RxAxis) { ++nAxis; }
else if (pdidoi->guidType == GUID_RyAxis) { ++nAxis; }
else if (pdidoi->guidType == GUID_RzAxis) { ++nAxis; }
else if (pdidoi->guidType == GUID_Slider) { ++nSliderCount; }
else if (pdidoi->guidType == GUID_Button) { ++nButtons; }
else if (pdidoi->guidType == GUID_Key) { ++nKey; }
else if (pdidoi->guidType == GUID_POV) { ++nPOVCount; }
else if (pdidoi->guidType == GUID_Unknown) { ++nUnknown; }
#endif
return DIENUM_CONTINUE;
}
// Callback for enumerating joysticks (gamepads)
BOOL CALLBACK EnumJoystickCallbackDI(LPCDIDEVICEINSTANCE lpddi, LPVOID pvRef)
{
DIPROPSTRING dstr;
dstr.diph.dwSize = sizeof(DIPROPSTRING);
dstr.diph.dwHeaderSize = sizeof(DIPROPHEADER);
dstr.diph.dwObj = 0;
dstr.diph.dwHow = DIPH_DEVICE;
PinInput * const ppinput = (PinInput *)pvRef;
HRESULT hr;
hr = ppinput->m_pDI->CreateDevice(lpddi->guidInstance, &ppinput->m_pJoystick[ppinput->m_num_joy], nullptr);
if (FAILED(hr))
{
ppinput->m_pJoystick[ppinput->m_num_joy] = nullptr; // make sure no garbage
return DIENUM_CONTINUE; // try for another joystick
}
hr = ppinput->m_pJoystick[ppinput->m_num_joy]->GetProperty(DIPROP_PRODUCTNAME, &dstr.diph);
if (hr == S_OK)
{
if (!WzSzStrCmp(dstr.wsz, "PinballWizard"))
ppinput->uShockType = USHOCKTYPE_PBWIZARD; // set type 1 = PinballWizard
else if (!WzSzStrCmp(dstr.wsz, "UltraCade Pinball"))
ppinput->uShockType = USHOCKTYPE_ULTRACADE; // set type 2 = UltraCade Pinball
else if (!WzSzStrCmp(dstr.wsz, "Microsoft SideWinder Freestyle Pro (USB)"))
ppinput->uShockType = USHOCKTYPE_SIDEWINDER; // set type 3 = Microsoft SideWinder Freestyle Pro
else if (!WzSzStrCmp(dstr.wsz, "VirtuaPin Controller"))
ppinput->uShockType = USHOCKTYPE_VIRTUAPIN; // set type 4 = VirtuaPin Controller
else if (!WzSzStrCmp(dstr.wsz, "Pinscape Controller"))
{
ppinput->uShockType = USHOCKTYPE_GENERIC; // set type = Generic
ppinput->m_linearPlunger = true; // use linear plunger calibration
}
else
ppinput->uShockType = USHOCKTYPE_GENERIC; // Generic Gamepad
}
hr = ppinput->m_pJoystick[ppinput->m_num_joy]->SetDataFormat(&c_dfDIJoystick);
// joystick input foreground or background focus
hr = ppinput->m_pJoystick[ppinput->m_num_joy]->SetCooperativeLevel(ppinput->m_hwnd, DISCL_NONEXCLUSIVE | DISCL_BACKGROUND);
DIPROPDWORD dipdw;
dipdw.diph.dwSize = sizeof(DIPROPDWORD);
dipdw.diph.dwHeaderSize = sizeof(DIPROPHEADER);
dipdw.diph.dwObj = 0;
dipdw.diph.dwHow = DIPH_DEVICE;
dipdw.dwData = INPUT_BUFFER_SIZE;
hr = ppinput->m_pJoystick[ppinput->m_num_joy]->SetProperty(DIPROP_BUFFERSIZE, &dipdw.diph);
// Enumerate the joystick objects. The callback function enabled user
// interface elements for objects that are found, and sets the min/max
// values property for discovered axes.
hr = ppinput->m_pJoystick[ppinput->m_num_joy]->EnumObjects(EnumObjectsCallbackDI, (VOID*)pvRef, DIDFT_ALL);
if (++(ppinput->m_num_joy) < PININ_JOYMXCNT)
return DIENUM_CONTINUE;
else
return DIENUM_STOP; //allocation for only PININ_JOYMXCNT joysticks, ignore any others
}
#endif
void PinInput::PushQueue(DIDEVICEOBJECTDATA * const data, const unsigned int app_data/*, const U32 curr_time_msec*/)
{
if ((!data) ||
(((m_head + 1) % MAX_KEYQUEUE_SIZE) == m_tail)) // queue full?
return;
m_diq[m_head] = *data;
//m_diq[m_head].dwTimeStamp = curr_time_msec; //rewrite time from game start
m_diq[m_head].dwSequence = app_data;
m_head = (m_head + 1) % MAX_KEYQUEUE_SIZE; // advance head of queue
}
const DIDEVICEOBJECTDATA *PinInput::GetTail(/*const U32 curr_sim_msec*/)
{
if (m_head == m_tail)
return nullptr; // queue empty?
const DIDEVICEOBJECTDATA * const ptr = &m_diq[m_tail];
// If we've simulated to or beyond the timestamp of when this control was received then process the control into the system
//if ( curr_sim_msec >= ptr->dwTimeStamp ) //!! time stamp disabled to save a bit of lag
{
m_tail = (m_tail + 1) % MAX_KEYQUEUE_SIZE; // advance tail of queue
return ptr;
}
//else return nullptr;
}
//
// End of Direct Input specific code
//
void PinInput::GetInputDeviceData(/*const U32 curr_time_msec*/)
{
DIDEVICEOBJECTDATA didod[INPUT_BUFFER_SIZE]; // Receives buffered data
#ifdef USE_DINPUT_FOR_KEYBOARD
// keyboard
#ifdef USE_DINPUT8
const LPDIRECTINPUTDEVICE8 pkyb = m_pKeyboard;
#else
const LPDIRECTINPUTDEVICE pkyb = m_pKeyboard;
#endif
if (pkyb)
{
HRESULT hr = pkyb->Acquire(); // try to acquire keyboard input
if (hr == S_OK || hr == S_FALSE)
{
DWORD dwElements = INPUT_BUFFER_SIZE;
hr = pkyb->GetDeviceData(sizeof(DIDEVICEOBJECTDATA), didod, &dwElements, 0);
if (hr == S_OK || hr == DI_BUFFEROVERFLOW)
{
if (m_hwnd == GetForegroundWindow())
for (DWORD i = 0; i < dwElements; i++)
PushQueue(&didod[i], APP_KEYBOARD/*, curr_time_msec*/);
}
}
}
#else
// cache to avoid double key triggers
static bool oldKeyStates[eCKeys] = { false };
#ifdef _WIN32
unsigned int i2 = 0;
for (unsigned int i = 0; i < eCKeys; ++i)
{
const unsigned int rgk = (unsigned int)g_pplayer->m_rgKeys[i];
const unsigned int vk = get_vk(rgk);
if (vk == ~0u)
continue;
const SHORT keyState = GetAsyncKeyState(vk);
const bool keyDown = !!((1 << 16) & keyState);
if (oldKeyStates[i] == keyDown)
continue;
oldKeyStates[i] = keyDown;
didod[i2].dwOfs = rgk;
didod[i2].dwData = keyDown ? 0x80 : 0;
//didod[i2].dwTimeStamp = curr_time_msec;
didod[i2].dwSequence = APP_KEYBOARD;
PushQueue(&didod[i2], APP_KEYBOARD/*, curr_time_msec*/);
++i2;
}
#endif
#endif
#ifdef _WIN32
// mouse
if (m_pMouse && m_enableMouseInPlayer)
{
HRESULT hr = m_pMouse->Acquire(); // try to acquire mouse input
if (hr == S_OK || hr == S_FALSE)
{
DIMOUSESTATE2 mouseState;
hr = m_pMouse->GetDeviceState(sizeof(DIMOUSESTATE2), &mouseState);
if ((hr == S_OK || hr == DI_BUFFEROVERFLOW) && (m_hwnd == GetForegroundWindow()))
{
if (g_pplayer->m_throwBalls || g_pplayer->m_ballControl) // debug ball throw functionality
{
if ((mouseState.rgbButtons[0] & 0x80) && !m_leftMouseButtonDown && !m_rightMouseButtonDown && !m_middleMouseButtonDown)
{
POINT curPos;
GetCursorPos(&curPos);
m_mouseX = curPos.x;
m_mouseY = curPos.y;
m_leftMouseButtonDown = true;
}
if (!(mouseState.rgbButtons[0] & 0x80) && m_leftMouseButtonDown && !m_rightMouseButtonDown && !m_middleMouseButtonDown)
{
POINT curPos;
GetCursorPos(&curPos);
m_mouseDX = curPos.x - m_mouseX;
m_mouseDY = curPos.y - m_mouseY;
didod[0].dwData = 1;
PushQueue(didod, APP_MOUSE);
m_leftMouseButtonDown = false;
}
if ((mouseState.rgbButtons[1] & 0x80) && !m_rightMouseButtonDown && !m_leftMouseButtonDown && !m_middleMouseButtonDown)
{
POINT curPos;
GetCursorPos(&curPos);
m_mouseX = curPos.x;
m_mouseY = curPos.y;
m_rightMouseButtonDown = true;
}
if (!(mouseState.rgbButtons[1] & 0x80) && !m_leftMouseButtonDown && m_rightMouseButtonDown && !m_middleMouseButtonDown)
{
POINT curPos;
GetCursorPos(&curPos);
m_mouseDX = curPos.x - m_mouseX;
m_mouseDY = curPos.y - m_mouseY;
didod[0].dwData = 2;
PushQueue(didod, APP_MOUSE);
m_rightMouseButtonDown = false;
}
if ((mouseState.rgbButtons[2] & 0x80) && !m_rightMouseButtonDown && !m_leftMouseButtonDown && !m_middleMouseButtonDown)
{
POINT curPos;
GetCursorPos(&curPos);
m_mouseX = curPos.x;
m_mouseY = curPos.y;
m_middleMouseButtonDown = true;
}
if (!(mouseState.rgbButtons[2] & 0x80) && !m_rightMouseButtonDown && !m_leftMouseButtonDown && m_middleMouseButtonDown)
{
POINT curPos;
GetCursorPos(&curPos);
m_mouseDX = curPos.x - m_mouseX;
m_mouseDY = curPos.y - m_mouseY;
didod[0].dwData = 3;
PushQueue(didod, APP_MOUSE);
m_middleMouseButtonDown = false;
}
if (g_pplayer->m_ballControl && !g_pplayer->m_throwBalls && m_leftMouseButtonDown && !m_rightMouseButtonDown && !m_middleMouseButtonDown)
{
POINT curPos;
GetCursorPos(&curPos);
didod[0].dwData = 4;
m_mouseX = curPos.x;
m_mouseY = curPos.y;
PushQueue(didod, APP_MOUSE);
}
} //if (g_pplayer->m_fThrowBalls)
else
{
for (DWORD i = 0; i < 3; i++)
{
if (m_oldMouseButtonState[i] != mouseState.rgbButtons[i])
{
didod[i].dwData = mouseState.rgbButtons[i];
didod[i].dwOfs = i + 1;
didod[i].dwSequence = APP_MOUSE;
PushQueue(&didod[i], APP_MOUSE);
m_oldMouseButtonState[i] = mouseState.rgbButtons[i];
}
}
}
}
}
}
#endif
// same for joysticks
switch (m_inputApi) {
case 1:
HandleInputXI(didod);
break;
case 2:
HandleInputSDL(didod);
break;
case 3:
HandleInputIGC(didod);
break;
case 0:
default:
HandleInputDI(didod);
break;
}
}
void PinInput::HandleInputDI(DIDEVICEOBJECTDATA *didod)
{
#ifdef _WIN32
for (int k = 0; k < m_num_joy; ++k)
{
#ifdef USE_DINPUT8
const LPDIRECTINPUTDEVICE8 pjoy = m_pJoystick[k];
#else
const LPDIRECTINPUTDEVICE pjoy = m_pJoystick[k];
#endif
if (pjoy)
{
HRESULT hr = pjoy->Acquire(); // try to acquire joystick input
if (hr == S_OK || hr == S_FALSE)
{
DWORD dwElements = INPUT_BUFFER_SIZE;
hr = pjoy->GetDeviceData(sizeof(DIDEVICEOBJECTDATA), didod, &dwElements, 0);
if (hr == S_OK || hr == DI_BUFFEROVERFLOW)
{
if (m_hwnd == GetForegroundWindow())
for (DWORD i = 0; i < dwElements; i++)
PushQueue(&didod[i], APP_JOYSTICK(k)/*, curr_time_msec*/);
}
}
}
}
#endif
}
void PinInput::HandleInputXI(DIDEVICEOBJECTDATA *didod)
{
#ifdef ENABLE_XINPUT
typedef struct {
WORD xi; DWORD di;
} mappingElement;
static constexpr mappingElement mappingTable[] = {
{XINPUT_GAMEPAD_A, DIJOFS_BUTTON0 },
{XINPUT_GAMEPAD_B, DIJOFS_BUTTON1 },
{XINPUT_GAMEPAD_X, DIJOFS_BUTTON2 },
{XINPUT_GAMEPAD_Y, DIJOFS_BUTTON3 },
{XINPUT_GAMEPAD_LEFT_SHOULDER, DIJOFS_BUTTON4 },
{XINPUT_GAMEPAD_RIGHT_SHOULDER, DIJOFS_BUTTON5 },
{XINPUT_GAMEPAD_BACK, DIJOFS_BUTTON6},
{XINPUT_GAMEPAD_START, DIJOFS_BUTTON7},
{XINPUT_GAMEPAD_LEFT_THUMB, DIJOFS_BUTTON8},
{XINPUT_GAMEPAD_RIGHT_THUMB, DIJOFS_BUTTON9},
{XINPUT_GAMEPAD_DPAD_LEFT, DIJOFS_BUTTON10},
{XINPUT_GAMEPAD_DPAD_RIGHT, DIJOFS_BUTTON11},
{XINPUT_GAMEPAD_DPAD_UP, DIJOFS_BUTTON12},
{XINPUT_GAMEPAD_DPAD_DOWN, DIJOFS_BUTTON13},
{0, 0} };
XINPUT_STATE state = {};
unsigned int xie = ERROR_DEVICE_NOT_CONNECTED;
if (m_inputDeviceXI != -2 && (m_inputDeviceXI == -1 || (xie = XInputGetState(m_inputDeviceXI, &state)) != ERROR_SUCCESS)) {
m_inputDeviceXI = -1;
m_num_joy = 0;
for (DWORD i = 0; i < XUSER_MAX_COUNT; i++)
{
ZeroMemory(&state, sizeof(XINPUT_STATE));
if ((xie = XInputGetState(i, &state)) == ERROR_SUCCESS) {
m_inputDeviceXI = i;
m_num_joy = 1;
break;
}
}
}
if (xie == ERROR_DEVICE_NOT_CONNECTED) { // XInputGetState can cause quite some overhead, especially if no devices connected! Thus disable the polling if nothing connected
m_inputDeviceXI = -2;
m_num_joy = 0;
}
if (m_rumbleRunning && m_inputDeviceXI >= 0) {
const DWORD now = timeGetTime();
if (m_rumbleOffTime <= now || m_rumbleOffTime - now > 65535) {
m_rumbleRunning = false;
XINPUT_VIBRATION vibration = {};
XInputSetState(m_inputDeviceXI, &vibration);
}
}
int i = 0;
int j = 0;
while (mappingTable[i].xi != 0) {
if ((m_inputDeviceXIstate.Gamepad.wButtons & mappingTable[i].xi) != (state.Gamepad.wButtons & mappingTable[i].xi)) {
didod[j].dwOfs = mappingTable[i].di;
didod[j].dwData = (state.Gamepad.wButtons & mappingTable[i].xi) > 0 ? 0x80 : 0x00;
PushQueue(&didod[j], APP_JOYSTICK(0));
j++;
}
i++;
}
if (m_inputDeviceXIstate.Gamepad.bLeftTrigger != state.Gamepad.bLeftTrigger) {
didod[j].dwOfs = DIJOFS_Z;
const int value = (int)state.Gamepad.bLeftTrigger * 512;
didod[j].dwData = (DWORD)(value);
PushQueue(&didod[j], APP_JOYSTICK(0));
j++;
}
if (m_inputDeviceXIstate.Gamepad.bRightTrigger != state.Gamepad.bRightTrigger) {
didod[j].dwOfs = DIJOFS_RZ;
const int value = (int)state.Gamepad.bRightTrigger * 512;
didod[j].dwData = (DWORD)(value);
PushQueue(&didod[j], APP_JOYSTICK(0));
j++;
}
if (m_inputDeviceXIstate.Gamepad.sThumbLX != state.Gamepad.sThumbLX) {
didod[j].dwOfs = DIJOFS_X;
const int value = (int)state.Gamepad.sThumbLX * -2;
didod[j].dwData = (DWORD)(value);
PushQueue(&didod[j], APP_JOYSTICK(0));
j++;
}
if (m_inputDeviceXIstate.Gamepad.sThumbLY != state.Gamepad.sThumbLY) {
didod[j].dwOfs = DIJOFS_Y;
const int value = (int)state.Gamepad.sThumbLY * -2;
didod[j].dwData = (DWORD)(value);
PushQueue(&didod[j], APP_JOYSTICK(0));
j++;
}
if (m_inputDeviceXIstate.Gamepad.sThumbRX != state.Gamepad.sThumbRX) {
didod[j].dwOfs = DIJOFS_RX;
const int value = (int)state.Gamepad.sThumbRX * -2;
didod[j].dwData = (DWORD)(value);
PushQueue(&didod[j], APP_JOYSTICK(0));
j++;
}
if (m_inputDeviceXIstate.Gamepad.sThumbRY != state.Gamepad.sThumbRY) {
didod[j].dwOfs = DIJOFS_RY;
const int value = (int)state.Gamepad.sThumbRY * -2;
didod[j].dwData = (DWORD)(value);
PushQueue(&didod[j], APP_JOYSTICK(0));
j++;
}
memcpy(&m_inputDeviceXIstate, &state, sizeof(XINPUT_STATE));
#endif
}
void PinInput::HandleInputSDL(DIDEVICEOBJECTDATA *didod)
{
#ifdef ENABLE_SDL_INPUT
static constexpr DWORD axes[] = { DIJOFS_X, DIJOFS_Y, DIJOFS_RX, DIJOFS_RY, DIJOFS_Z , DIJOFS_RZ };
static constexpr int axisMultiplier[] = { 2, 2, 2, 2, 256 , 256 };
SDL_Event e;
int j = 0;
while (SDL_PollEvent(&e) != 0 && j<32)
{
//User requests quit
switch (e.type) {
case SDL_QUIT:
//Open Exit dialog
break;
#ifndef ENABLE_SDL_GAMECONTROLLER
case SDL_JOYDEVICEADDED:
if (!m_inputDeviceSDL) {
m_inputDeviceSDL = SDL_JoystickOpen(0);
if (m_inputDeviceSDL) {
m_num_joy = 1;
if (SDL_JoystickIsHaptic(m_inputDeviceSDL)) {
m_rumbleDeviceSDL = SDL_HapticOpenFromJoystick(m_inputDeviceSDL);
const int error = SDL_HapticRumbleInit(m_rumbleDeviceSDL);
if (error < 0) {
ShowError(SDL_GetError());
SDL_HapticClose(m_rumbleDeviceSDL);
m_rumbleDeviceSDL = nullptr;
}
}
}
}
break;
case SDL_JOYDEVICEREMOVED:
if (m_rumbleDeviceSDL)
SDL_HapticClose(m_rumbleDeviceSDL);
m_rumbleDeviceSDL = nullptr;
if (m_inputDeviceSDL)
SDL_JoystickClose(m_inputDeviceSDL);
if (SDL_NumJoysticks() > 0) {
m_inputDeviceSDL = SDL_JoystickOpen(0);
if (m_inputDeviceSDL) {
m_num_joy = 1;
if (SDL_JoystickIsHaptic(m_inputDeviceSDL)) {
m_rumbleDeviceSDL = SDL_HapticOpenFromJoystick(m_inputDeviceSDL);
const int error = SDL_HapticRumbleInit(m_rumbleDeviceSDL);
if (error < 0) {
ShowError(SDL_GetError());
SDL_HapticClose(m_rumbleDeviceSDL);
m_rumbleDeviceSDL = nullptr;
}
}
}
}
else {
m_inputDeviceSDL = nullptr;
m_num_joy = 0;
}
break;
case SDL_JOYAXISMOTION:
if (e.jaxis.axis < 6) {
didod[j].dwOfs = axes[e.jaxis.axis];
const int value = e.jaxis.value * axisMultiplier[e.jaxis.axis];
didod[j].dwData = (DWORD)(value);
PushQueue(&didod[j], APP_JOYSTICK(0));
j++;
}
break;
case SDL_JOYBUTTONDOWN:
case SDL_JOYBUTTONUP:
if (e.jbutton.button < 32) {
didod[j].dwOfs = DIJOFS_BUTTON0 + (DWORD)e.jbutton.button;
didod[j].dwData = e.type == SDL_JOYBUTTONDOWN ? 0x80 : 0x00;
PushQueue(&didod[j], APP_JOYSTICK(0));
j++;
}
break;
#else
case SDL_CONTROLLERDEVICEADDED:
case SDL_CONTROLLERDEVICEREMOVED:
SetupSDLGameController();
break;
case SDL_CONTROLLERBUTTONDOWN:
case SDL_CONTROLLERBUTTONUP:
if (e.cbutton.button < 32) {
didod[j].dwOfs = DIJOFS_BUTTON0 + (DWORD)e.cbutton.button;
didod[j].dwData = e.type == SDL_CONTROLLERBUTTONDOWN ? 0x80 : 0x00;
PushQueue(&didod[j], APP_JOYSTICK(0));
j++;
}
break;
#endif
}
}
#endif
}
void PinInput::HandleInputIGC(DIDEVICEOBJECTDATA *didod)
{
#ifdef ENABLE_IGAMECONTROLLER
#endif
}
void PinInput::PlayRumble(const float lowFrequencySpeed, const float highFrequencySpeed, const int ms_duration)
{
if (m_rumbleMode == 0) return;
switch (m_inputApi) {
case 1: //XInput
#ifdef ENABLE_XINPUT
if (m_inputDeviceXI >= 0) {
m_rumbleOffTime = ms_duration + timeGetTime();
m_rumbleRunning = true;
XINPUT_VIBRATION vibration = {};
// On both PS4 and X360:
// The left motor is the low - frequency rumble motor. (explosions, etc)
// The right motor is the high - frequency rumble motor. (subtle stuff)
// The two motors are not the same, and they create different vibration effects.
vibration.wLeftMotorSpeed = (WORD)(saturate(lowFrequencySpeed) * 65535.f);
vibration.wRightMotorSpeed = (WORD)(saturate(highFrequencySpeed) * 65535.f);
XInputSetState(m_inputDeviceXI, &vibration);
}
#endif
break;
case 2: //SDL2
#ifdef ENABLE_SDL_INPUT
#ifndef ENABLE_SDL_GAMECONTROLLER
if (m_rumbleDeviceSDL)
SDL_HapticRumblePlay(m_rumbleDeviceSDL, saturate(max(lowFrequencySpeed, highFrequencySpeed)), ms_duration); //!! meh
#else
if (m_gameController && SDL_GameControllerHasRumble(m_gameController))
SDL_GameControllerRumble(m_gameController, (Uint16)(saturate(lowFrequencySpeed) * 65535.f), (Uint16)(saturate(highFrequencySpeed) * 65535.f), ms_duration);
#endif
#endif
break;
case 3: //IGameController
#ifdef ENABLE_IGAMECONTROLLER
#endif
break;
}
}
void PinInput::Init(const HWND hwnd)
{
m_hwnd = hwnd;
#if defined(ENABLE_SDL_INPUT)
#ifndef ENABLE_SDL_GAMECONTROLLER
SDL_InitSubSystem(SDL_INIT_JOYSTICK);
#else
SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER | SDL_INIT_HAPTIC);
#endif
#endif
#ifdef _WIN32
HRESULT hr;
#ifdef USE_DINPUT8
hr = DirectInput8Create(g_pvp->theInstance, DIRECTINPUT_VERSION, IID_IDirectInput8, (void **)&m_pDI, nullptr);
#else
hr = DirectInputCreate(g_pvp->theInstance, DIRECTINPUT_VERSION, &m_pDI, nullptr);
#endif
#ifdef USE_DINPUT_FOR_KEYBOARD
// Create keyboard device
hr = m_pDI->CreateDevice(GUID_SysKeyboard, &m_pKeyboard, nullptr); //Standard Keyboard device
hr = m_pKeyboard->SetDataFormat(&c_dfDIKeyboard);
hr = m_pKeyboard->SetCooperativeLevel(hwnd, DISCL_NONEXCLUSIVE | DISCL_FOREGROUND); //!! exclusive necessary??
DIPROPDWORD dipdw;
dipdw.diph.dwSize = sizeof(DIPROPDWORD);
dipdw.diph.dwHeaderSize = sizeof(DIPROPHEADER);
dipdw.diph.dwObj = 0;
dipdw.diph.dwHow = DIPH_DEVICE;
dipdw.dwData = INPUT_BUFFER_SIZE;
hr = m_pKeyboard->SetProperty(DIPROP_BUFFERSIZE, &dipdw.diph);
#endif
if (m_enableMouseInPlayer)
{
// Create mouse device
if (!FAILED(m_pDI->CreateDevice(GUID_SysMouse, &m_pMouse, nullptr)))
{
hr = m_pMouse->SetDataFormat(&c_dfDIMouse2);
hr = m_pMouse->SetCooperativeLevel(hwnd, DISCL_NONEXCLUSIVE | DISCL_FOREGROUND);
DIPROPDWORD dipdwm;
dipdwm.diph.dwSize = sizeof(DIPROPDWORD);
dipdwm.diph.dwHeaderSize = sizeof(DIPROPHEADER);
dipdwm.diph.dwObj = 0;
dipdwm.diph.dwHow = DIPH_DEVICE;
dipdwm.dwData = INPUT_BUFFER_SIZE;
hr = m_pMouse->SetProperty(DIPROP_BUFFERSIZE, &dipdwm.diph);
}
else
m_pMouse = nullptr;
}
/* Disable Sticky Keys */
// get the current state
m_startupStickyKeys.cbSize = sizeof(STICKYKEYS);
SystemParametersInfo(SPI_GETSTICKYKEYS, sizeof(STICKYKEYS), &m_startupStickyKeys, 0);
// turn it all OFF
STICKYKEYS newStickyKeys = {};
newStickyKeys.cbSize = sizeof(STICKYKEYS);
newStickyKeys.dwFlags = 0;
SystemParametersInfo(SPI_SETSTICKYKEYS, sizeof(STICKYKEYS), &newStickyKeys, SPIF_SENDCHANGE);
#endif
for (int i = 0; i < eCKeys; i++)
m_keyPressedState[i] = false;
m_nextKeyPressedTime = 0;
uShockType = 0;
m_inputApi = g_pvp->m_settings.LoadValueWithDefault(Settings::Player, "InputApi"s, 0);
switch (m_inputApi) {
case 1: //xInput
#ifdef ENABLE_XINPUT
m_inputDeviceXI = -1;
uShockType = USHOCKTYPE_GENERIC;
m_rumbleRunning = false;
#else
m_inputApi = 0;
#endif
break;
case 2: //SDL2
#ifdef ENABLE_SDL_INPUT
#ifndef ENABLE_SDL_GAMECONTROLLER
m_inputDeviceSDL = SDL_JoystickOpen(0);
if (m_inputDeviceSDL) {
m_num_joy = 1;
if (SDL_JoystickIsHaptic(m_inputDeviceSDL)) {
m_rumbleDeviceSDL = SDL_HapticOpenFromJoystick(m_inputDeviceSDL);
int error = SDL_HapticRumbleInit(m_rumbleDeviceSDL);
if (error < 0) {
ShowError(SDL_GetError());
SDL_HapticClose(m_rumbleDeviceSDL);
m_rumbleDeviceSDL = nullptr;
}
}
}
uShockType = USHOCKTYPE_GENERIC;
#else
SetupSDLGameController();
#endif
#else
m_inputApi = 0;
#endif
break;
case 3: //iGameController
#ifdef ENABLE_IGAMECONTROLLER
#else
m_inputApi = 0;
#endif
break;
default:
m_inputApi = 0;
break;
}
m_rumbleMode = (m_inputApi > 0) ? g_pvp->m_settings.LoadValueWithDefault(Settings::Player, "RumbleMode"s, 3) : 0;
#ifdef _WIN32
if (m_inputApi == 0) {
#ifdef USE_DINPUT8
m_pDI->EnumDevices(DI8DEVCLASS_GAMECTRL, EnumJoystickCallbackDI, this, DIEDFL_ATTACHEDONLY); //enum Joysticks
#else
m_pDI->EnumDevices(DIDEVTYPE_JOYSTICK, EnumJoystickCallbackDI, this, DIEDFL_ATTACHEDONLY); //enum Joysticks
#endif
}
#endif
m_mixerKeyDown = false;
m_mixerKeyUp = false;
}