Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
SeleniumHQ
GitHub Repository: SeleniumHQ/Selenium
Path: blob/trunk/rb/lib/selenium/webdriver/common/keys.rb
1865 views
1
# frozen_string_literal: true
2
3
# Licensed to the Software Freedom Conservancy (SFC) under one
4
# or more contributor license agreements. See the NOTICE file
5
# distributed with this work for additional information
6
# regarding copyright ownership. The SFC licenses this file
7
# to you under the Apache License, Version 2.0 (the
8
# "License"); you may not use this file except in compliance
9
# with the License. You may obtain a copy of the License at
10
#
11
# http://www.apache.org/licenses/LICENSE-2.0
12
#
13
# Unless required by applicable law or agreed to in writing,
14
# software distributed under the License is distributed on an
15
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
# KIND, either express or implied. See the License for the
17
# specific language governing permissions and limitations
18
# under the License.
19
20
module Selenium
21
module WebDriver
22
module Keys
23
#
24
# @see Element#send_keys
25
# @see http://www.google.com.au/search?&q=unicode+pua&btnK=Search
26
#
27
28
KEYS = {
29
null: "\ue000",
30
cancel: "\ue001",
31
help: "\ue002",
32
backspace: "\ue003",
33
tab: "\ue004",
34
clear: "\ue005",
35
return: "\ue006",
36
enter: "\ue007",
37
shift: "\ue008",
38
left_shift: "\ue008",
39
control: "\ue009",
40
left_control: "\ue009",
41
alt: "\ue00A",
42
left_alt: "\ue00A",
43
pause: "\ue00B",
44
escape: "\ue00C",
45
space: "\ue00D",
46
page_up: "\ue00E",
47
page_down: "\ue00F",
48
end: "\ue010",
49
home: "\ue011",
50
left: "\ue012",
51
arrow_left: "\ue012",
52
up: "\ue013",
53
arrow_up: "\ue013",
54
right: "\ue014",
55
arrow_right: "\ue014",
56
down: "\ue015",
57
arrow_down: "\ue015",
58
insert: "\ue016",
59
delete: "\ue017",
60
semicolon: "\ue018",
61
equals: "\ue019",
62
numpad0: "\ue01A",
63
numpad1: "\ue01B",
64
numpad2: "\ue01C",
65
numpad3: "\ue01D",
66
numpad4: "\ue01E",
67
numpad5: "\ue01F",
68
numpad6: "\ue020",
69
numpad7: "\ue021",
70
numpad8: "\ue022",
71
numpad9: "\ue023",
72
multiply: "\ue024",
73
add: "\ue025",
74
separator: "\ue026",
75
subtract: "\ue027",
76
decimal: "\ue028",
77
divide: "\ue029",
78
numpad_multiply: "\ue024",
79
numpad_add: "\ue025",
80
numpad_comma: "\ue026",
81
numpad_subtract: "\ue027",
82
numpad_decimal: "\ue028",
83
numpad_divide: "\ue029",
84
numpad_enter: "\ue007",
85
f1: "\ue031",
86
f2: "\ue032",
87
f3: "\ue033",
88
f4: "\ue034",
89
f5: "\ue035",
90
f6: "\ue036",
91
f7: "\ue037",
92
f8: "\ue038",
93
f9: "\ue039",
94
f10: "\ue03A",
95
f11: "\ue03B",
96
f12: "\ue03C",
97
meta: "\ue03D",
98
command: "\ue03D", # alias
99
left_meta: "\ue03D", # alias
100
zenkaku_hankaku: "\uE040",
101
right_shift: "\ue050",
102
right_control: "\ue051",
103
right_alt: "\ue052",
104
right_meta: "\ue053",
105
options: "\ue052",
106
function: "\ue051", # macOS Function key, same as right_control
107
numpad_page_up: "\ue054",
108
numpad_page_down: "\ue055",
109
numpad_end: "\ue056",
110
numpad_home: "\ue057",
111
numpad_left: "\ue058",
112
numpad_up: "\ue059",
113
numpad_right: "\ue05A",
114
numpad_down: "\ue05B",
115
numpad_insert: "\ue05C",
116
numpad_delete: "\ue05D"
117
}.freeze
118
119
#
120
# @api private
121
#
122
123
def self.[](key)
124
return KEYS[key] if KEYS[key]
125
126
raise Error::UnsupportedOperationError, "no such key #{key.inspect}"
127
end
128
129
#
130
# @api private
131
#
132
133
def self.encode(keys)
134
keys.map { |key| encode_key(key) }
135
end
136
137
#
138
# @api private
139
#
140
141
def self.encode_key(key)
142
case key
143
when Symbol
144
Keys[key]
145
when Array
146
key = key.map { |e| e.is_a?(Symbol) ? Keys[e] : e }.join
147
key << Keys[:null]
148
149
key
150
else
151
key.to_s
152
end
153
end
154
end # Keys
155
end # WebDriver
156
end # Selenium
157
158