You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

MenuKey.java 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /* Copyright 2011 Martin Koegler <mkoegler@auto.tuwien.ac.at>
  2. * Copyright 2011 Pierre Ossman <ossman@cendio.se> for Cendio AB
  3. * Copyright 2012-2017 Brian P. Hinz
  4. *
  5. * This is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This software is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this software; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
  18. * USA.
  19. */
  20. package com.tigervnc.vncviewer;
  21. import java.awt.event.KeyEvent;
  22. import com.tigervnc.rfb.*;
  23. import static java.awt.event.KeyEvent.*;
  24. import static com.tigervnc.rfb.Keysymdef.*;
  25. public class MenuKey
  26. {
  27. static class MenuKeySymbol {
  28. public MenuKeySymbol(String name_, int javacode_,
  29. int keycode_, int keysym_) {
  30. name = name_;
  31. javacode = javacode_;
  32. keycode = keycode_;
  33. keysym = keysym_;
  34. }
  35. String name;
  36. int javacode;
  37. int keycode;
  38. int keysym;
  39. }
  40. private static final MenuKeySymbol[] menuSymbols = {
  41. new MenuKeySymbol("F1", VK_F1, 0x3b, XK_F1),
  42. new MenuKeySymbol("F2", VK_F2, 0x3c, XK_F2),
  43. new MenuKeySymbol("F3", VK_F3, 0x3d, XK_F3),
  44. new MenuKeySymbol("F4", VK_F4, 0x3e, XK_F4),
  45. new MenuKeySymbol("F5", VK_F5, 0x3f, XK_F5),
  46. new MenuKeySymbol("F6", VK_F6, 0x40, XK_F6),
  47. new MenuKeySymbol("F7", VK_F7, 0x41, XK_F7),
  48. new MenuKeySymbol("F8", VK_F8, 0x42, XK_F8),
  49. new MenuKeySymbol("F9", VK_F9, 0x43, XK_F9),
  50. new MenuKeySymbol("F10", VK_F10, 0x44, XK_F10),
  51. new MenuKeySymbol("F11", VK_F11, 0x57, XK_F11),
  52. new MenuKeySymbol("F12", VK_F12, 0x58, XK_F12),
  53. new MenuKeySymbol("Pause", VK_PAUSE, 0xc6, XK_Pause),
  54. new MenuKeySymbol("Scroll_Lock", VK_SCROLL_LOCK,
  55. 0x46, XK_Scroll_Lock),
  56. new MenuKeySymbol("Escape", VK_ESCAPE, 0x01, XK_Escape),
  57. new MenuKeySymbol("Insert", VK_INSERT, 0xd2, XK_Insert),
  58. new MenuKeySymbol("Delete", VK_DELETE, 0xd3, XK_Delete),
  59. new MenuKeySymbol("Home", VK_HOME, 0xc7, XK_Home),
  60. new MenuKeySymbol("Page_Up", VK_PAGE_UP, 0xc9, XK_Page_Up),
  61. new MenuKeySymbol("Page_Down", VK_PAGE_DOWN, 0xd1, XK_Page_Down)
  62. };
  63. static int getMenuKeySymbolCount() {
  64. return menuSymbols.length;
  65. }
  66. public static MenuKeySymbol[] getMenuKeySymbols() {
  67. return menuSymbols;
  68. }
  69. public static String getKeyText(MenuKeySymbol sym) {
  70. if (VncViewer.os.startsWith("mac os x"))
  71. return sym.name.replace("_", " ");
  72. else
  73. return KeyEvent.getKeyText(sym.javacode);
  74. }
  75. public static String getMenuKeyValueStr() {
  76. String s = "";
  77. for (int i = 0; i < getMenuKeySymbolCount(); i++) {
  78. s += menuSymbols[i].name;
  79. if (i < getMenuKeySymbolCount() - 1)
  80. s += ", ";
  81. }
  82. return s;
  83. }
  84. static int getMenuKeyJavaCode() {
  85. int menuKeyCode = VK_F8;
  86. @SuppressWarnings({"static"})
  87. String menuKeyStr =
  88. Configuration.global().getParam("menuKey").getValueStr();
  89. for(int i = 0; i < getMenuKeySymbolCount(); i++)
  90. if (menuSymbols[i].name.equals(menuKeyStr))
  91. menuKeyCode = menuSymbols[i].javacode;
  92. return menuKeyCode;
  93. }
  94. static int getMenuKeyCode() {
  95. int menuKeyCode = 0x42;
  96. @SuppressWarnings({"static"})
  97. String menuKeyStr =
  98. Configuration.global().getParam("menuKey").getValueStr();
  99. for(int i = 0; i < getMenuKeySymbolCount(); i++)
  100. if (menuSymbols[i].name.equals(menuKeyStr))
  101. menuKeyCode = menuSymbols[i].keycode;
  102. return menuKeyCode;
  103. }
  104. static int getMenuKeySym() {
  105. int menuKeySym = XK_F8;
  106. @SuppressWarnings({"static"})
  107. String menuKeyStr =
  108. Configuration.global().getParam("menuKey").getValueStr();
  109. for(int i = 0; i < getMenuKeySymbolCount(); i++)
  110. if (menuSymbols[i].name.equals(menuKeyStr))
  111. menuKeySym = menuSymbols[i].keysym;
  112. return menuKeySym;
  113. }
  114. }