From fd48f4088922fc0e9f699850000db7c77bac4c83 Mon Sep 17 00:00:00 2001 From: dgis Date: Thu, 27 Jun 2019 23:38:54 +0200 Subject: [PATCH] Improve the win32 keyboard mapping. - Prevent the ESC key from leaving the application. - Map the keyboard DELETE key like it should. - Map the keyboard +/= key to the + key and the _/- key to the - (US keyboard). --- ReadMe.txt | 4 +++ .../emulator/calculator/MainScreenView.java | 35 +++++++++++-------- .../emulator/calculator/PanAndScaleView.java | 3 +- 3 files changed, 27 insertions(+), 15 deletions(-) diff --git a/ReadMe.txt b/ReadMe.txt index 1ca8635..a99935f 100644 --- a/ReadMe.txt +++ b/ReadMe.txt @@ -65,6 +65,9 @@ Version 1.5 (2019-06-xx) - Fix: Selecting an empty KML folder prevent to select the default embedded KML folder (Github Fix: #5)! - Fix a crash with waveOutClose(). - Fix an issue with the Pan and zoom which was possible after closing the calc. +- Prevent the ESC key from leaving the application. +- Map the keyboard DELETE key like it should. +- Map the keyboard +/= key to the + key and the _/- key to the - (US keyboard). Version 1.4 (2019-06-08) @@ -147,6 +150,7 @@ The Eric's Real scripts ("real*.kml" and "real*.bmp") are embedded in this appli TODO +- Make the regular (not keypad) '*', and '/' work (#6). - In Chrome OS: - The timezone seems to be GMT (localtime_r not right?)! - sometimes there is no OK button in the KML Script Compilation Result. diff --git a/app/src/main/java/org/emulator/calculator/MainScreenView.java b/app/src/main/java/org/emulator/calculator/MainScreenView.java index d9bdec5..33ec790 100644 --- a/app/src/main/java/org/emulator/calculator/MainScreenView.java +++ b/app/src/main/java/org/emulator/calculator/MainScreenView.java @@ -60,14 +60,15 @@ public class MainScreenView extends PanAndScaleView { ((Activity)context).getWindowManager().getDefaultDisplay().getMetrics(displayMetrics); bitmapMainScreen = Bitmap.createBitmap(displayMetrics.widthPixels, displayMetrics.heightPixels, Bitmap.Config.ARGB_8888); bitmapMainScreen.eraseColor(Color.BLACK); + enableZoomKeyboard = false; vkmap = new HashMap<>(); //vkmap.put(KeyEvent.KEYCODE_BACK, 0x08); // VK_BACK vkmap.put(KeyEvent.KEYCODE_TAB, 0x09); // VK_TAB vkmap.put(KeyEvent.KEYCODE_ENTER, 0x0D); // VK_RETURN vkmap.put(KeyEvent.KEYCODE_NUMPAD_ENTER, 0x0D); // VK_RETURN - //vkmap.put(KeyEvent.KEYCODE_DEL, 0x2E); // VK_DELETE - vkmap.put(KeyEvent.KEYCODE_DEL, 0x08); // VK_DELETE + vkmap.put(KeyEvent.KEYCODE_DEL, 0x08); // VK_BACK + vkmap.put(KeyEvent.KEYCODE_FORWARD_DEL, 0x2E); // VK_DELETE vkmap.put(KeyEvent.KEYCODE_INSERT, 0x2D); // VK_INSERT vkmap.put(KeyEvent.KEYCODE_SHIFT_LEFT, 0x10); // VK_SHIFT vkmap.put(KeyEvent.KEYCODE_SHIFT_RIGHT, 0x10); // VK_SHIFT @@ -115,16 +116,6 @@ public class MainScreenView extends PanAndScaleView { vkmap.put(KeyEvent.KEYCODE_X, 0x58); // X vkmap.put(KeyEvent.KEYCODE_Y, 0x59); // Y vkmap.put(KeyEvent.KEYCODE_Z, 0x5A); // Z - vkmap.put(KeyEvent.KEYCODE_NUMPAD_0, 0x60); // VK_NUMPAD0 - vkmap.put(KeyEvent.KEYCODE_NUMPAD_1, 0x61); // VK_NUMPAD1 - vkmap.put(KeyEvent.KEYCODE_NUMPAD_2, 0x62); // VK_NUMPAD2 - vkmap.put(KeyEvent.KEYCODE_NUMPAD_3, 0x63); // VK_NUMPAD3 - vkmap.put(KeyEvent.KEYCODE_NUMPAD_4, 0x64); // VK_NUMPAD4 - vkmap.put(KeyEvent.KEYCODE_NUMPAD_5, 0x65); // VK_NUMPAD5 - vkmap.put(KeyEvent.KEYCODE_NUMPAD_6, 0x66); // VK_NUMPAD6 - vkmap.put(KeyEvent.KEYCODE_NUMPAD_7, 0x67); // VK_NUMPAD7 - vkmap.put(KeyEvent.KEYCODE_NUMPAD_8, 0x68); // VK_NUMPAD8 - vkmap.put(KeyEvent.KEYCODE_NUMPAD_9, 0x69); // VK_NUMPAD9 vkmap.put(KeyEvent.KEYCODE_0, 0x60); // VK_NUMPAD0 vkmap.put(KeyEvent.KEYCODE_1, 0x61); // VK_NUMPAD1 vkmap.put(KeyEvent.KEYCODE_2, 0x62); // VK_NUMPAD2 @@ -135,9 +126,21 @@ public class MainScreenView extends PanAndScaleView { vkmap.put(KeyEvent.KEYCODE_7, 0x67); // VK_NUMPAD7 vkmap.put(KeyEvent.KEYCODE_8, 0x68); // VK_NUMPAD8 vkmap.put(KeyEvent.KEYCODE_9, 0x69); // VK_NUMPAD9 + vkmap.put(KeyEvent.KEYCODE_NUMPAD_0, 0x60); // VK_NUMPAD0 + vkmap.put(KeyEvent.KEYCODE_NUMPAD_1, 0x61); // VK_NUMPAD1 + vkmap.put(KeyEvent.KEYCODE_NUMPAD_2, 0x62); // VK_NUMPAD2 + vkmap.put(KeyEvent.KEYCODE_NUMPAD_3, 0x63); // VK_NUMPAD3 + vkmap.put(KeyEvent.KEYCODE_NUMPAD_4, 0x64); // VK_NUMPAD4 + vkmap.put(KeyEvent.KEYCODE_NUMPAD_5, 0x65); // VK_NUMPAD5 + vkmap.put(KeyEvent.KEYCODE_NUMPAD_6, 0x66); // VK_NUMPAD6 + vkmap.put(KeyEvent.KEYCODE_NUMPAD_7, 0x67); // VK_NUMPAD7 + vkmap.put(KeyEvent.KEYCODE_NUMPAD_8, 0x68); // VK_NUMPAD8 + vkmap.put(KeyEvent.KEYCODE_NUMPAD_9, 0x69); // VK_NUMPAD9 vkmap.put(KeyEvent.KEYCODE_NUMPAD_MULTIPLY, 0x6A); // VK_MULTIPLY vkmap.put(KeyEvent.KEYCODE_NUMPAD_ADD, 0x6B); // VK_ADD + vkmap.put(KeyEvent.KEYCODE_EQUALS, 0x6B); // VK_ADD vkmap.put(KeyEvent.KEYCODE_NUMPAD_SUBTRACT, 0x6D); // VK_SUBTRACT + vkmap.put(KeyEvent.KEYCODE_MINUS, 0x6D); // VK_SUBTRACT vkmap.put(KeyEvent.KEYCODE_NUMPAD_DOT, 0x6E); // VK_DECIMAL vkmap.put(KeyEvent.KEYCODE_NUMPAD_DIVIDE, 0x6F); // VK_DIVIDE // vkmap.put(KeyEvent.KEYCODE_SEMICOLON, 0xBA); // VK_OEM_1 (:);) @@ -225,11 +228,13 @@ public class MainScreenView extends PanAndScaleView { public boolean onKeyDown(int keyCode, KeyEvent event) { if((event.getFlags() & KeyEvent.FLAG_VIRTUAL_HARD_KEY) == 0) { Integer windowsKeycode = vkmap.get(keyCode); - if (windowsKeycode != null) + if (windowsKeycode != null) { NativeLib.keyDown(windowsKeycode); - else + } else Log.e(TAG, String.format("Unknown keyCode: %d", keyCode)); } + if(keyCode == KeyEvent.KEYCODE_BACK) + return true; return super.onKeyDown(keyCode, event); } @@ -242,6 +247,8 @@ public class MainScreenView extends PanAndScaleView { else Log.e(TAG, String.format("Unknown keyCode: %d", keyCode)); } + if(keyCode == KeyEvent.KEYCODE_BACK) + return true; return super.onKeyUp(keyCode, event); } diff --git a/app/src/main/java/org/emulator/calculator/PanAndScaleView.java b/app/src/main/java/org/emulator/calculator/PanAndScaleView.java index 2b11acf..eeb71bc 100644 --- a/app/src/main/java/org/emulator/calculator/PanAndScaleView.java +++ b/app/src/main/java/org/emulator/calculator/PanAndScaleView.java @@ -67,6 +67,7 @@ public class PanAndScaleView extends View { protected boolean allowDoubleTapZoom = true; protected boolean fillBounds = false; protected boolean enablePanAndScale = false; + protected boolean enableZoomKeyboard = true; protected Paint paint = null; protected OnTapListener onTapDownListener; @@ -452,7 +453,7 @@ public class PanAndScaleView extends View { @Override public boolean onKeyUp(int keyCode, KeyEvent event) { - if(enablePanAndScale && !fillBounds) { + if(enableZoomKeyboard && enablePanAndScale && !fillBounds) { char character = (char) event.getUnicodeChar(); if (character == '+') { scaleByStep(scaleStep, getWidth() / 2.0f, getHeight() / 2.0f);