Option to assign mouse click to any HW key

This commit is contained in:
pelya
2011-01-04 16:19:40 +00:00
parent 28b25e2224
commit 92fe366c81
12 changed files with 73 additions and 17 deletions

View File

@@ -4,6 +4,7 @@ package net.sourceforge.clonekeenplus;
import android.app.Activity;
import android.content.Context;
import java.util.Vector;
import android.view.KeyEvent;
class Globals {
public static String ApplicationName = "CommanderGenius";
@@ -65,13 +66,15 @@ class Globals {
public static final int LEFT_CLICK_NEAR_CURSOR = 1;
public static final int LEFT_CLICK_WITH_MULTITOUCH = 2;
public static final int LEFT_CLICK_WITH_PRESSURE = 3;
public static final int LEFT_CLICK_WITH_DPAD = 4;
public static final int LEFT_CLICK_WITH_KEY = 4;
public static int LeftClickMethod = LEFT_CLICK_NORMAL;
public static int LeftClickKey = KeyEvent.KEYCODE_DPAD_CENTER;
public static final int RIGHT_CLICK_NONE = 0;
public static final int RIGHT_CLICK_WITH_MULTITOUCH = 1;
public static final int RIGHT_CLICK_WITH_PRESSURE = 2;
public static final int RIGHT_CLICK_WITH_MENU_BUTTON = 3;
public static final int RIGHT_CLICK_WITH_KEY = 3;
public static int RightClickMethod = RIGHT_CLICK_NONE;
public static int RightClickKey = KeyEvent.KEYCODE_MENU;
public static boolean MoveMouseWithJoystick = false;
public static int MoveMouseWithJoystickSpeed = 0;
public static int MoveMouseWithJoystickAccel = 0;

View File

@@ -108,6 +108,8 @@ class Settings
for( int i = 0; i < Globals.ScreenKbControlsLayout.length; i++ )
for( int ii = 0; ii < 4; ii++ )
out.writeInt(Globals.ScreenKbControlsLayout[i][ii]);
out.writeInt(Globals.LeftClickKey);
out.writeInt(Globals.RightClickKey);
out.close();
settingsLoaded = true;
@@ -230,6 +232,8 @@ class Settings
for( int i = 0; i < Globals.ScreenKbControlsLayout.length; i++ )
for( int ii = 0; ii < 4; ii++ )
Globals.ScreenKbControlsLayout[i][ii] = settingsFile.readInt();
Globals.LeftClickKey = settingsFile.readInt();
Globals.RightClickKey = settingsFile.readInt();
settingsLoaded = true;
@@ -876,7 +880,7 @@ class Settings
p.getResources().getString(R.string.leftclick_near_cursor),
p.getResources().getString(R.string.leftclick_multitouch),
p.getResources().getString(R.string.leftclick_pressure),
p.getResources().getString(R.string.leftclick_dpadcenter) };
p.getResources().getString(R.string.rightclick_key) };
AlertDialog.Builder builder = new AlertDialog.Builder(p);
builder.setTitle(R.string.leftclick_question);
@@ -886,7 +890,10 @@ class Settings
{
Globals.LeftClickMethod = item;
dialog.dismiss();
showMouseConfigMainMenu(p);
if( item == Globals.LEFT_CLICK_WITH_KEY )
p.keyListener = new KeyRemapToolMouseClick(p, true);
else
showMouseConfigMainMenu(p);
}
});
AlertDialog alert = builder.create();
@@ -905,7 +912,7 @@ class Settings
final CharSequence[] items = { p.getResources().getString(R.string.rightclick_none),
p.getResources().getString(R.string.rightclick_multitouch),
p.getResources().getString(R.string.rightclick_pressure),
p.getResources().getString(R.string.rightclick_menu) };
p.getResources().getString(R.string.rightclick_key) };
AlertDialog.Builder builder = new AlertDialog.Builder(p);
builder.setTitle(R.string.rightclick_question);
@@ -915,7 +922,10 @@ class Settings
{
Globals.RightClickMethod = item;
dialog.dismiss();
showMouseConfigMainMenu(p);
if( item == Globals.RIGHT_CLICK_WITH_KEY )
p.keyListener = new KeyRemapToolMouseClick(p, false);
else
showMouseConfigMainMenu(p);
}
});
AlertDialog alert = builder.create();
@@ -923,6 +933,35 @@ class Settings
alert.show();
}
public static class KeyRemapToolMouseClick implements KeyEventsListener
{
MainActivity p;
boolean leftClick;
public KeyRemapToolMouseClick(MainActivity _p, boolean leftClick)
{
p = _p;
p.setText(p.getResources().getString(R.string.remap_hwkeys_press));
this.leftClick = leftClick;
}
public void onKeyEvent(final int keyCode)
{
p.touchListener = null;
int keyIndex = keyCode;
if( keyIndex < 0 )
keyIndex = 0;
if( keyIndex > SDL_Keys.JAVA_KEYCODE_LAST )
keyIndex = 0;
if( leftClick )
Globals.LeftClickKey = keyIndex;
else
Globals.RightClickKey = keyIndex;
showMouseConfigMainMenu(p);
}
}
static void showAdditionalMouseConfig(final MainActivity p)
{
if( ! Globals.AppUsesMouse )
@@ -1597,7 +1636,9 @@ class Settings
Globals.ClickScreenPressure,
Globals.ClickScreenTouchspotSize,
Globals.MoveMouseWithJoystickSpeed,
Globals.MoveMouseWithJoystickAccel );
Globals.MoveMouseWithJoystickAccel,
Globals.LeftClickKey,
Globals.RightClickKey );
if( Globals.AppUsesJoystick && (Globals.UseAccelerometerAsArrowKeys || Globals.UseTouchscreenKeyboard) )
nativeSetJoystickUsed();
if( Globals.AppUsesMultitouch )
@@ -1678,7 +1719,8 @@ class Settings
private static native void nativeSetAccelerometerSettings(int sensitivity, int centerPos);
private static native void nativeSetMouseUsed(int RightClickMethod, int ShowScreenUnderFinger, int LeftClickMethod,
int MoveMouseWithJoystick, int ClickMouseWithDpad, int MaxForce, int MaxRadius,
int MoveMouseWithJoystickSpeed, int MoveMouseWithJoystickAccel);
int MoveMouseWithJoystickSpeed, int MoveMouseWithJoystickAccel,
int leftClickKeycode, int rightClickKeycode);
private static native void nativeSetJoystickUsed();
private static native void nativeSetMultitouchUsed();
private static native void nativeSetTouchscreenKeyboardUsed();

