OSDN Git Service

ff824ae3d4b8dfffbc2a681d0e0eece014484fa9
[psychlops/silverlight.git] / dev5 / psychlops / core / device / hid.cs
1 using System;\r
2 using System.Windows;\r
3 using System.Windows.Controls;\r
4 using System.Windows.Documents;\r
5 using System.Windows.Input;\r
6 \r
7 \r
8 namespace Psychlops\r
9 {\r
10         public class HID\r
11         {\r
12                 public struct Button\r
13                 {\r
14                         private static object locker;\r
15                         static Button()\r
16                         {\r
17                                 locker = new object(); \r
18                         }\r
19                         private bool pushed_, released_, pressed_;\r
20                         public void down()\r
21                         {\r
22                                 lock (locker)\r
23                                 {\r
24                                         pushed_ = true;\r
25                                         pressed_ = true;\r
26                                 }\r
27                         }\r
28                         public void up()\r
29                         {\r
30                                 lock (locker)\r
31                                 {\r
32                                         released_ = true;\r
33                                         pressed_ = false;\r
34                                 }\r
35                         }\r
36                         public bool pushed() { lock (locker) { bool tmp = pushed_; pushed_ = false; return tmp; } }\r
37                         public bool released() { lock (locker) { bool tmp = released_; released_ = false; return tmp; } }\r
38                         public bool pressed() { return pressed_; }\r
39                 }\r
40         }\r
41 \r
42 \r
43         public static class Mouse\r
44         {\r
45                 static internal Point position_;\r
46                 static internal System.Windows.UIElement _prime;\r
47                 static public HID.Button left, right, middle;\r
48                 static internal Point wheelDelta_;\r
49 \r
50                 static public Point position { get { return position_; } }\r
51                 static public int x { get { return (int)position_.x; } }\r
52                 static public int y { get { return (int)position_.y; } }\r
53                 static public Point wheelDelta { get { return wheelDelta_; } }\r
54 \r
55                 static public void show() { }\r
56                 static public void hide() { }\r
57 \r
58                 static public void Canvas_MousePos(object sender, MouseEventArgs e)\r
59                 {\r
60                         System.Windows.Point p = e.GetPosition(_prime);\r
61                         position_.set(p.X, p.Y);\r
62                 }\r
63                 static public void Canvas_LDown(object sender, MouseEventArgs e)\r
64                 {\r
65                         left.down();\r
66                         System.Windows.Point p = e.GetPosition(_prime);\r
67                         position_.set(p.X, p.Y);\r
68                 }\r
69                 static public void Canvas_LUp(object sender, MouseEventArgs e)\r
70                 {\r
71                         left.up();\r
72                         System.Windows.Point p = e.GetPosition(_prime);\r
73                         position_.set(p.X, p.Y);\r
74                 }\r
75                 static public void Canvas_MouseWheel(object sender, MouseWheelEventArgs e)\r
76                 {\r
77                         wheelDelta_.y += e.Delta;\r
78                         System.Windows.Point p = e.GetPosition(_prime);\r
79                         position_.set(p.X, p.Y);\r
80                 }\r
81         }\r
82 \r
83 \r
84         public static class Keyboard\r
85         {\r
86                 public class IKey\r
87                 {\r
88                         //internal static HID.Button[] states;\r
89                         //int p;\r
90                         internal HID.Button state;\r
91                         public void down() { state.down(); }\r
92                         public void up() { state.up(); }\r
93                         public bool pushed() { return state.pushed(); }\r
94                         public bool released() { return state.released(); }\r
95                         public bool pressed() { return state.pressed(); }\r
96                 }\r
97                 static public IKey\r
98                         alt, shift, ctrl,\r
99                         esc, spc, rtn,\r
100                         left, right, up, down,\r
101                         tab,\r
102                         comma, period,\r
103                         q, w, e, r, t, y, u, i, o, p,\r
104                         a, s, d, f, g, h, j, k, l,\r
105                         z, x, c, v, b, n, m,\r
106                         one, two, three, four, five, six, seven, eight, nine, zero,\r
107                         pad0, pad1, pad2, pad3, pad4, pad5, pad6, pad7, pad8, pad9;\r
108                 static private System.Collections.Generic.Dictionary<System.Windows.Input.Key, IKey> map;\r
109                 static public void Canvas_KeyUp(object sender, KeyEventArgs e)\r
110                 {\r
111                         if (map.ContainsKey(e.Key)) map[e.Key].up();\r
112                 }\r
113                 static public void Canvas_KeyDown(object sender, KeyEventArgs e)\r
114                 {\r
115                         if (map.ContainsKey(e.Key)) map[e.Key].down();\r
116                 }\r
117 \r
118 \r
119                 static Keyboard()\r
120                 {\r
121                         /*\r
122                         esc = new Key(0); spc = new Key(1); rtn = new Key(2);\r
123                         left = new Key(3); right = new Key(4); up = new Key(5); down = new Key(6);\r
124                         comma = new Key(7); period = new Key(8);\r
125                         q = new Key(32); w = new Key(33); e = new Key(34); r = new Key(35); t = new Key(36); y = new Key(37); u = new Key(38); i = new Key(39); o = new Key(40); p = new Key(41);\r
126                         a = new Key(42); s = new Key(43); d = new Key(44); f = new Key(45); g = new Key(46); h = new Key(47); j = new Key(48); k = new Key(49); l = new Key(50);\r
127                         z = new Key(51); x = new Key(52); c = new Key(53); v = new Key(54); b = new Key(55); n = new Key(56); m = new Key(57);\r
128                         one = new Key(80); two = new Key(81); three = new Key(82); four = new Key(83); five = new Key(84); six = new Key(85); seven = new Key(86); eight = new Key(87); nine = new Key(88); zero = new Key(96);\r
129                         pad0 = new Key(96); pad1 = new Key(97); pad2 = new Key(98); pad3 = new Key(99); pad4 = new Key(100); pad5 = new Key(101); pad6 = new Key(102); pad7 = new Key(103); pad8 = new Key(104); pad9 = new Key(105);\r
130                         */\r
131                         alt = new IKey(); shift = new IKey(); ctrl = new IKey();\r
132                         esc = new IKey(); spc = new IKey(); rtn = new IKey();\r
133                         left = new IKey(); right = new IKey(); up = new IKey(); down = new IKey();\r
134                         comma = new IKey(); period = new IKey();\r
135                         q = new IKey(); w = new IKey(); e = new IKey(); r = new IKey(); t = new IKey(); y = new IKey(); u = new IKey(); i = new IKey(); o = new IKey(); p = new IKey();\r
136                         a = new IKey(); s = new IKey(); d = new IKey(); f = new IKey(); g = new IKey(); h = new IKey(); j = new IKey(); k = new IKey(); l = new IKey();\r
137                         z = new IKey(); x = new IKey(); c = new IKey(); v = new IKey(); b = new IKey(); n = new IKey(); m = new IKey();\r
138                         one = new IKey(); two = new IKey(); three = new IKey(); four = new IKey(); five = new IKey(); six = new IKey(); seven = new IKey(); eight = new IKey(); nine = new IKey(); zero = new IKey();\r
139                         pad0 = new IKey(); pad1 = new IKey(); pad2 = new IKey(); pad3 = new IKey(); pad4 = new IKey(); pad5 = new IKey(); pad6 = new IKey(); pad7 = new IKey(); pad8 = new IKey(); pad9 = new IKey();\r
140 \r
141                         map = new System.Collections.Generic.Dictionary<System.Windows.Input.Key, IKey>();\r
142                         map.Add(Key.Alt, alt); map.Add(Key.Shift, shift); map.Add(Key.Ctrl, ctrl);\r
143                         map.Add(Key.Escape, esc); map.Add(Key.Space, spc); map.Add(Key.Enter, rtn);\r
144                         map.Add(Key.Left, left); map.Add(Key.Right, right); map.Add(Key.Up, up); map.Add(Key.Down, down);\r
145                         map.Add(Key.Tab, tab);\r
146                         map.Add(Key.PageDown, comma); map.Add(Key.PageUp, period);\r
147                         map.Add(Key.Q, q); map.Add(Key.W, w); map.Add(Key.E, e); map.Add(Key.R, r); map.Add(Key.T, t); map.Add(Key.Y, y); map.Add(Key.U, u); map.Add(Key.I, i); map.Add(Key.O, o); map.Add(Key.P, p);\r
148                         map.Add(Key.A, a); map.Add(Key.S, s); map.Add(Key.D, d); map.Add(Key.F, f); map.Add(Key.G, g); map.Add(Key.H, h); map.Add(Key.J, j); map.Add(Key.K, k); map.Add(Key.L, l);\r
149                         map.Add(Key.Z, z); map.Add(Key.X, x); map.Add(Key.C, c); map.Add(Key.V, v); map.Add(Key.B, b); map.Add(Key.N, n); map.Add(Key.M, m);\r
150                         map.Add(Key.D1, one); map.Add(Key.D2, two); map.Add(Key.D3, three); map.Add(Key.D4, four); map.Add(Key.D5, five); map.Add(Key.D6, six); map.Add(Key.D7, seven); map.Add(Key.D8, eight); map.Add(Key.D9, nine); map.Add(Key.D0, zero);\r
151                         map.Add(Key.NumPad0, pad0); map.Add(Key.NumPad1, pad1); map.Add(Key.NumPad2, pad2); map.Add(Key.NumPad3, pad3); map.Add(Key.NumPad4, pad4); map.Add(Key.NumPad5, pad5); map.Add(Key.NumPad6, pad6); map.Add(Key.NumPad7, pad7); map.Add(Key.NumPad8, pad8); map.Add(Key.NumPad9, pad9);\r
152                 }\r
153         }\r
154 \r
155 }