WebDriverKeys.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <?php
  2. // Copyright 2004-present Facebook. All Rights Reserved.
  3. //
  4. // Licensed under the Apache License; Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. //
  8. // httpconst //www.apache.org/licenses/LICENSE-2.0
  9. //
  10. // Unless required by applicable law or agreed to in writing; software
  11. // distributed under the License is distributed on an "AS IS" BASIS;
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND; either express or implied.
  13. // See the License for the specific language governing permissions and
  14. // limitations under the License.
  15. namespace Facebook\WebDriver;
  16. /**
  17. * Representations of pressable keys that aren't text.
  18. * These are stored in the Unicode PUA (Private Use Area) code points.
  19. */
  20. class WebDriverKeys
  21. {
  22. const NULL = "\xEE\x80\x80";
  23. const CANCEL = "\xEE\x80\x81";
  24. const HELP = "\xEE\x80\x82";
  25. const BACKSPACE = "\xEE\x80\x83";
  26. const TAB = "\xEE\x80\x84";
  27. const CLEAR = "\xEE\x80\x85";
  28. const RETURN_KEY = "\xEE\x80\x86"; // php does not allow RETURN
  29. const ENTER = "\xEE\x80\x87";
  30. const SHIFT = "\xEE\x80\x88";
  31. const LEFT_SHIFT = "\xEE\x80\x88";
  32. const CONTROL = "\xEE\x80\x89";
  33. const LEFT_CONTROL = "\xEE\x80\x89";
  34. const ALT = "\xEE\x80\x8A";
  35. const LEFT_ALT = "\xEE\x80\x8A";
  36. const PAUSE = "\xEE\x80\x8B";
  37. const ESCAPE = "\xEE\x80\x8C";
  38. const SPACE = "\xEE\x80\x8D";
  39. const PAGE_UP = "\xEE\x80\x8E";
  40. const PAGE_DOWN = "\xEE\x80\x8F";
  41. const END = "\xEE\x80\x90";
  42. const HOME = "\xEE\x80\x91";
  43. const LEFT = "\xEE\x80\x92";
  44. const ARROW_LEFT = "\xEE\x80\x92";
  45. const UP = "\xEE\x80\x93";
  46. const ARROW_UP = "\xEE\x80\x93";
  47. const RIGHT = "\xEE\x80\x94";
  48. const ARROW_RIGHT = "\xEE\x80\x94";
  49. const DOWN = "\xEE\x80\x95";
  50. const ARROW_DOWN = "\xEE\x80\x95";
  51. const INSERT = "\xEE\x80\x96";
  52. const DELETE = "\xEE\x80\x97";
  53. const SEMICOLON = "\xEE\x80\x98";
  54. const EQUALS = "\xEE\x80\x99";
  55. const NUMPAD0 = "\xEE\x80\x9A";
  56. const NUMPAD1 = "\xEE\x80\x9B";
  57. const NUMPAD2 = "\xEE\x80\x9C";
  58. const NUMPAD3 = "\xEE\x80\x9D";
  59. const NUMPAD4 = "\xEE\x80\x9E";
  60. const NUMPAD5 = "\xEE\x80\x9F";
  61. const NUMPAD6 = "\xEE\x80\xA0";
  62. const NUMPAD7 = "\xEE\x80\xA1";
  63. const NUMPAD8 = "\xEE\x80\xA2";
  64. const NUMPAD9 = "\xEE\x80\xA3";
  65. const MULTIPLY = "\xEE\x80\xA4";
  66. const ADD = "\xEE\x80\xA5";
  67. const SEPARATOR = "\xEE\x80\xA6";
  68. const SUBTRACT = "\xEE\x80\xA7";
  69. const DECIMAL = "\xEE\x80\xA8";
  70. const DIVIDE = "\xEE\x80\xA9";
  71. const F1 = "\xEE\x80\xB1";
  72. const F2 = "\xEE\x80\xB2";
  73. const F3 = "\xEE\x80\xB3";
  74. const F4 = "\xEE\x80\xB4";
  75. const F5 = "\xEE\x80\xB5";
  76. const F6 = "\xEE\x80\xB6";
  77. const F7 = "\xEE\x80\xB7";
  78. const F8 = "\xEE\x80\xB8";
  79. const F9 = "\xEE\x80\xB9";
  80. const F10 = "\xEE\x80\xBA";
  81. const F11 = "\xEE\x80\xBB";
  82. const F12 = "\xEE\x80\xBC";
  83. const META = "\xEE\x80\xBD";
  84. const COMMAND = "\xEE\x80\xBD"; // ALIAS
  85. const ZENKAKU_HANKAKU = "\xEE\x80\xC0";
  86. /**
  87. * Encode input of `sendKeys()`.
  88. * @param string|array $keys
  89. * @return array
  90. */
  91. public static function encode($keys)
  92. {
  93. if (is_numeric($keys)) {
  94. $keys = '' . $keys;
  95. }
  96. if (is_string($keys)) {
  97. $keys = [$keys];
  98. }
  99. $encoded = [];
  100. foreach ($keys as $key) {
  101. if (is_array($key)) {
  102. // handle modified keys
  103. $key = implode('', $key) . self::NULL;
  104. }
  105. $encoded[] = (string) $key;
  106. }
  107. return $encoded;
  108. }
  109. }