keys.go 22 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037
  1. // Copyright 2013 The Ebitengine Authors
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. // Code generated by genkeys.go using 'go generate'. DO NOT EDIT.
  15. package ebiten
  16. import (
  17. "fmt"
  18. "strings"
  19. "github.com/hajimehoshi/ebiten/v2/internal/ui"
  20. )
  21. // A Key represents a keyboard key.
  22. // These keys represent physical keys of US keyboard.
  23. // For example, KeyQ represents Q key on US keyboards and ' (quote) key on Dvorak keyboards.
  24. type Key int
  25. // Keys.
  26. const (
  27. KeyA Key = Key(ui.KeyA)
  28. KeyB Key = Key(ui.KeyB)
  29. KeyC Key = Key(ui.KeyC)
  30. KeyD Key = Key(ui.KeyD)
  31. KeyE Key = Key(ui.KeyE)
  32. KeyF Key = Key(ui.KeyF)
  33. KeyG Key = Key(ui.KeyG)
  34. KeyH Key = Key(ui.KeyH)
  35. KeyI Key = Key(ui.KeyI)
  36. KeyJ Key = Key(ui.KeyJ)
  37. KeyK Key = Key(ui.KeyK)
  38. KeyL Key = Key(ui.KeyL)
  39. KeyM Key = Key(ui.KeyM)
  40. KeyN Key = Key(ui.KeyN)
  41. KeyO Key = Key(ui.KeyO)
  42. KeyP Key = Key(ui.KeyP)
  43. KeyQ Key = Key(ui.KeyQ)
  44. KeyR Key = Key(ui.KeyR)
  45. KeyS Key = Key(ui.KeyS)
  46. KeyT Key = Key(ui.KeyT)
  47. KeyU Key = Key(ui.KeyU)
  48. KeyV Key = Key(ui.KeyV)
  49. KeyW Key = Key(ui.KeyW)
  50. KeyX Key = Key(ui.KeyX)
  51. KeyY Key = Key(ui.KeyY)
  52. KeyZ Key = Key(ui.KeyZ)
  53. KeyAltLeft Key = Key(ui.KeyAltLeft)
  54. KeyAltRight Key = Key(ui.KeyAltRight)
  55. KeyArrowDown Key = Key(ui.KeyArrowDown)
  56. KeyArrowLeft Key = Key(ui.KeyArrowLeft)
  57. KeyArrowRight Key = Key(ui.KeyArrowRight)
  58. KeyArrowUp Key = Key(ui.KeyArrowUp)
  59. KeyBackquote Key = Key(ui.KeyBackquote)
  60. KeyBackslash Key = Key(ui.KeyBackslash)
  61. KeyBackspace Key = Key(ui.KeyBackspace)
  62. KeyBracketLeft Key = Key(ui.KeyBracketLeft)
  63. KeyBracketRight Key = Key(ui.KeyBracketRight)
  64. KeyCapsLock Key = Key(ui.KeyCapsLock)
  65. KeyComma Key = Key(ui.KeyComma)
  66. KeyContextMenu Key = Key(ui.KeyContextMenu)
  67. KeyControlLeft Key = Key(ui.KeyControlLeft)
  68. KeyControlRight Key = Key(ui.KeyControlRight)
  69. KeyDelete Key = Key(ui.KeyDelete)
  70. KeyDigit0 Key = Key(ui.KeyDigit0)
  71. KeyDigit1 Key = Key(ui.KeyDigit1)
  72. KeyDigit2 Key = Key(ui.KeyDigit2)
  73. KeyDigit3 Key = Key(ui.KeyDigit3)
  74. KeyDigit4 Key = Key(ui.KeyDigit4)
  75. KeyDigit5 Key = Key(ui.KeyDigit5)
  76. KeyDigit6 Key = Key(ui.KeyDigit6)
  77. KeyDigit7 Key = Key(ui.KeyDigit7)
  78. KeyDigit8 Key = Key(ui.KeyDigit8)
  79. KeyDigit9 Key = Key(ui.KeyDigit9)
  80. KeyEnd Key = Key(ui.KeyEnd)
  81. KeyEnter Key = Key(ui.KeyEnter)
  82. KeyEqual Key = Key(ui.KeyEqual)
  83. KeyEscape Key = Key(ui.KeyEscape)
  84. KeyF1 Key = Key(ui.KeyF1)
  85. KeyF2 Key = Key(ui.KeyF2)
  86. KeyF3 Key = Key(ui.KeyF3)
  87. KeyF4 Key = Key(ui.KeyF4)
  88. KeyF5 Key = Key(ui.KeyF5)
  89. KeyF6 Key = Key(ui.KeyF6)
  90. KeyF7 Key = Key(ui.KeyF7)
  91. KeyF8 Key = Key(ui.KeyF8)
  92. KeyF9 Key = Key(ui.KeyF9)
  93. KeyF10 Key = Key(ui.KeyF10)
  94. KeyF11 Key = Key(ui.KeyF11)
  95. KeyF12 Key = Key(ui.KeyF12)
  96. KeyF13 Key = Key(ui.KeyF13)
  97. KeyF14 Key = Key(ui.KeyF14)
  98. KeyF15 Key = Key(ui.KeyF15)
  99. KeyF16 Key = Key(ui.KeyF16)
  100. KeyF17 Key = Key(ui.KeyF17)
  101. KeyF18 Key = Key(ui.KeyF18)
  102. KeyF19 Key = Key(ui.KeyF19)
  103. KeyF20 Key = Key(ui.KeyF20)
  104. KeyF21 Key = Key(ui.KeyF21)
  105. KeyF22 Key = Key(ui.KeyF22)
  106. KeyF23 Key = Key(ui.KeyF23)
  107. KeyF24 Key = Key(ui.KeyF24)
  108. KeyHome Key = Key(ui.KeyHome)
  109. KeyInsert Key = Key(ui.KeyInsert)
  110. KeyIntlBackslash Key = Key(ui.KeyIntlBackslash)
  111. KeyMetaLeft Key = Key(ui.KeyMetaLeft)
  112. KeyMetaRight Key = Key(ui.KeyMetaRight)
  113. KeyMinus Key = Key(ui.KeyMinus)
  114. KeyNumLock Key = Key(ui.KeyNumLock)
  115. KeyNumpad0 Key = Key(ui.KeyNumpad0)
  116. KeyNumpad1 Key = Key(ui.KeyNumpad1)
  117. KeyNumpad2 Key = Key(ui.KeyNumpad2)
  118. KeyNumpad3 Key = Key(ui.KeyNumpad3)
  119. KeyNumpad4 Key = Key(ui.KeyNumpad4)
  120. KeyNumpad5 Key = Key(ui.KeyNumpad5)
  121. KeyNumpad6 Key = Key(ui.KeyNumpad6)
  122. KeyNumpad7 Key = Key(ui.KeyNumpad7)
  123. KeyNumpad8 Key = Key(ui.KeyNumpad8)
  124. KeyNumpad9 Key = Key(ui.KeyNumpad9)
  125. KeyNumpadAdd Key = Key(ui.KeyNumpadAdd)
  126. KeyNumpadDecimal Key = Key(ui.KeyNumpadDecimal)
  127. KeyNumpadDivide Key = Key(ui.KeyNumpadDivide)
  128. KeyNumpadEnter Key = Key(ui.KeyNumpadEnter)
  129. KeyNumpadEqual Key = Key(ui.KeyNumpadEqual)
  130. KeyNumpadMultiply Key = Key(ui.KeyNumpadMultiply)
  131. KeyNumpadSubtract Key = Key(ui.KeyNumpadSubtract)
  132. KeyPageDown Key = Key(ui.KeyPageDown)
  133. KeyPageUp Key = Key(ui.KeyPageUp)
  134. KeyPause Key = Key(ui.KeyPause)
  135. KeyPeriod Key = Key(ui.KeyPeriod)
  136. KeyPrintScreen Key = Key(ui.KeyPrintScreen)
  137. KeyQuote Key = Key(ui.KeyQuote)
  138. KeyScrollLock Key = Key(ui.KeyScrollLock)
  139. KeySemicolon Key = Key(ui.KeySemicolon)
  140. KeyShiftLeft Key = Key(ui.KeyShiftLeft)
  141. KeyShiftRight Key = Key(ui.KeyShiftRight)
  142. KeySlash Key = Key(ui.KeySlash)
  143. KeySpace Key = Key(ui.KeySpace)
  144. KeyTab Key = Key(ui.KeyTab)
  145. KeyAlt Key = Key(ui.KeyReserved0)
  146. KeyControl Key = Key(ui.KeyReserved1)
  147. KeyShift Key = Key(ui.KeyReserved2)
  148. KeyMeta Key = Key(ui.KeyReserved3)
  149. KeyMax Key = KeyMeta
  150. // Keys for backward compatibility.
  151. // Deprecated: as of v2.1.
  152. Key0 Key = Key(ui.KeyDigit0)
  153. Key1 Key = Key(ui.KeyDigit1)
  154. Key2 Key = Key(ui.KeyDigit2)
  155. Key3 Key = Key(ui.KeyDigit3)
  156. Key4 Key = Key(ui.KeyDigit4)
  157. Key5 Key = Key(ui.KeyDigit5)
  158. Key6 Key = Key(ui.KeyDigit6)
  159. Key7 Key = Key(ui.KeyDigit7)
  160. Key8 Key = Key(ui.KeyDigit8)
  161. Key9 Key = Key(ui.KeyDigit9)
  162. KeyApostrophe Key = Key(ui.KeyQuote)
  163. KeyDown Key = Key(ui.KeyArrowDown)
  164. KeyGraveAccent Key = Key(ui.KeyBackquote)
  165. KeyKP0 Key = Key(ui.KeyNumpad0)
  166. KeyKP1 Key = Key(ui.KeyNumpad1)
  167. KeyKP2 Key = Key(ui.KeyNumpad2)
  168. KeyKP3 Key = Key(ui.KeyNumpad3)
  169. KeyKP4 Key = Key(ui.KeyNumpad4)
  170. KeyKP5 Key = Key(ui.KeyNumpad5)
  171. KeyKP6 Key = Key(ui.KeyNumpad6)
  172. KeyKP7 Key = Key(ui.KeyNumpad7)
  173. KeyKP8 Key = Key(ui.KeyNumpad8)
  174. KeyKP9 Key = Key(ui.KeyNumpad9)
  175. KeyKPAdd Key = Key(ui.KeyNumpadAdd)
  176. KeyKPDecimal Key = Key(ui.KeyNumpadDecimal)
  177. KeyKPDivide Key = Key(ui.KeyNumpadDivide)
  178. KeyKPEnter Key = Key(ui.KeyNumpadEnter)
  179. KeyKPEqual Key = Key(ui.KeyNumpadEqual)
  180. KeyKPMultiply Key = Key(ui.KeyNumpadMultiply)
  181. KeyKPSubtract Key = Key(ui.KeyNumpadSubtract)
  182. KeyLeft Key = Key(ui.KeyArrowLeft)
  183. KeyLeftBracket Key = Key(ui.KeyBracketLeft)
  184. KeyMenu Key = Key(ui.KeyContextMenu)
  185. KeyRight Key = Key(ui.KeyArrowRight)
  186. KeyRightBracket Key = Key(ui.KeyBracketRight)
  187. KeyUp Key = Key(ui.KeyArrowUp)
  188. )
  189. func (k Key) isValid() bool {
  190. switch k {
  191. case KeyA:
  192. return true
  193. case KeyB:
  194. return true
  195. case KeyC:
  196. return true
  197. case KeyD:
  198. return true
  199. case KeyE:
  200. return true
  201. case KeyF:
  202. return true
  203. case KeyG:
  204. return true
  205. case KeyH:
  206. return true
  207. case KeyI:
  208. return true
  209. case KeyJ:
  210. return true
  211. case KeyK:
  212. return true
  213. case KeyL:
  214. return true
  215. case KeyM:
  216. return true
  217. case KeyN:
  218. return true
  219. case KeyO:
  220. return true
  221. case KeyP:
  222. return true
  223. case KeyQ:
  224. return true
  225. case KeyR:
  226. return true
  227. case KeyS:
  228. return true
  229. case KeyT:
  230. return true
  231. case KeyU:
  232. return true
  233. case KeyV:
  234. return true
  235. case KeyW:
  236. return true
  237. case KeyX:
  238. return true
  239. case KeyY:
  240. return true
  241. case KeyZ:
  242. return true
  243. case KeyAlt:
  244. return true
  245. case KeyAltLeft:
  246. return true
  247. case KeyAltRight:
  248. return true
  249. case KeyArrowDown:
  250. return true
  251. case KeyArrowLeft:
  252. return true
  253. case KeyArrowRight:
  254. return true
  255. case KeyArrowUp:
  256. return true
  257. case KeyBackquote:
  258. return true
  259. case KeyBackslash:
  260. return true
  261. case KeyBackspace:
  262. return true
  263. case KeyBracketLeft:
  264. return true
  265. case KeyBracketRight:
  266. return true
  267. case KeyCapsLock:
  268. return true
  269. case KeyComma:
  270. return true
  271. case KeyContextMenu:
  272. return true
  273. case KeyControl:
  274. return true
  275. case KeyControlLeft:
  276. return true
  277. case KeyControlRight:
  278. return true
  279. case KeyDelete:
  280. return true
  281. case KeyDigit0:
  282. return true
  283. case KeyDigit1:
  284. return true
  285. case KeyDigit2:
  286. return true
  287. case KeyDigit3:
  288. return true
  289. case KeyDigit4:
  290. return true
  291. case KeyDigit5:
  292. return true
  293. case KeyDigit6:
  294. return true
  295. case KeyDigit7:
  296. return true
  297. case KeyDigit8:
  298. return true
  299. case KeyDigit9:
  300. return true
  301. case KeyEnd:
  302. return true
  303. case KeyEnter:
  304. return true
  305. case KeyEqual:
  306. return true
  307. case KeyEscape:
  308. return true
  309. case KeyF1:
  310. return true
  311. case KeyF2:
  312. return true
  313. case KeyF3:
  314. return true
  315. case KeyF4:
  316. return true
  317. case KeyF5:
  318. return true
  319. case KeyF6:
  320. return true
  321. case KeyF7:
  322. return true
  323. case KeyF8:
  324. return true
  325. case KeyF9:
  326. return true
  327. case KeyF10:
  328. return true
  329. case KeyF11:
  330. return true
  331. case KeyF12:
  332. return true
  333. case KeyF13:
  334. return true
  335. case KeyF14:
  336. return true
  337. case KeyF15:
  338. return true
  339. case KeyF16:
  340. return true
  341. case KeyF17:
  342. return true
  343. case KeyF18:
  344. return true
  345. case KeyF19:
  346. return true
  347. case KeyF20:
  348. return true
  349. case KeyF21:
  350. return true
  351. case KeyF22:
  352. return true
  353. case KeyF23:
  354. return true
  355. case KeyF24:
  356. return true
  357. case KeyHome:
  358. return true
  359. case KeyInsert:
  360. return true
  361. case KeyIntlBackslash:
  362. return true
  363. case KeyMeta:
  364. return true
  365. case KeyMetaLeft:
  366. return true
  367. case KeyMetaRight:
  368. return true
  369. case KeyMinus:
  370. return true
  371. case KeyNumLock:
  372. return true
  373. case KeyNumpad0:
  374. return true
  375. case KeyNumpad1:
  376. return true
  377. case KeyNumpad2:
  378. return true
  379. case KeyNumpad3:
  380. return true
  381. case KeyNumpad4:
  382. return true
  383. case KeyNumpad5:
  384. return true
  385. case KeyNumpad6:
  386. return true
  387. case KeyNumpad7:
  388. return true
  389. case KeyNumpad8:
  390. return true
  391. case KeyNumpad9:
  392. return true
  393. case KeyNumpadAdd:
  394. return true
  395. case KeyNumpadDecimal:
  396. return true
  397. case KeyNumpadDivide:
  398. return true
  399. case KeyNumpadEnter:
  400. return true
  401. case KeyNumpadEqual:
  402. return true
  403. case KeyNumpadMultiply:
  404. return true
  405. case KeyNumpadSubtract:
  406. return true
  407. case KeyPageDown:
  408. return true
  409. case KeyPageUp:
  410. return true
  411. case KeyPause:
  412. return true
  413. case KeyPeriod:
  414. return true
  415. case KeyPrintScreen:
  416. return true
  417. case KeyQuote:
  418. return true
  419. case KeyScrollLock:
  420. return true
  421. case KeySemicolon:
  422. return true
  423. case KeyShift:
  424. return true
  425. case KeyShiftLeft:
  426. return true
  427. case KeyShiftRight:
  428. return true
  429. case KeySlash:
  430. return true
  431. case KeySpace:
  432. return true
  433. case KeyTab:
  434. return true
  435. default:
  436. return false
  437. }
  438. }
  439. // String returns a string representing the key.
  440. //
  441. // If k is an undefined key, String returns an empty string.
  442. func (k Key) String() string {
  443. switch k {
  444. case KeyA:
  445. return "A"
  446. case KeyB:
  447. return "B"
  448. case KeyC:
  449. return "C"
  450. case KeyD:
  451. return "D"
  452. case KeyE:
  453. return "E"
  454. case KeyF:
  455. return "F"
  456. case KeyG:
  457. return "G"
  458. case KeyH:
  459. return "H"
  460. case KeyI:
  461. return "I"
  462. case KeyJ:
  463. return "J"
  464. case KeyK:
  465. return "K"
  466. case KeyL:
  467. return "L"
  468. case KeyM:
  469. return "M"
  470. case KeyN:
  471. return "N"
  472. case KeyO:
  473. return "O"
  474. case KeyP:
  475. return "P"
  476. case KeyQ:
  477. return "Q"
  478. case KeyR:
  479. return "R"
  480. case KeyS:
  481. return "S"
  482. case KeyT:
  483. return "T"
  484. case KeyU:
  485. return "U"
  486. case KeyV:
  487. return "V"
  488. case KeyW:
  489. return "W"
  490. case KeyX:
  491. return "X"
  492. case KeyY:
  493. return "Y"
  494. case KeyZ:
  495. return "Z"
  496. case KeyAlt:
  497. return "Alt"
  498. case KeyAltLeft:
  499. return "AltLeft"
  500. case KeyAltRight:
  501. return "AltRight"
  502. case KeyArrowDown:
  503. return "ArrowDown"
  504. case KeyArrowLeft:
  505. return "ArrowLeft"
  506. case KeyArrowRight:
  507. return "ArrowRight"
  508. case KeyArrowUp:
  509. return "ArrowUp"
  510. case KeyBackquote:
  511. return "Backquote"
  512. case KeyBackslash:
  513. return "Backslash"
  514. case KeyBackspace:
  515. return "Backspace"
  516. case KeyBracketLeft:
  517. return "BracketLeft"
  518. case KeyBracketRight:
  519. return "BracketRight"
  520. case KeyCapsLock:
  521. return "CapsLock"
  522. case KeyComma:
  523. return "Comma"
  524. case KeyContextMenu:
  525. return "ContextMenu"
  526. case KeyControl:
  527. return "Control"
  528. case KeyControlLeft:
  529. return "ControlLeft"
  530. case KeyControlRight:
  531. return "ControlRight"
  532. case KeyDelete:
  533. return "Delete"
  534. case KeyDigit0:
  535. return "Digit0"
  536. case KeyDigit1:
  537. return "Digit1"
  538. case KeyDigit2:
  539. return "Digit2"
  540. case KeyDigit3:
  541. return "Digit3"
  542. case KeyDigit4:
  543. return "Digit4"
  544. case KeyDigit5:
  545. return "Digit5"
  546. case KeyDigit6:
  547. return "Digit6"
  548. case KeyDigit7:
  549. return "Digit7"
  550. case KeyDigit8:
  551. return "Digit8"
  552. case KeyDigit9:
  553. return "Digit9"
  554. case KeyEnd:
  555. return "End"
  556. case KeyEnter:
  557. return "Enter"
  558. case KeyEqual:
  559. return "Equal"
  560. case KeyEscape:
  561. return "Escape"
  562. case KeyF1:
  563. return "F1"
  564. case KeyF2:
  565. return "F2"
  566. case KeyF3:
  567. return "F3"
  568. case KeyF4:
  569. return "F4"
  570. case KeyF5:
  571. return "F5"
  572. case KeyF6:
  573. return "F6"
  574. case KeyF7:
  575. return "F7"
  576. case KeyF8:
  577. return "F8"
  578. case KeyF9:
  579. return "F9"
  580. case KeyF10:
  581. return "F10"
  582. case KeyF11:
  583. return "F11"
  584. case KeyF12:
  585. return "F12"
  586. case KeyF13:
  587. return "F13"
  588. case KeyF14:
  589. return "F14"
  590. case KeyF15:
  591. return "F15"
  592. case KeyF16:
  593. return "F16"
  594. case KeyF17:
  595. return "F17"
  596. case KeyF18:
  597. return "F18"
  598. case KeyF19:
  599. return "F19"
  600. case KeyF20:
  601. return "F20"
  602. case KeyF21:
  603. return "F21"
  604. case KeyF22:
  605. return "F22"
  606. case KeyF23:
  607. return "F23"
  608. case KeyF24:
  609. return "F24"
  610. case KeyHome:
  611. return "Home"
  612. case KeyInsert:
  613. return "Insert"
  614. case KeyIntlBackslash:
  615. return "IntlBackslash"
  616. case KeyMeta:
  617. return "Meta"
  618. case KeyMetaLeft:
  619. return "MetaLeft"
  620. case KeyMetaRight:
  621. return "MetaRight"
  622. case KeyMinus:
  623. return "Minus"
  624. case KeyNumLock:
  625. return "NumLock"
  626. case KeyNumpad0:
  627. return "Numpad0"
  628. case KeyNumpad1:
  629. return "Numpad1"
  630. case KeyNumpad2:
  631. return "Numpad2"
  632. case KeyNumpad3:
  633. return "Numpad3"
  634. case KeyNumpad4:
  635. return "Numpad4"
  636. case KeyNumpad5:
  637. return "Numpad5"
  638. case KeyNumpad6:
  639. return "Numpad6"
  640. case KeyNumpad7:
  641. return "Numpad7"
  642. case KeyNumpad8:
  643. return "Numpad8"
  644. case KeyNumpad9:
  645. return "Numpad9"
  646. case KeyNumpadAdd:
  647. return "NumpadAdd"
  648. case KeyNumpadDecimal:
  649. return "NumpadDecimal"
  650. case KeyNumpadDivide:
  651. return "NumpadDivide"
  652. case KeyNumpadEnter:
  653. return "NumpadEnter"
  654. case KeyNumpadEqual:
  655. return "NumpadEqual"
  656. case KeyNumpadMultiply:
  657. return "NumpadMultiply"
  658. case KeyNumpadSubtract:
  659. return "NumpadSubtract"
  660. case KeyPageDown:
  661. return "PageDown"
  662. case KeyPageUp:
  663. return "PageUp"
  664. case KeyPause:
  665. return "Pause"
  666. case KeyPeriod:
  667. return "Period"
  668. case KeyPrintScreen:
  669. return "PrintScreen"
  670. case KeyQuote:
  671. return "Quote"
  672. case KeyScrollLock:
  673. return "ScrollLock"
  674. case KeySemicolon:
  675. return "Semicolon"
  676. case KeyShift:
  677. return "Shift"
  678. case KeyShiftLeft:
  679. return "ShiftLeft"
  680. case KeyShiftRight:
  681. return "ShiftRight"
  682. case KeySlash:
  683. return "Slash"
  684. case KeySpace:
  685. return "Space"
  686. case KeyTab:
  687. return "Tab"
  688. }
  689. return ""
  690. }
  691. func keyNameToKeyCode(name string) (Key, bool) {
  692. switch strings.ToLower(name) {
  693. case "0":
  694. return Key0, true
  695. case "1":
  696. return Key1, true
  697. case "2":
  698. return Key2, true
  699. case "3":
  700. return Key3, true
  701. case "4":
  702. return Key4, true
  703. case "5":
  704. return Key5, true
  705. case "6":
  706. return Key6, true
  707. case "7":
  708. return Key7, true
  709. case "8":
  710. return Key8, true
  711. case "9":
  712. return Key9, true
  713. case "a":
  714. return KeyA, true
  715. case "b":
  716. return KeyB, true
  717. case "c":
  718. return KeyC, true
  719. case "d":
  720. return KeyD, true
  721. case "e":
  722. return KeyE, true
  723. case "f":
  724. return KeyF, true
  725. case "g":
  726. return KeyG, true
  727. case "h":
  728. return KeyH, true
  729. case "i":
  730. return KeyI, true
  731. case "j":
  732. return KeyJ, true
  733. case "k":
  734. return KeyK, true
  735. case "l":
  736. return KeyL, true
  737. case "m":
  738. return KeyM, true
  739. case "n":
  740. return KeyN, true
  741. case "o":
  742. return KeyO, true
  743. case "p":
  744. return KeyP, true
  745. case "q":
  746. return KeyQ, true
  747. case "r":
  748. return KeyR, true
  749. case "s":
  750. return KeyS, true
  751. case "t":
  752. return KeyT, true
  753. case "u":
  754. return KeyU, true
  755. case "v":
  756. return KeyV, true
  757. case "w":
  758. return KeyW, true
  759. case "x":
  760. return KeyX, true
  761. case "y":
  762. return KeyY, true
  763. case "z":
  764. return KeyZ, true
  765. case "alt":
  766. return KeyAlt, true
  767. case "altleft":
  768. return KeyAltLeft, true
  769. case "altright":
  770. return KeyAltRight, true
  771. case "apostrophe":
  772. return KeyApostrophe, true
  773. case "arrowdown":
  774. return KeyArrowDown, true
  775. case "arrowleft":
  776. return KeyArrowLeft, true
  777. case "arrowright":
  778. return KeyArrowRight, true
  779. case "arrowup":
  780. return KeyArrowUp, true
  781. case "backquote":
  782. return KeyBackquote, true
  783. case "backslash":
  784. return KeyBackslash, true
  785. case "backspace":
  786. return KeyBackspace, true
  787. case "bracketleft":
  788. return KeyBracketLeft, true
  789. case "bracketright":
  790. return KeyBracketRight, true
  791. case "capslock":
  792. return KeyCapsLock, true
  793. case "comma":
  794. return KeyComma, true
  795. case "contextmenu":
  796. return KeyContextMenu, true
  797. case "control":
  798. return KeyControl, true
  799. case "controlleft":
  800. return KeyControlLeft, true
  801. case "controlright":
  802. return KeyControlRight, true
  803. case "delete":
  804. return KeyDelete, true
  805. case "digit0":
  806. return KeyDigit0, true
  807. case "digit1":
  808. return KeyDigit1, true
  809. case "digit2":
  810. return KeyDigit2, true
  811. case "digit3":
  812. return KeyDigit3, true
  813. case "digit4":
  814. return KeyDigit4, true
  815. case "digit5":
  816. return KeyDigit5, true
  817. case "digit6":
  818. return KeyDigit6, true
  819. case "digit7":
  820. return KeyDigit7, true
  821. case "digit8":
  822. return KeyDigit8, true
  823. case "digit9":
  824. return KeyDigit9, true
  825. case "down":
  826. return KeyDown, true
  827. case "end":
  828. return KeyEnd, true
  829. case "enter":
  830. return KeyEnter, true
  831. case "equal":
  832. return KeyEqual, true
  833. case "escape":
  834. return KeyEscape, true
  835. case "f1":
  836. return KeyF1, true
  837. case "f2":
  838. return KeyF2, true
  839. case "f3":
  840. return KeyF3, true
  841. case "f4":
  842. return KeyF4, true
  843. case "f5":
  844. return KeyF5, true
  845. case "f6":
  846. return KeyF6, true
  847. case "f7":
  848. return KeyF7, true
  849. case "f8":
  850. return KeyF8, true
  851. case "f9":
  852. return KeyF9, true
  853. case "f10":
  854. return KeyF10, true
  855. case "f11":
  856. return KeyF11, true
  857. case "f12":
  858. return KeyF12, true
  859. case "f13":
  860. return KeyF13, true
  861. case "f14":
  862. return KeyF14, true
  863. case "f15":
  864. return KeyF15, true
  865. case "f16":
  866. return KeyF16, true
  867. case "f17":
  868. return KeyF17, true
  869. case "f18":
  870. return KeyF18, true
  871. case "f19":
  872. return KeyF19, true
  873. case "f20":
  874. return KeyF20, true
  875. case "f21":
  876. return KeyF21, true
  877. case "f22":
  878. return KeyF22, true
  879. case "f23":
  880. return KeyF23, true
  881. case "f24":
  882. return KeyF24, true
  883. case "graveaccent":
  884. return KeyGraveAccent, true
  885. case "home":
  886. return KeyHome, true
  887. case "insert":
  888. return KeyInsert, true
  889. case "intlbackslash":
  890. return KeyIntlBackslash, true
  891. case "kp0":
  892. return KeyKP0, true
  893. case "kp1":
  894. return KeyKP1, true
  895. case "kp2":
  896. return KeyKP2, true
  897. case "kp3":
  898. return KeyKP3, true
  899. case "kp4":
  900. return KeyKP4, true
  901. case "kp5":
  902. return KeyKP5, true
  903. case "kp6":
  904. return KeyKP6, true
  905. case "kp7":
  906. return KeyKP7, true
  907. case "kp8":
  908. return KeyKP8, true
  909. case "kp9":
  910. return KeyKP9, true
  911. case "kpadd":
  912. return KeyKPAdd, true
  913. case "kpdecimal":
  914. return KeyKPDecimal, true
  915. case "kpdivide":
  916. return KeyKPDivide, true
  917. case "kpenter":
  918. return KeyKPEnter, true
  919. case "kpequal":
  920. return KeyKPEqual, true
  921. case "kpmultiply":
  922. return KeyKPMultiply, true
  923. case "kpsubtract":
  924. return KeyKPSubtract, true
  925. case "left":
  926. return KeyLeft, true
  927. case "leftbracket":
  928. return KeyLeftBracket, true
  929. case "menu":
  930. return KeyMenu, true
  931. case "meta":
  932. return KeyMeta, true
  933. case "metaleft":
  934. return KeyMetaLeft, true
  935. case "metaright":
  936. return KeyMetaRight, true
  937. case "minus":
  938. return KeyMinus, true
  939. case "numlock":
  940. return KeyNumLock, true
  941. case "numpad0":
  942. return KeyNumpad0, true
  943. case "numpad1":
  944. return KeyNumpad1, true
  945. case "numpad2":
  946. return KeyNumpad2, true
  947. case "numpad3":
  948. return KeyNumpad3, true
  949. case "numpad4":
  950. return KeyNumpad4, true
  951. case "numpad5":
  952. return KeyNumpad5, true
  953. case "numpad6":
  954. return KeyNumpad6, true
  955. case "numpad7":
  956. return KeyNumpad7, true
  957. case "numpad8":
  958. return KeyNumpad8, true
  959. case "numpad9":
  960. return KeyNumpad9, true
  961. case "numpadadd":
  962. return KeyNumpadAdd, true
  963. case "numpaddecimal":
  964. return KeyNumpadDecimal, true
  965. case "numpaddivide":
  966. return KeyNumpadDivide, true
  967. case "numpadenter":
  968. return KeyNumpadEnter, true
  969. case "numpadequal":
  970. return KeyNumpadEqual, true
  971. case "numpadmultiply":
  972. return KeyNumpadMultiply, true
  973. case "numpadsubtract":
  974. return KeyNumpadSubtract, true
  975. case "pagedown":
  976. return KeyPageDown, true
  977. case "pageup":
  978. return KeyPageUp, true
  979. case "pause":
  980. return KeyPause, true
  981. case "period":
  982. return KeyPeriod, true
  983. case "printscreen":
  984. return KeyPrintScreen, true
  985. case "quote":
  986. return KeyQuote, true
  987. case "right":
  988. return KeyRight, true
  989. case "rightbracket":
  990. return KeyRightBracket, true
  991. case "scrolllock":
  992. return KeyScrollLock, true
  993. case "semicolon":
  994. return KeySemicolon, true
  995. case "shift":
  996. return KeyShift, true
  997. case "shiftleft":
  998. return KeyShiftLeft, true
  999. case "shiftright":
  1000. return KeyShiftRight, true
  1001. case "slash":
  1002. return KeySlash, true
  1003. case "space":
  1004. return KeySpace, true
  1005. case "tab":
  1006. return KeyTab, true
  1007. case "up":
  1008. return KeyUp, true
  1009. }
  1010. return 0, false
  1011. }
  1012. // MarshalText implements encoding.TextMarshaler.
  1013. func (k Key) MarshalText() ([]byte, error) {
  1014. return []byte(k.String()), nil
  1015. }
  1016. // UnmarshalText implements encoding.TextUnmarshaler
  1017. func (k *Key) UnmarshalText(text []byte) error {
  1018. key, ok := keyNameToKeyCode(string(text))
  1019. if !ok {
  1020. return fmt.Errorf("ebiten: unexpected key name: %s", string(text))
  1021. }
  1022. *k = key
  1023. return nil
  1024. }