Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'[' and ']' do not work in Norwegian layout keyboard #843

Open
kaorahi opened this issue Jan 11, 2021 · 4 comments
Open

'[' and ']' do not work in Norwegian layout keyboard #843

kaorahi opened this issue Jan 11, 2021 · 4 comments

Comments

@kaorahi
Copy link
Contributor

kaorahi commented Jan 11, 2021

from #832 (comment)

@kaorahi
Copy link
Contributor Author

kaorahi commented Jan 11, 2021

I have three plans. But each has some drawback.

Plan A

Support the numpad left/right arrow keys. But this does not help keyboards without numpads.

--- a/src/main/java/featurecat/lizzie/gui/Input.java
+++ b/src/main/java/featurecat/lizzie/gui/Input.java
@@ -498,6 +498,7 @@ public class Input implements MouseListener, KeyListener, MouseWheelListener, Mo
         break;
 
       case VK_OPEN_BRACKET:
+      case VK_KP_LEFT:
         if (Lizzie.frame.boardPositionProportion > 0) {
           Lizzie.frame.boardPositionProportion--;
           refreshType = 2;
@@ -505,6 +506,7 @@ public class Input implements MouseListener, KeyListener, MouseWheelListener, Mo
         break;
 
       case VK_CLOSE_BRACKET:
+      case VK_KP_RIGHT:
         if (Lizzie.frame.boardPositionProportion < 8) {
           Lizzie.frame.boardPositionProportion++;
           refreshType = 2;

Plan B

Use modifiers like Ctrl+Shift+H and Ctrl+Shift+L to avoid conflicts with existing shortcuts. But I'm not sure which combinations are safe in various environments.

--- a/src/main/java/featurecat/lizzie/gui/Input.java
+++ b/src/main/java/featurecat/lizzie/gui/Input.java
@@ -285,7 +285,11 @@ public class Input implements MouseListener, KeyListener, MouseWheelListener, Mo
         break;
 
       case VK_H:
-        Lizzie.config.toggleHandicapInsteadOfWinrate();
+        if (controlIsPressed(e) && e.isShiftDown()) {
+          Lizzie.frame.shiftBoardPosition(-1);
+        } else {
+          Lizzie.config.toggleHandicapInsteadOfWinrate();
+        }
         break;
 
       case VK_PAGE_UP:
@@ -369,7 +373,11 @@ public class Input implements MouseListener, KeyListener, MouseWheelListener, Mo
         break;
 
       case VK_L:
-        Lizzie.config.toggleShowLcbWinrate();
+        if (controlIsPressed(e) && e.isShiftDown()) {
+          Lizzie.frame.shiftBoardPosition(+1);
+        } else {
+          Lizzie.config.toggleShowLcbWinrate();
+        }
         break;
 
       case VK_G:
@@ -498,17 +506,11 @@ public class Input implements MouseListener, KeyListener, MouseWheelListener, Mo
         break;
 
       case VK_OPEN_BRACKET:
-        if (Lizzie.frame.boardPositionProportion > 0) {
-          Lizzie.frame.boardPositionProportion--;
-          refreshType = 2;
-        }
+        Lizzie.frame.shiftBoardPosition(-1);
         break;
 
       case VK_CLOSE_BRACKET:
-        if (Lizzie.frame.boardPositionProportion < 8) {
-          Lizzie.frame.boardPositionProportion++;
-          refreshType = 2;
-        }
+        Lizzie.frame.shiftBoardPosition(+1);
         break;
 
       case VK_K:
--- a/src/main/java/featurecat/lizzie/gui/MainFrame.java
+++ b/src/main/java/featurecat/lizzie/gui/MainFrame.java
@@ -364,6 +364,15 @@ public abstract class MainFrame extends JFrame {
         : resourceBundle.getString("LizzieFrame.display.loading");
   }
 
+  public void shiftBoardPosition(int delta) {
+    final int min = 0, max = 7;
+    int newValue = boardPositionProportion + delta;
+    if (min <= newValue && newValue <= max) {
+      boardPositionProportion = newValue;
+      refresh(2);
+    }
+  }
+
   public void toggleEstimateByZen() {
     if (isEstimating) {
       noEstimateByZen(true);

Plan C

Enable [ and ] even in Norwegian layout. But this will cause a trouble if there exists a layout that assigns Shift+. as ], for example, because Shift+. is already used for another function "toggle KataGo estimate blend".

--- a/src/main/java/featurecat/lizzie/gui/Input.java
+++ b/src/main/java/featurecat/lizzie/gui/Input.java
@@ -51,7 +51,29 @@ public class Input implements MouseListener, KeyListener, MouseWheelListener, Mo
   }
 
   @Override
-  public void keyTyped(KeyEvent e) {}
+  public void keyTyped(KeyEvent e) {
+    // We need to use keyTyped instead of keyPressed to detect '[' and ']'
+    // in Norwegian layout.
+    // (No keys generate VK_OPEN_BRACKET and VK_CLOSE_BRACKET
+    // because they are not on the primary layer of the keyboard.)
+    // https://github.com/featurecat/lizzie/issues/832#issuecomment-756894145
+    // https://github.com/featurecat/lizzie/issues/832#issuecomment-757534648
+    switch (e.getKeyChar()) {
+      case '[':
+        if (Lizzie.frame.boardPositionProportion > 0) {
+          Lizzie.frame.boardPositionProportion--;
+          Lizzie.frame.refresh(2);
+        }
+        break;
+
+      case ']':
+        if (Lizzie.frame.boardPositionProportion < 8) {
+          Lizzie.frame.boardPositionProportion++;
+          Lizzie.frame.refresh(2);
+        }
+        break;
+    }
+  }
 
   public static void undo() {
     undo(1);
@@ -497,20 +519,6 @@ public class Input implements MouseListener, KeyListener, MouseWheelListener, Mo
         Lizzie.frame.replayBranch(e.isAltDown());
         break;
 
-      case VK_OPEN_BRACKET:
-        if (Lizzie.frame.boardPositionProportion > 0) {
-          Lizzie.frame.boardPositionProportion--;
-          refreshType = 2;
-        }
-        break;
-
-      case VK_CLOSE_BRACKET:
-        if (Lizzie.frame.boardPositionProportion < 8) {
-          Lizzie.frame.boardPositionProportion++;
-          refreshType = 2;
-        }
-        break;
-
       case VK_K:
         Lizzie.config.toggleEvaluationColoring();
         break;

@xyproto
Copy link

xyproto commented Jan 11, 2021

I vote for a re-arrangement of keys for the next release, where they are made more standard. ctrl-o for open, ctrl-s for save, ctrl-n for new and alt-left and alt-right to go backwards and forwards, like in browsers.

If that's not possible, I think plan A, to use the numpad arrow keys, sounds best.

@kaorahi
Copy link
Contributor Author

kaorahi commented Jan 11, 2021

Plan A seems useless for Norwegians who use compact keyboards without numpads. Is it really OK?

(Anyway, I'm not an official staff of this project and not in a position to decide which is acceptable.)

@xyproto
Copy link

xyproto commented Jan 11, 2021

There's still the option of using the mouse and/or changing the keyboard layout before launching lizzie, but more standard keybindings would be best, IMO.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants