-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathCCInputUtils.cs
More file actions
167 lines (152 loc) · 3 KB
/
CCInputUtils.cs
File metadata and controls
167 lines (152 loc) · 3 KB
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
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.18449
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
using System;
using UnityEngine;
namespace CameraTools
{
public class CCInputUtils
{
public static string GetInputString()
{
//keyCodes
string[] names = System.Enum.GetNames(typeof(KeyCode));
int numberOfKeycodes = names.Length;
for(int i = 0; i < numberOfKeycodes; i++)
{
string output = names[i];
if(output.Contains("Keypad"))
{
output = "["+output.Substring(6).ToLower()+"]";
}
else if(output.Contains("Alpha"))
{
output = output.Substring(5);
}
else //lower case key
{
output = output.ToLower();
}
//modifiers
if(output.Contains("control"))
{
output = output.Split('c')[0] + " ctrl";
}
else if(output.Contains("alt"))
{
output = output.Split('a')[0] + " alt";
}
else if(output.Contains("shift"))
{
output = output.Split ('s')[0] + " shift";
}
else if(output.Contains("command"))
{
output = output.Split('c')[0]+" cmd";
}
//special keys
else if(output == "backslash")
{
output = @"\";
}
else if(output == "backquote")
{
output = "`";
}
else if(output == "[period]")
{
output = "[.]";
}
else if(output == "[plus]")
{
output = "[+]";
}
else if(output == "[multiply]")
{
output = "[*]";
}
else if(output == "[divide]")
{
output = "[/]";
}
else if(output == "[minus]")
{
output = "[-]";
}
else if(output == "[enter]")
{
output = "enter";
}
else if(output.Contains("page"))
{
output = output.Insert(4, " ");
}
else if(output.Contains("arrow"))
{
output = output.Split('a')[0];
}
else if(output == "capslock")
{
output = "caps lock";
}
else if(output == "minus")
{
output = "-";
}
//test if input is valid
try
{
if(Input.GetKey(output))
{
return output;
}
}
catch(System.Exception)
{
}
}
//mouse
for(int m = 0; m < 6; m++)
{
string inputString = "mouse "+m;
try
{
if(Input.GetKey(inputString))
{
return inputString;
}
}
catch(UnityException)
{
Debug.Log ("Invalid mouse: "+inputString);
}
}
//joysticks
for(int j = 1; j < 12; j++)
{
for(int b = 0; b<20; b++)
{
string inputString = "joystick "+j+" button "+b;
try
{
if(Input.GetKey(inputString))
{
return inputString;
}
}
catch(UnityException)
{
return string.Empty;
}
}
}
return string.Empty;
}
}
}