-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRS_Input.rb
1915 lines (1741 loc) · 59.4 KB
/
RS_Input.rb
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
#================================================================
# The MIT License
# Copyright (c) 2020 biud436
# ---------------------------------------------------------------
# Free for commercial and non commercial use.
#================================================================
#===============================================================================
# Name : RS_Input
# Author : biud436
# Version : v1.0.24 (2024.12.31)
# Link : https://blog.naver.com/biud436/220289463681
# Description : This script provides the extension keycode and easy to use.
#-------------------------------------------------------------------------------
# Version Log
#-------------------------------------------------------------------------------
# v1.0.0 (2018.10.29) - First Release.
# v1.0.1 (2018.10.29) :
# - Fixed the bug that causes an error when clicking the right button of the mouse.
# - Added the TouchInput feature that is the same as RPG Maker MV.
# - Fixed the issue that did not play the cursor sound when selecting the button using mouse
# v1.0.2 (2018.11.11)
# - Added the feature such as a path finding in RPG Maker MV
# - Added the destination sprite such as RPG Maker MV
# v1.0.3 (2019.01.20) :
# - Added the feature that can use the mouse wheel in the Save and Load scenes.
# v1.0.4 (2019.01.21) :
# - In the selectable window, Added the feature that can use the mouse wheel.
# v1.0.5 (2019.02.02) :
# - Added feature that can use the mouse left button in the Window_DebugRight
# v1.0.6 (2019.03.25) :
# - Added the repeat? method into Input class.
# v1.0.7 (2019.11.13) :
# - 마우스 왼쪽 클릭으로 비행선을 탑승할 수 없었던 문제를 수정하였습니다.
# - 목적지 스프라이트를 화면에서 감출 수 있는 기능을 추가하였습니다.
# - 비행선 탑승 후, 마우스 자동 이동 시 한 칸만 움직이고 멈추는 현상을 수정하였습니다.
# - TouchInput.update를 추가하였습니다.
# v1.0.8 (2020.01.29) :
# - 자동 이동 설정을 변경할 수 있습니다.
# v1.0.9 (2020.02.14) :
# - DLL 파일에 한글 조합 기능을 추가하였습니다.
# v1.0.10 (2020.03.04) :
# - 스킬 목록에서 인덱스 계산이 잘못되는 문제를 수정하였습니다.
# v1.0.11 (2020.05.01) :
# - 마우스의 아이콘의 인덱스를 바꿀 수 있습니다.
# v1.0.12 (2022.01.06) :
# - Windows 11에서 Mouse Wheel이 동작하지 않는 문제가 있어 SafeWin32API 모듈 도입
# v1.0.24 (2024.12.31) :
# 이동 가능한 타일인데 마우스를 올려놓으면, 이동 불가능한 타일로 표시되는 문제를 수정하였습니다.
#-------------------------------------------------------------------------------
# 사용법 / How to use
#-------------------------------------------------------------------------------
# To use this code called 'p', You can output the string to the console for debug.
# These functions are checking whether certain key is pressed.
#
# You can use the key name as string type.
# for example, the virtual keycode of the letter named 'a' returns 65.
#
# p"]" if Input.press?("]")
# p"[" if Input.press?("[")
# p";" if Input.press?(";")
# p'"' if Input.press?('"')
# p">" if Input.press?(">")
# p"<" if Input.press?("<")
# p"?" if Input.press?("?")
# p"\\" if Input.press?("\\")
# p"-" if Input.press?("-")
# p"+" if Input.press?("+")
# p"~" if Input.press?("~")
#
# You can also use the virtual keycode to parameter 1.
# The keycode value called 221 is the same as the letter called ']'
# p"]" if Input.trigger?(221)
#
# in case of used the symbol, you can use like as at the following code!
# You can see that, the symbol starts with the colon(:)
#
# p"backspace" if Input.press?(:VK_BACK)
#
# if you need to change the mouse icon,
# You will gonna insert a new note tag in the event editor, as follows.
#
# <MOUSE_OVER : X>
#
# The 'X' is an index value into the icon set.
#
#-------------------------------------------------------------------------------
# API / Funcions :
#-------------------------------------------------------------------------------
# Please available virtual key codes refer to the line 164 (a.k.a KEY CONSTANT)
#
# Input.trigger?(Symbol)
# Input.repeat?(Symbol)
# Input.release?(Symbol)
# Input.press?(Symbol)
# Input.trigger?(String)
# Input.repeat?(String)
# Input.release?(String)
# Input.press?(String)
# Input.mouse_trigger?(0)
# Input.mouse_trigger?(1)
# Input.mouse_trigger?(2)
# Input.mouse_release?(0)
# Input.mouse_release?(1)
# Input.mouse_release?(2)
# Input.mouse_press?(0)
# Input.mouse_press?(1)
# Input.mouse_press?(2)
# Input.mouse_x
# Input.mouse_y
# TouchInput.x
# TouchInput.y
# TouchInput.z
# TouchInput.wheel
# TouchInput.trigger?(:LEFT)
# TouchInput.trigger?(:RIGHT)
# TouchInput.trigger?(:MIDDLE)
# TouchInput.press?(:LEFT)
# TouchInput.press?(:RIGHT)
# TouchInput.press?(:MIDDLE)
# TouchInput.release?(:LEFT)
# TouchInput.release?(:RIGHT)
# TouchInput.release?(:MIDDLE)
# TouchInput.show_mouse_cursor
# TouchInput.hide_mouse_cursor
#
#===============================================================================
$imported = {} if $imported.nil?
$imported["RS_Input"] = true
module RS; end
#===============================================================================
# 설정 / Config
#===============================================================================
module RS::Input
Config = {
# 마우스 커서 아이콘
# 커서 아이콘은 기본적으로 스킬이나 아이템,
# 무기구 장비의 아이콘 세트 파일의 아이콘과 같습니다.
# 아이콘 세트 파일의 위치는 Graphics/System/IconSet.png이고,
# 크기는 24 x 24 픽셀이고 인덱스 값은 0부터 시작합니다.
# 아이콘을 표시하고 싶지 않다면 0이라고 적어주십시오.
:CURSOR_ICON => 397,
# 기본 마우스 커서를 표시하려면 true, 감추려면 false
:SHOW_MOUSE_CURSOR => false,
# 패스 파인딩 알고리즘 최적화 설정
# 목표 지점까지의 최단 경로 계산 시, 이동 불가 지역을 피해가게 됩니다.
# 시작 지점부터 목표 지점까지의 이동 비용이 최적화 값보다 커지게 되면,
# 알고리즘을 즉각 끝내고 지금까지 계산된 경로를 반환합니다.
:SEARCH_LIMIT => 12,
# 자동 이동 설정
# 마우스로 특정 지역을 클릭했을 때 플레이어가 자동으로 타겟까지
# 자동 이동하게 하려면 true,
# 특정 지역으로 이동하지 않게 하려면 false
:USE_AUTOMOVEMENT => true,
# 목적지 표시 스프라이트 표시
# 표시하려면 true, 감추려면 false
:SHOW_DESTINATION => true,
# 목적지 표시 그래픽의 뷰포트 설정
# 1로 설정하면 타일맵, 원경, 캐릭터들과 동일한 뷰포트를 사용합니다.
# 2로 설정하면 그림, 타이머, 날씨 효과 등과 동일한 뷰포트를 사용합니다.
# 3으로 설정하면 화면 밝기 뷰포트와 동일한 뷰포트를 사용합니다.
# 4로 설정하면 윈도우와 동일한 뷰포트를 사용합니다.
:DESTINATION_VIEWPORT => 1,
# 목적지 표시 그래픽의 Z좌표 설정
# 스프라이트 생성 시 동일한 뷰포트로 설정될 수 있습니다.
# 이때 Z좌표 설정으로 같은 뷰포트 내에서도 우선 순위를 나눌 수 있습니다.
# 뷰포트를 1로 설정했다면,
# 캐릭터 스프라이트의 Z좌표는 각 0, 100, 200이 되므로,
# 이 값을 500 정도로 설정해야 머리 위에 뜨게 됩니다.
# 50 정도로 설정하면 캐릭터가 목적지 표시 스프라이트를 밟게 됩니다.
:DESTINATION_Z => 500,
# 목적지 표시 그래픽 - 기본 색상 (기본색 : 흰색)
:DESTINATION_NORMAL_COLOR => Color.new(255,255,255,255),
# 목적지 표시 그래픽 - 이동 중일 때 색상 (기본색 : 빨강)
:DESTINATION_MOVING_FORWARD_COLOR => Color.new(255,0,0,255),
# 목적지 표시 그래픽 - 이동 불가 지형 색상 (기본색 : 빨강)
:DESTINATION_UNABLE_PASSABLE_TILE_COLOR => Color.new(255,0,0,255),
# 목적지 표시 그래픽 - 줌 이펙트 속도
:DESTINATION_ZOOM_EFFECT_SPEED => 10,
# 지정한 프레임까지 대기
:KEY_REPEAT_WAIT => 24,
# 지정한 프레임이 지나면 키를 다시 체크
:KEY_REPEAT_INTERVAL => 6,
}
end
#===============================================================================
# 유니코드 모듈 / Unicode module
#===============================================================================
if not defined?(Unicode)
module Unicode
MultiByteToWideChar = Win32API.new('Kernel32','MultiByteToWideChar','llpipi','i')
WideCharToMultiByte = Win32API.new('Kernel32','WideCharToMultiByte','llpipipp','i')
UTF_8 = 65001
def unicode!
buf = "\0" * (self.size * 2 + 1)
MultiByteToWideChar.call(UTF_8, 0, self, -1, buf, buf.size)
buf
end
def unicode_s
buf = "\0" * (self.size * 2 + 1)
WideCharToMultiByte.call(UTF_8, 0, self, -1, buf, buf.size, nil, nil)
buf.delete("\0")
end
end
class String
include Unicode
end
module INI
WritePrivateProfileStringW = Win32API.new('Kernel32','WritePrivateProfileStringW','pppp','s')
GetPrivateProfileStringW = Win32API.new('Kernel32','GetPrivateProfileStringW','ppppip','s')
extend self
def write_string(app,key,str,file_name)
path = ".\\" + file_name
(param = [app,key.to_s,str.to_s,path]).collect! {|i| i.unicode!}
success = WritePrivateProfileStringW.call(*param)
end
def read_string(app_name,key_name,file_name)
buf = "\0" * 256
path = ".\\" + file_name
(param = [app_name,key_name,path]).collect! {|x| x.unicode!}
GetPrivateProfileStringW.call(param[0], param[1],0,buf,256,param[2])
buf.unicode_s.unpack('U*').pack('U*')
end
end
class Hash
def to_ini(file_name="Default.ini",app_name="Default")
self.each { |k, v| INI.write_string(app_name,k.to_s.dup,v.to_s.dup,file_name) }
end
end
end
#===============================================================================
# Buffer classes
#===============================================================================
class InputBuffer
attr_accessor :old
attr_accessor :current
attr_accessor :map
def initialize(size)
@old = ""
@current = "\0" * size
end
end
class MouseBuffer < InputBuffer
attr_accessor :point
def initialize(size)
super(size)
@map = Array.new(8, 0)
@point = Rect.new
end
def left_button=(val)
@current[0] = val
end
def right_button=(val)
@current[1] = val
end
def middle_button=(val)
@current[2] = val
end
end
#===============================================================================
# SafeWin32API (Windows 11)
#===============================================================================
module SafeWin32API
DATA = {
"v" => nil,
'l' => 0,
'p' => ""
}
class << self
def bind(*args)
# Windows 11에서 Mouse Wheel이 동작하지 않는 문제가 있어 도입하였습니다.
temp_api = Win32API.new(*args) rescue Proc.new { DATA[args[3]] rescue 0 }
temp_api
end
end
end
#===============================================================================
# Input moudle
#===============================================================================
module Input
FindWindowW = Win32API.new('user32.dll', 'FindWindowW', 'pp', 'l')
GetKeyboardState = Win32API.new('User32.dll', 'GetKeyboardState', 'p', 's')
GetCursorPos = Win32API.new('user32.dll', 'GetCursorPos', 'p', 's')
ScreenToClient = Win32API.new('user32.dll', 'ScreenToClient', 'lp', 's')
GetAsyncKeyState = Win32API.new('user32.dll', 'GetAsyncKeyState', 'i', 'i')
GetKeyNameTextW = Win32API.new('user32.dll', 'GetKeyNameText', 'lpi', 'i')
MapVirtualKey = Win32API.new('user32.dll', 'MapVirtualKey', 'll', 'l')
RSGetWheelDelta = SafeWin32API.bind('RS-InputCore.dll', 'RSGetWheelDelta', 'v', 'l')
RSResetWheelDelta = SafeWin32API.bind('RS-InputCore.dll', 'RSResetWheelDelta', 'v', 'v')
GetText = SafeWin32API.bind('RS-InputCore.dll', 'get_text', 'v', 'p')
MAPVK_VSC_TO_VK_EX = 3
# Read the game title from ./Game.ini path and then set the window handle
WINDOW_NAME = INI.read_string('Game', 'Title', 'Game.ini')
HANDLE = FindWindowW.call('RGSS Player'.unicode!, WINDOW_NAME.unicode!)
# keyboard input buffer
@@keyboard = InputBuffer.new(256)
# mouse input buffer;
@@mouse = MouseBuffer.new(8)
# Available virtual keys for Windows OS;
# a-z or A-Z letters are not here.
KEY = {
:VK_LBUTTON=> 0x01,
:VK_RBUTTON=> 0x02,
:VK_CANCEL=> 0x03,
:VK_MBUTTON=> 0x04,
:VK_XBUTTON1=> 0x05,
:VK_XBUTTON2=> 0x06,
:VK_BACK=> 0x08, # 백스페이스
:VK_TAB=> 0x09, # 탭
:VK_CLEAR=> 0x0C, # NumLock이 해제되었을 때의 5
:VK_RETURN=> 0x0D, # Enter
:VK_SHIFT=> 0x10, # Shift
:VK_CONTROL=> 0x11, # Ctrl
:VK_MENU=> 0x12, # Alt
:VK_PAUSE=> 0x13, # Pause
:VK_CAPITAL=> 0x14, # Caps Lock
:VK_KANA=> 0x15,
:VK_HANGEUL=> 0x15,
:VK_HANGUL=> 0x15, # 한/영 변환
:VK_JUNJA=> 0x17,
:VK_FINAL=> 0x18,
:VK_HANJA=> 0x19, # 한자
:VK_KANJI=> 0x19,
:VK_ESCAPE=> 0x1B, # Esc
:VK_CONVERT=> 0x1C,
:VK_NONCONVERT=> 0x1D,
:VK_ACCEPT=> 0x1E,
:VK_MODECHANGE=> 0x1F,
:VK_SPACE=> 0x20,
:VK_PRIOR=> 0x21, # PgUp
:VK_NEXT=> 0x22, # PgDn
:VK_END=> 0x23, # End
:VK_HOME=> 0x24, # Home
:VK_LEFT=> 0x25, #
:VK_UP=> 0x26,
:VK_RIGHT=> 0x27,
:VK_DOWN=> 0x28,
:VK_SELECT=> 0x29,
:VK_PRINT=> 0x2A,
:VK_EXECUTE=> 0x2B,
:VK_SNAPSHOT=> 0x2C, # Print Screen
:VK_INSERT=> 0x2D, # Insert
:VK_DELETE=> 0x2E, # Delete
:VK_HELP=> 0x2F,
:VK_LWIN=> 0x5B, # 왼쪽 윈도우 키
:VK_RWIN=> 0x5C, # 오른쪽 윈도우 키
:VK_APPS=> 0x5D,
:VK_SLEEP=> 0x5F,
:VK_NUMPAD0=> 0x60, # 숫자 패드 0 ~ 9
:VK_NUMPAD1=> 0x61,
:VK_NUMPAD2=> 0x62,
:VK_NUMPAD3=> 0x63,
:VK_NUMPAD4=> 0x64,
:VK_NUMPAD5=> 0x65,
:VK_NUMPAD6=> 0x66,
:VK_NUMPAD7=> 0x67,
:VK_NUMPAD8=> 0x68,
:VK_NUMPAD9=> 0x69,
:VK_MULTIPLY=> 0x6A, # 숫자 패드 *
:VK_ADD=> 0x6B, # 숫자 패드 +
:VK_SEPARATOR=> 0x6C,
:VK_SUBTRACT=> 0x6D, # 숫자 패드 -
:VK_DECIMAL=> 0x6E, # 숫자 패드 .
:VK_DIVIDE=> 0x6F, # 숫자 패드 /
:VK_F1=> 0x70,
:VK_F2=> 0x71,
:VK_F3=> 0x72,
:VK_F4=> 0x73,
:VK_F5=> 0x74,
:VK_F6=> 0x75,
:VK_F7=> 0x76,
:VK_F8=> 0x77,
:VK_F9=> 0x78,
:VK_F10=> 0x79,
:VK_F11=> 0x7A,
:VK_F12=> 0x7B,
:VK_F13=> 0x7C,
:VK_F14=> 0x7D,
:VK_F15=> 0x7E,
:VK_F16=> 0x7F,
:VK_F17=> 0x80,
:VK_F18=> 0x81,
:VK_F19=> 0x82,
:VK_F20=> 0x83,
:VK_F21=> 0x84,
:VK_F22=> 0x85,
:VK_F23=> 0x86,
:VK_F24=> 0x87,
:VK_NUMLOCK=> 0x90, # Num Lock
:VK_SCROLL=> 0x91, # Scroll Lock
:VK_OEM_NEC_EQUAL=> 0x92,
:VK_OEM_FJ_JISHO=> 0x92,
:VK_OEM_FJ_MASSHOU=>0x93,
:VK_OEM_FJ_TOUROKU=>0x94,
:VK_OEM_FJ_LOYA=> 0x95,
:VK_OEM_FJ_ROYA=> 0x96,
:VK_LSHIFT=> 0xA0,
:VK_RSHIFT=> 0xA1,
:VK_LCONTROL=> 0xA2,
:VK_RCONTROL=> 0xA3,
:VK_LMENU=> 0xA4,
:VK_RMENU=> 0xA5,
:VK_BROWSER_BACK=> 0xA6,
:VK_BROWSER_FORWARD=> 0xA7,
:VK_BROWSER_REFRESH=> 0xA8,
:VK_BROWSER_STOP=> 0xA9,
:VK_BROWSER_SEARCH=> 0xAA,
:VK_BROWSER_FAVORITES=> 0xAB,
:VK_BROWSER_HOME=> 0xAC,
:VK_VOLUME_MUTE=> 0xAD,
:VK_VOLUME_DOWN=> 0xAE,
:VK_VOLUME_UP=> 0xAF,
:VK_MEDIA_NEXT_TRACK=> 0xB0,
:VK_MEDIA_PREV_TRACK=> 0xB1,
:VK_MEDIA_STOP=> 0xB2,
:VK_MEDIA_PLAY_PAUSE=> 0xB3,
:VK_LAUNCH_MAIL=> 0xB4,
:VK_LAUNCH_MEDIA_SELECT=> 0xB5,
:VK_LAUNCH_APP1=> 0xB6,
:VK_LAUNCH_APP2=> 0xB7,
:VK_OEM_1=> 0xBA,
:VK_OEM_PLUS=> 0xBB,
:VK_OEM_COMMA=> 0xBC,
:VK_OEM_MINUS=> 0xBD,
:VK_OEM_PERIOD=> 0xBE,
:VK_OEM_2=> 0xBF,
:VK_OEM_3=> 0xC0, # `
:VK_OEM_4=> 0xDB,
:VK_OEM_5=> 0xDC,
:VK_OEM_6=> 0xDD,
:VK_OEM_7=> 0xDE,
:VK_OEM_8=> 0xDF,
:VK_OEM_AX=> 0xE1,
:VK_OEM_102=> 0xE2,
:VK_ICO_HELP=> 0xE3,
:VK_ICO_00=> 0xE4,
:VK_PROCESSKEY=> 0xE5,
:VK_ICO_CLEAR=> 0xE6,
:VK_PACKET=> 0xE7,
:VK_OEM_RESET=> 0xE9,
:VK_OEM_JUMP=> 0xEA,
:VK_OEM_PA1=> 0xEB,
:VK_OEM_PA2=> 0xEC,
:VK_OEM_PA3=> 0xED,
:VK_OEM_WSCTRL=> 0xEE,
:VK_OEM_CUSEL=> 0xEF,
:VK_OEM_ATTN=> 0xF0,
:VK_OEM_FINISH=> 0xF1,
:VK_OEM_COPY=> 0xF2,
:VK_OEM_AUTO=> 0xF3,
:VK_OEM_ENLW=> 0xF4,
:VK_OEM_BACKTAB=> 0xF5,
:VK_ATTN=> 0xF6,
:VK_CRSEL=> 0xF7,
:VK_EXSEL=> 0xF8,
:VK_EREOF=> 0xF9,
:VK_PLAY=> 0xFA,
:VK_ZOOM=> 0xFB,
:VK_NONAME=> 0xFC,
:VK_PA1=> 0xFD,
:VK_OEM_CLEAR=> 0xFE,
# 상단 숫자 키
:VK_KEY_0 => 0x30,
:VK_KEY_1 => 0x31,
:VK_KEY_2 => 0x32,
:VK_KEY_3 => 0x33,
:VK_KEY_4 => 0x34,
:VK_KEY_5 => 0x35,
:VK_KEY_6 => 0x36,
:VK_KEY_7 => 0x37,
:VK_KEY_8 => 0x38,
:VK_KEY_9 => 0x39,
}
# 기본 심볼
DEFEAULT_SYM = [
:DOWN,
:LEFT,
:RIGHT,
:UP,
:F5,
:F6,
:F7,
:F8,
:F9,
:SHIFT,
:CTRL,
:ALT,
:A,
:B,
:C,
:X,
:Y,
:Z,
:L,
:R
]
# 기호 키
SPECIFIC_KEY = {
"~" => 192,
"`" => 192,
"[" => 219,
"{" => 219,
"}" => 221,
"]" => 221,
";" => 186,
":" => 186,
'"' => 222,
"'" => 222,
"<" => 188,
"," => 188,
">" => 190,
"," => 188,
"?" => 191,
"/" => 191,
"-" => 189,
"_" => 189,
"+" => 187,
"=" => 187
}
# 키 상태
STATES = {
:NONE => 0,
:DOWN => 1,
:UP => 2,
:PRESS => 3
}
MOUSE_BUTTON = {
:LEFT => 0,
:RIGHT => 1,
:MIDDLE => 2
}
@@test = {}
@@pressed_time = 0
@@triggered = false
@@mouse_pressed = false
@@wheel = 0
# repeat settings
@@repeat_type = {
:latest_button => 0,
:pressed_time => 0,
:key_repeat_wait => RS::Input::Config[:KEY_REPEAT_WAIT],
:key_repeat_interval => RS::Input::Config[:KEY_REPEAT_INTERVAL]
}
class << self
alias rs_input_update update
def update(*args, &block)
rs_input_update(*args, &block)
update_keyboard
update_mouse
end
# 가상키 획득
def get_virutal_key(keyname)
vk_key = SPECIFIC_KEY[keyname]
vk_key
end
# 키코드 획득
def get_keycode(keyname)
keycode = 0
if keyname.is_a?(String)
keycode = keyname.ord if keycode == 0
return keycode if (65..90).include?(keycode) # if it is an upper case
return keycode if (97..122).include?(keycode) # it it is a lower case
keycode = get_virutal_key(keyname)
return keycode if not keycode.nil?
elsif keyname.is_a?(Integer)
keycode = keyname
return keycode
elsif keyname.is_a?(Symbol)
keycode = KEY[keyname]
return (keycode.nil?) ? 0 : keycode
end
keycode = 0
return keycode
end
# 트리거인가?
alias rs_input_trigger? trigger?
def trigger?(*args, &block)
keycode = get_keycode(args[0])
key_status = @@keyboard.map[keycode]
latest_button = @@repeat_type[:latest_button]
pressed_time = @@repeat_type[:pressed_time]
if latest_button == 0
return false
end
if (latest_button == keycode and pressed_time == 0)
return true
end
if key_status and key_status == STATES[:DOWN]
return true
end
return rs_input_trigger?(*args, &block)
end
def mouse_trigger?(*args, &block)
index = args[0].is_a?(Symbol) ? MOUSE_BUTTON[args[0]] : args[0]
return @@triggered > 0|| @@mouse.map[index] == STATES[:DOWN]
end
def mouse_press?(*args, &block)
index = args[0].is_a?(Symbol) ? MOUSE_BUTTON[args[0]] : args[0]
return @@mouse_pressed || @@mouse.map[index] == STATES[:PRESS]
end
def mouse_long_press?(*args, &block)
@@pressed_time >= 24 && mouse_press?(*args, &block)
end
def mouse_release?(*args, &block)
index = args[0].is_a?(Symbol) ? MOUSE_BUTTON[args[0]] : args[0]
return @@mouse.map[index] == STATES[:UP]
end
alias rs_input_press? press?
def press?(*args, &block)
keycode = get_keycode(args[0])
key_status = @@keyboard.map[keycode]
if key_status and key_status == STATES[:PRESS]
return true
end
return rs_input_press?(*args, &block)
end
def release?(*args, &block)
keycode = get_keycode(args[0])
key_status = @@keyboard.map[keycode]
if key_status and key_status == STATES[:UP]
return true
end
end
alias rs_input_repeat? repeat?
def repeat?(*args, &block)
if DEFEAULT_SYM.include?(args[0])
return rs_input_repeat?(*args, &block)
end
keycode = get_keycode(args[0])
latest_button = @@repeat_type[:latest_button]
pressed_time = @@repeat_type[:pressed_time]
key_repeat_wait = @@repeat_type[:key_repeat_wait]
key_repeat_interval = @@repeat_type[:key_repeat_interval]
if latest_button == 0
return false
end
if latest_button == keycode
if pressed_time == 0
return true
end
if (pressed_time >= key_repeat_wait)
if ((pressed_time % key_repeat_interval) == 0)
return true
end
end
end
return false
end
def update_keyboard
@@keyboard.old = @@keyboard.current.dup
@@keyboard.current = "\0" * 256
@@keyboard.map = Array.new(256, 0)
GetKeyboardState.call(@@keyboard.current)
@@keyboard.current = @@keyboard.current.unpack('c*')
# repeat
if (@@keyboard.current[@@repeat_type[:latest_button]] & 0x80) > 0
@@repeat_type[:pressed_time] += 1
else
@@repeat_type[:latest_button] = 0
end
# update map
for i in (0...256)
@@keyboard.current[i] = ((@@keyboard.current[i] & 0x80) > 0) ? 1 : 0
old = @@keyboard.old[i]
cur = @@keyboard.current[i]
if old == 0 and cur == 1
@@keyboard.map[i] = STATES[:DOWN]
@@repeat_type[:latest_button] = i
@@repeat_type[:pressed_time] = 0
elsif old == 1 and cur == 1
@@keyboard.map[i] = STATES[:PRESS]
elsif old == 1 and cur == 0
@@keyboard.map[i] = STATES[:UP]
else
@@keyboard.map[i] = STATES[:NONE]
end
end
end
def get_async_key_state(symbol)
return 0 if not [:VK_LBUTTON, :VK_RBUTTON, :VK_MBUTTON].include?(symbol)
return ((GetAsyncKeyState.call(KEY[symbol]) & 0x8000) != 0) ? 1 : 0
end
def update_mouse
@@mouse.old = @@mouse.current.dup
@@mouse.current = Array.new(8, 0)
@@mouse.map = Array.new(8, 0)
@@mouse.left_button = self.get_async_key_state(:VK_LBUTTON)
@@mouse.right_button = self.get_async_key_state(:VK_RBUTTON)
@@mouse.middle_button = self.get_async_key_state(:VK_MBUTTON)
@@triggered = @@mouse.map[MOUSE_BUTTON[:LEFT]] if @@mouse.map
for i in (0...8)
old = @@mouse.old[i]
cur = @@mouse.current[i]
if old == 0 and cur == 1
@@mouse.map[i] = STATES[:DOWN]
@@mouse_pressed = true
@@pressed_time = 0
elsif old == 1 and cur == 1
@@mouse.map[i] = STATES[:PRESS]
elsif old == 1 and cur == 0
@@mouse.map[i] = STATES[:UP]
@@mouse_pressed = false
end
end
update_mouse_point
if mouse_trigger?(:LEFT)
@@pressed_time += 1
end
@@wheel = RSGetWheelDelta.call
clear_wheel
end
def update_mouse_point
pt = [0, 0].pack('l2')
GetCursorPos.call(pt)
ScreenToClient.call(HANDLE, pt)
lpt = pt.unpack('l2')
@@mouse.point.x = lpt[0]
@@mouse.point.y = lpt[1]
end
def mouse_x
@@mouse.point.x rescue 0
end
def mouse_y
@@mouse.point.y rescue 0
end
def mouse_wheel
@@wheel
end
def clear_wheel
RSResetWheelDelta.call
end
def char
str = $input_char || ""
/([a-zA-Z가-힣ㄱ-ㅎ\.\?\!\@\#\$\%\^\&\*\(\)\-\=\_\+\/\*0-9\~\`\{\}])/i =~ str
return $1.to_s
end
end
end
#===============================================================================
# TouchInput moudle
#===============================================================================
module TouchInput
ShowCursor = Win32API.new("user32", "ShowCursor", "i", "i" )
ShowCursor.call(RS::Input::Config[:SHOW_MOUSE_CURSOR] ? 1 : 0)
class << self
def press?(*args, &block)
Input.mouse_press?(*args, &block)
end
def long_press?(*args, &block)
Input.mouse_long_press?(*args, &block)
end
def trigger?(*args, &block)
Input.mouse_trigger?(*args, &block)
end
def release?(*args, &block); Input.mouse_release?(*args, &block); end
def down?(key); Input.mouse_press?(key); end
def up?(key); Input.mouse_release?(key); end
def x
Input.mouse_x
end
def y
Input.mouse_y
end
def z
Input.mouse_wheel
end
def wheel
Input.mouse_wheel
end
def get_pos
[x, y]
end
def show_mouse_cursor
ShowCursor.call(1)
end
def hide_mouse_cursor
ShowCursor.call(0)
end
def update
Input.update_mouse
end
end
end
#===============================================================================
# Window_Selectable
#===============================================================================
class Window_Selectable < Window_Base
alias xrx1s_update update
def update
xrx1s_update
process_wheel
process_touch
end
def process_cursor_move
return unless cursor_movable?
last_index = @index
cursor_down (Input.trigger?(:DOWN)) if Input.repeat?(:DOWN)
cursor_up (Input.trigger?(:UP)) if Input.repeat?(:UP)
cursor_right(Input.trigger?(:RIGHT)) if Input.repeat?(:RIGHT)
cursor_left (Input.trigger?(:LEFT)) if Input.repeat?(:LEFT)
cursor_pagedown if !handle?(:pagedown) && Input.trigger?(:R)
cursor_pageup if !handle?(:pageup) && Input.trigger?(:L)
Sound.play_cursor if @index != last_index
end
def process_touch
return unless open? and active
mx = TouchInput.x
my = TouchInput.y
_self = self
sy = [[((my - self.y) / item_height), 0].max, item_max - 1].min
sx = [[((mx - self.x) / item_width), 0].max, item_max - 1].min
idx = [ [(sy * col_max) + sx, 0].max, item_max - 1].min
item_max.times do |i|
temp_rect = self.item_rect(i)
check_area?(temp_rect) do
last_index = self.index
self.index = idx
Sound.play_cursor if self.index != last_index
end
end
if TouchInput.trigger?(:LEFT)
rect = self.item_rect(idx)
check_area?(rect) { process_ok if ok_enabled? }
end
if TouchInput.trigger?(:RIGHT)
rect = self.item_rect(idx)
process_cancel if cancel_enabled?
end
end
def check_area?(rect)
mx = TouchInput.x
my = TouchInput.y
tx = self.x
ty = self.y
if (mx - tx) >= rect.x && (mx - tx) <= rect.x + rect.width &&
(my - ty) >= rect.y && (my - ty) <= rect.y + rect.height
yield
end
end
def process_wheel
if open? and active
if TouchInput.wheel > 0
scroll_up
elsif TouchInput.wheel < 0
scroll_down
end
end
end
def max_rows
[(item_max / col_max).ceil, 1].max
end
def scroll_down
if top_row + 1 < max_rows
self.top_row = top_row + 1
end
end
def scroll_up
if top_row > 0
self.top_row = top_row - 1
end
end
end
#===============================================================================
# Window_Message
#===============================================================================
class Window_Message < Window_Base
def cancelled?
Input.trigger?(:B) || TouchInput.trigger?(:RIGHT)
end
def triggered?
Input.trigger?(:C) || TouchInput.trigger?(:LEFT)
end
def update_show_fast
@show_fast = true if cancelled?
end
def input_pause
self.pause = true
wait(10)
Fiber.yield until triggered?
Input.update
self.pause = false
end
end
#===============================================================================
# Window_DebugRight
#===============================================================================
class Window_DebugRight < Window_Selectable
#--------------------------------------------------------------------------
# * Update During Switch Mode
#--------------------------------------------------------------------------
def update_switch_mode
if Input.trigger?(:C) or TouchInput.trigger?(:LEFT)
Sound.play_ok
$game_switches[current_id] = !$game_switches[current_id]
redraw_current_item
end
end
end
#===============================================================================
# TouchInput::Cursor
#===============================================================================
module TouchInput::Cursor
def create_cursor(index)
@cursor = Sprite.new
@cursor.x, @cursor.y = TouchInput.get_pos
@cursor.bitmap = Bitmap.new(24, 24)
@contents = @cursor.bitmap
draw_icon(index, 0, 0, true)