Path: blob/trunk/rb/lib/selenium/webdriver/common/keys.rb
1865 views
# frozen_string_literal: true12# Licensed to the Software Freedom Conservancy (SFC) under one3# or more contributor license agreements. See the NOTICE file4# distributed with this work for additional information5# regarding copyright ownership. The SFC licenses this file6# to you under the Apache License, Version 2.0 (the7# "License"); you may not use this file except in compliance8# with the License. You may obtain a copy of the License at9#10# http://www.apache.org/licenses/LICENSE-2.011#12# Unless required by applicable law or agreed to in writing,13# software distributed under the License is distributed on an14# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY15# KIND, either express or implied. See the License for the16# specific language governing permissions and limitations17# under the License.1819module Selenium20module WebDriver21module Keys22#23# @see Element#send_keys24# @see http://www.google.com.au/search?&q=unicode+pua&btnK=Search25#2627KEYS = {28null: "\ue000",29cancel: "\ue001",30help: "\ue002",31backspace: "\ue003",32tab: "\ue004",33clear: "\ue005",34return: "\ue006",35enter: "\ue007",36shift: "\ue008",37left_shift: "\ue008",38control: "\ue009",39left_control: "\ue009",40alt: "\ue00A",41left_alt: "\ue00A",42pause: "\ue00B",43escape: "\ue00C",44space: "\ue00D",45page_up: "\ue00E",46page_down: "\ue00F",47end: "\ue010",48home: "\ue011",49left: "\ue012",50arrow_left: "\ue012",51up: "\ue013",52arrow_up: "\ue013",53right: "\ue014",54arrow_right: "\ue014",55down: "\ue015",56arrow_down: "\ue015",57insert: "\ue016",58delete: "\ue017",59semicolon: "\ue018",60equals: "\ue019",61numpad0: "\ue01A",62numpad1: "\ue01B",63numpad2: "\ue01C",64numpad3: "\ue01D",65numpad4: "\ue01E",66numpad5: "\ue01F",67numpad6: "\ue020",68numpad7: "\ue021",69numpad8: "\ue022",70numpad9: "\ue023",71multiply: "\ue024",72add: "\ue025",73separator: "\ue026",74subtract: "\ue027",75decimal: "\ue028",76divide: "\ue029",77numpad_multiply: "\ue024",78numpad_add: "\ue025",79numpad_comma: "\ue026",80numpad_subtract: "\ue027",81numpad_decimal: "\ue028",82numpad_divide: "\ue029",83numpad_enter: "\ue007",84f1: "\ue031",85f2: "\ue032",86f3: "\ue033",87f4: "\ue034",88f5: "\ue035",89f6: "\ue036",90f7: "\ue037",91f8: "\ue038",92f9: "\ue039",93f10: "\ue03A",94f11: "\ue03B",95f12: "\ue03C",96meta: "\ue03D",97command: "\ue03D", # alias98left_meta: "\ue03D", # alias99zenkaku_hankaku: "\uE040",100right_shift: "\ue050",101right_control: "\ue051",102right_alt: "\ue052",103right_meta: "\ue053",104options: "\ue052",105function: "\ue051", # macOS Function key, same as right_control106numpad_page_up: "\ue054",107numpad_page_down: "\ue055",108numpad_end: "\ue056",109numpad_home: "\ue057",110numpad_left: "\ue058",111numpad_up: "\ue059",112numpad_right: "\ue05A",113numpad_down: "\ue05B",114numpad_insert: "\ue05C",115numpad_delete: "\ue05D"116}.freeze117118#119# @api private120#121122def self.[](key)123return KEYS[key] if KEYS[key]124125raise Error::UnsupportedOperationError, "no such key #{key.inspect}"126end127128#129# @api private130#131132def self.encode(keys)133keys.map { |key| encode_key(key) }134end135136#137# @api private138#139140def self.encode_key(key)141case key142when Symbol143Keys[key]144when Array145key = key.map { |e| e.is_a?(Symbol) ? Keys[e] : e }.join146key << Keys[:null]147148key149else150key.to_s151end152end153end # Keys154end # WebDriver155end # Selenium156157158