fork(1) download
  1. import java.util.HashMap;
  2. import java.util.Map;
  3.  
  4. public final class Main {
  5.  
  6. private final Map<Character, Runnable> map;
  7.  
  8. public Main() {
  9. map = new HashMap<>();
  10. map.put('h', () -> moveCursorLeft());
  11. map.put('j', () -> moveCursorUp());
  12. map.put('k', () -> moveCursorDown());
  13. map.put('l', () -> moveCursorRight());
  14. }
  15.  
  16. public void handleKeyInput() {
  17. var c = getPressedKey();
  18. var action = map.get(c);
  19. if (action == null) {
  20. // Does nothing with keys not associated with actions.
  21. return;
  22. }
  23. action.run();
  24. }
  25.  
  26. /**
  27.   Returns the character of the pressed key.
  28.   If no key is pressed, blocks until any key is pressed.
  29.  
  30.   @return
  31.   The character of the pressed key.
  32.   */
  33. private char getPressedKey() {
  34. return 'a';
  35. }
  36.  
  37. private void moveCursorRight() {}
  38. private void moveCursorUp() {}
  39. private void moveCursorDown() {}
  40. private void moveCursorLeft() {}
  41.  
  42. public static void main(String[] args) {
  43. var m = new Main();
  44. m.handleKeyInput();
  45. }
  46. }
  47.  
Success #stdin #stdout 0.06s 33084KB
stdin
Standard input is empty
stdout
Standard output is empty