/lib/veewee/provider/core/helper/scancode.rb

https://github.com/vishvananda/veewee · Ruby · 114 lines · 93 code · 17 blank · 4 comment · 5 complexity · dc1c850820383533ac62276c9b9b2f76 MD5 · raw file

  1. module Veewee
  2. module Provider
  3. module Core
  4. module Helper
  5. class Scancode
  6. def self.string_to_keycode(thestring)
  7. #http://www.win.tue.nl/~aeb/linux/kbd/scancodes-1.html
  8. k=Hash.new
  9. k['1'] = '02 82' ; k['2'] = '03 83' ; k['3'] = '04 84'; k['4']= '05 85' ;
  10. k['5']='06 86'; k['6'] = '07 87' ; k['7'] = '08 88'; k['8'] = '09 89'; k['9']= '0a 8a';
  11. k['0']='0b 8b'; k['-'] = '0c 8c'; k['='] = '0d 8d' ;
  12. k['Tab'] = '0f 8f';
  13. k['q'] = '10 90' ; k['w'] = '11 91' ; k['e'] = '12 92';
  14. k['r'] = '13 93' ; k['t'] = '14 94' ; k['y'] = '15 95';
  15. k['u']= '16 96' ; k['i']='17 97'; k['o'] = '18 98' ; k['p'] = '19 99' ;
  16. k['Q'] = '2a 10 aa' ; k['W'] = '2a 11 aa' ; k['E'] = '2a 12 aa'; k['R'] = '2a 13 aa' ; k['T'] = '2a 14 aa' ; k['Y'] = '2a 15 aa'; k['U']= '2a 16 aa' ; k['I']='2a 17 aa'; k['O'] = '2a 18 aa' ; k['P'] = '2a 19 aa' ;
  17. k['a'] = '1e 9e'; k['s'] = '1f 9f' ; k['d'] = '20 a0' ; k['f'] = '21 a1'; k['g'] = '22 a2' ; k['h'] = '23 a3' ; k['j'] = '24 a4';
  18. k['k']= '25 a5' ; k['l']='26 a6';
  19. k['A'] = '2a 1e aa 9e'; k['S'] = '2a 1f aa 9f' ; k['D'] = '2a 20 aa a0' ; k['F'] = '2a 21 aa a1';
  20. k['G'] = '2a 22 aa a2' ; k['H'] = '2a 23 aa a3' ; k['J'] = '2a 24 aa a4'; k['K']= '2a 25 aa a5' ; k['L']='2a 26 aa a6';
  21. k[';'] = '27 a7' ;k['"']='2a 28 aa a8';k['\'']='28 a8';
  22. k['\\'] = '2b ab'; k['|'] = '2a 2b aa 8b';
  23. k['[']='1a 9a'; k[']']='1b 9b';
  24. k['<']='2a 33 aa b3'; k['>']='2a 34 aa b4';
  25. k['$']='2a 05 aa 85';
  26. k['+']='2a 0d aa 8d';
  27. k['?']='2a 35 aa b5';
  28. k['z'] = '2c ac'; k['x'] = '2d ad' ; k['c'] = '2e ae' ; k['v'] = '2f af'; k['b'] = '30 b0' ; k['n'] = '31 b1' ;
  29. k['m'] = '32 b2';
  30. k['Z'] = '2a 2c aa ac'; k['X'] = '2a 2d aa ad' ; k['C'] = '2a 2e aa ae' ; k['V'] = '2a 2f aa af';
  31. k['B'] = '2a 30 aa b0' ; k['N'] = '2a 31 aa b1' ; k['M'] = '2a 32 aa b2';
  32. k[',']= '33 b3' ; k['.']='34 b4'; k['/'] = '35 b5' ;k[':'] = '2a 27 aa a7';
  33. k['%'] = '2a 06 aa 86'; k['_'] = '2a 0c aa 8c';
  34. k['&'] = '2a 08 aa 88';
  35. k['('] = '2a 0a aa 8a';
  36. k[')'] = '2a 0b aa 8b';
  37. special=Hash.new;
  38. special['<Enter>'] = '1c 9c';
  39. special['<Backspace>'] = '0e 8e';
  40. special['<Spacebar>'] = '39 b9';
  41. special['<Return>'] = '1c 9c'
  42. special['<Esc>'] = '01 81';
  43. special['<Tab>'] = '0f 8f';
  44. special['<KillX>'] = '1d 38 0e';
  45. special['<Wait>'] = 'wait';
  46. special['<Up>'] = '48 c8';
  47. special['<Down>'] = '50 d0';
  48. special['<PageUp>'] = '49 c9';
  49. special['<PageDown>'] = '51 d1';
  50. special['<End>'] = '4f cf';
  51. special['<Insert>'] = '52 d2';
  52. special['<Delete>'] = '53 d3';
  53. special['<Left>'] = '4b cb';
  54. special['<Right>'] = '4d cd';
  55. special['<Home>'] = '47 c7';
  56. special['<F1>'] = '3b';
  57. special['<F2>'] = '3c';
  58. special['<F3>'] = '3d';
  59. special['<F4>'] = '3e';
  60. special['<F5>'] = '3f';
  61. special['<F6>'] = '40';
  62. special['<F7>'] = '41';
  63. special['<F8>'] = '42';
  64. special['<F9>'] = '43';
  65. special['<F10>'] = '44';
  66. keycodes=''
  67. thestring.gsub!(/ /,"<Spacebar>")
  68. until thestring.length == 0
  69. nospecial=true;
  70. special.keys.each { |key|
  71. if thestring.start_with?(key)
  72. #take thestring
  73. #check if it starts with a special key + pop special string
  74. keycodes=keycodes+special[key]+' ';
  75. thestring=thestring.slice(key.length,thestring.length-key.length)
  76. nospecial=false;
  77. break;
  78. end
  79. }
  80. if nospecial
  81. code=k[thestring.slice(0,1)]
  82. if !code.nil?
  83. keycodes=keycodes+code+' '
  84. else
  85. env.ui.info "no scan code for #{thestring.slice(0,1)}"
  86. end
  87. #pop one
  88. thestring=thestring.slice(1,thestring.length-1)
  89. end
  90. end
  91. return keycodes
  92. end
  93. end #Class
  94. end #Module
  95. end #Module
  96. end #Module
  97. end #Module