aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx/Input/GTK3/GTK3MappingHelper.cs
blob: 1035e415398de181001fa1ff73a8fa241ec0b1e0 (plain) (blame)
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
using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using GtkKey = Gdk.Key;

namespace Ryujinx.Input.GTK3
{
    public static class GTK3MappingHelper
    {
        private static readonly GtkKey[] _keyMapping = new GtkKey[(int)Key.Count]
        {
            // NOTE: invalid
            GtkKey.blank,

            GtkKey.Shift_L,
            GtkKey.Shift_R,
            GtkKey.Control_L,
            GtkKey.Control_R,
            GtkKey.Alt_L,
            GtkKey.Alt_R,
            GtkKey.Super_L,
            GtkKey.Super_R,
            GtkKey.Menu,
            GtkKey.F1,
            GtkKey.F2,
            GtkKey.F3,
            GtkKey.F4,
            GtkKey.F5,
            GtkKey.F6,
            GtkKey.F7,
            GtkKey.F8,
            GtkKey.F9,
            GtkKey.F10,
            GtkKey.F11,
            GtkKey.F12,
            GtkKey.F13,
            GtkKey.F14,
            GtkKey.F15,
            GtkKey.F16,
            GtkKey.F17,
            GtkKey.F18,
            GtkKey.F19,
            GtkKey.F20,
            GtkKey.F21,
            GtkKey.F22,
            GtkKey.F23,
            GtkKey.F24,
            GtkKey.F25,
            GtkKey.F26,
            GtkKey.F27,
            GtkKey.F28,
            GtkKey.F29,
            GtkKey.F30,
            GtkKey.F31,
            GtkKey.F32,
            GtkKey.F33,
            GtkKey.F34,
            GtkKey.F35,
            GtkKey.Up,
            GtkKey.Down,
            GtkKey.Left,
            GtkKey.Right,
            GtkKey.Return,
            GtkKey.Escape,
            GtkKey.space,
            GtkKey.Tab,
            GtkKey.BackSpace,
            GtkKey.Insert,
            GtkKey.Delete,
            GtkKey.Page_Up,
            GtkKey.Page_Down,
            GtkKey.Home,
            GtkKey.End,
            GtkKey.Caps_Lock,
            GtkKey.Scroll_Lock,
            GtkKey.Print,
            GtkKey.Pause,
            GtkKey.Num_Lock,
            GtkKey.Clear,
            GtkKey.KP_0,
            GtkKey.KP_1,
            GtkKey.KP_2,
            GtkKey.KP_3,
            GtkKey.KP_4,
            GtkKey.KP_5,
            GtkKey.KP_6,
            GtkKey.KP_7,
            GtkKey.KP_8,
            GtkKey.KP_9,
            GtkKey.KP_Divide,
            GtkKey.KP_Multiply,
            GtkKey.KP_Subtract,
            GtkKey.KP_Add,
            GtkKey.KP_Decimal,
            GtkKey.KP_Enter,
            GtkKey.a,
            GtkKey.b,
            GtkKey.c,
            GtkKey.d,
            GtkKey.e,
            GtkKey.f,
            GtkKey.g,
            GtkKey.h,
            GtkKey.i,
            GtkKey.j,
            GtkKey.k,
            GtkKey.l,
            GtkKey.m,
            GtkKey.n,
            GtkKey.o,
            GtkKey.p,
            GtkKey.q,
            GtkKey.r,
            GtkKey.s,
            GtkKey.t,
            GtkKey.u,
            GtkKey.v,
            GtkKey.w,
            GtkKey.x,
            GtkKey.y,
            GtkKey.z,
            GtkKey.Key_0,
            GtkKey.Key_1,
            GtkKey.Key_2,
            GtkKey.Key_3,
            GtkKey.Key_4,
            GtkKey.Key_5,
            GtkKey.Key_6,
            GtkKey.Key_7,
            GtkKey.Key_8,
            GtkKey.Key_9,
            GtkKey.grave,
            GtkKey.grave,
            GtkKey.minus,
            GtkKey.plus,
            GtkKey.bracketleft,
            GtkKey.bracketright,
            GtkKey.semicolon,
            GtkKey.quoteright,
            GtkKey.comma,
            GtkKey.period,
            GtkKey.slash,
            GtkKey.backslash,

            // NOTE: invalid
            GtkKey.blank,
        };

        private static readonly Dictionary<GtkKey, Key> _gtkKeyMapping;

        static GTK3MappingHelper()
        {
            var inputKeys = Enum.GetValues<Key>();

            // GtkKey is not contiguous and quite large, so use a dictionary instead of an array.
            _gtkKeyMapping = new Dictionary<GtkKey, Key>();

            foreach (var key in inputKeys)
            {
                try
                {
                    var index = ToGtkKey((Key)key);
                    _gtkKeyMapping[index] = (Key)key;
                }
                catch
                {
                    // Skip invalid mappings.
                }
            }
        }

        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public static GtkKey ToGtkKey(Key key)
        {
            return _keyMapping[(int)key];
        }

        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public static Key ToInputKey(GtkKey key)
        {
            return _gtkKeyMapping.GetValueOrDefault(key, Key.Unknown);
        }
    }
}