View File

@@ -107,4 +107,5 @@
<string name="calibrate_touchscreen_touch">Touch allen vier Rändern des Bildschirms, drücken Sie Menü, wenn Sie fertig</string>
<string name="screenkb_custom_layout">Passen Sie auf dem Bildschirm Tastatur-Layout</string>
<string name="screenkb_custom_layout_help">Slide-Bildschirm hinzufügen Taste, drücken Sie Menü zum letzten Knopf rückgängig machen</string>
<string name="rightclick_key">Physikalische Schlüssel</string>
</resources>

View File

@@ -107,4 +107,5 @@
<string name="calibrate_touchscreen_touch">Touch kaikki neljä reunaa näytön, paina Valikko, kun olet valmis</string>
<string name="screenkb_custom_layout">Mukauta-ruudun näppäimistö</string>
<string name="screenkb_custom_layout_help">Työnnä näytön lisätä painikkeen, paina Menu kumota viimeksi painike</string>
<string name="rightclick_key">Fyysinen avain</string>
</resources>

View File

@@ -110,4 +110,5 @@
<string name="calibrate_touchscreen_touch">Touchez les quatre bords de l\u0026#39;écran, appuyez sur MENU lorsque vous avez terminé</string>
<string name="screenkb_custom_layout">Personnalisation de la présentation du clavier à l\u0026#39;écran</string>
<string name="screenkb_custom_layout_help">Faites glisser l\u0026#39;écran pour ajouter le bouton, appuyez sur Menu pour annuler le dernier bouton</string>
<string name="rightclick_key">Physique clés</string>
</resources>

View File

@@ -100,4 +100,5 @@
<string name="calibrate_touchscreen_touch">Дотроньтесь до всех четырех краев экрана, потом нажмите MENU</string>
<string name="screenkb_custom_layout">Настройка расположения кнопок</string>
<string name="screenkb_custom_layout_help">Провезите по экрану, чтобы добавить кнопку, нажмите клавишу Меню, чтобы отменить последнюю кнопку</string>
<string name="rightclick_key">Физическая кнопка</string>
</resources>

View File

@@ -100,4 +100,5 @@
<string name="calibrate_touchscreen_touch">Доторкнiться до всіх чотирьох країв екрану, потiм натисніть MENU</string>
<string name="screenkb_custom_layout">Налаштування положення кнопок</string>
<string name="screenkb_custom_layout_help">Провезiть по екрану, щоб додати кнопку, натисніть клавішу Меню, щоб скасувати останню кнопку</string>
<string name="rightclick_key">Фізична кнопка</string>
</resources>

View File

@@ -71,6 +71,7 @@
<string name="mouse_emulation">Mouse emulation</string>
<string name="rightclick_question">Right mouse click</string>
<string name="rightclick_menu">Menu key</string>
<string name="rightclick_key">Physical key</string>
<string name="rightclick_multitouch">Touch screen with second finger</string>
<string name="rightclick_pressure">Touch screen with force</string>
<string name="rightclick_none">Disable right mouse click</string>