Skip to content

Commit

Permalink
option to send F1-F10 on SHIFT + 1-0
Browse files Browse the repository at this point in the history
this basically reverts 06a4438 but makes it
optional, and disabled by default.

Also refactor the sendFunctionKey() method, it's much shorter now.
The method now requires an ASCII character as parameter instead of a KeyCode.
This makes it possible to use the method with Desire-Z-like keyboards:
Pressing FN+SHIFT+qwert... sends F-Keys, and it works for different keyboard
layouts (QUERTZ/QUERTY), too.
  • Loading branch information
m0vie authored and ddrown committed Jan 16, 2013
1 parent 8acbec6 commit 45b52e2
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 36 deletions.
4 changes: 4 additions & 0 deletions res/values/strings.xml
Expand Up @@ -249,6 +249,10 @@
<string name="pref_dpadescape_title">"2x DPAD = ESC"</string>
<string name="pref_dpadescape_summary">"Send ESC when pressing jogball/dpad twice. Useful for hard keyboards that don't have an escape key, but a jogball/dpad."</string>

<!-- f keys using shift + 1-9 -->
<string name="pref_shiftfkeys_title">"F-Keys on Shift + 1–9"</string>
<string name="pref_shiftfkeys_summary">"Send function keys when pressing Shift + 1–9 on a hardware keyboard."</string>

<!-- Preference to not use pubkeys to authenticate to this host. -->
<string name="list_pubkeyids_none">"Do not use keys"</string>
<!-- Preference to use any pubkey to authenticate to this host. -->
Expand Down
6 changes: 6 additions & 0 deletions res/xml/preferences.xml
Expand Up @@ -239,6 +239,12 @@
android:summary="@string/pref_dpadescape_summary"
android:defaultValue="false"
/>
<CheckBoxPreference
android:key="shiftfkeys"
android:title="@string/pref_shiftfkeys_title"
android:summary="@string/pref_shiftfkeys_summary"
android:defaultValue="false"
/>
</PreferenceCategory>

<PreferenceCategory
Expand Down
57 changes: 21 additions & 36 deletions src/org/woltage/irssiconnectbot/service/TerminalKeyListener.java
Expand Up @@ -94,6 +94,7 @@ public class TerminalKeyListener implements OnKeyListener, OnSharedPreferenceCha
private boolean delOnShiftBackspace;
private String desireZSkandinavianFixes;
private boolean dPadEscape;
private boolean fKeysUsingShiftNumbers;
private String keymode;
private String searchbutton;
private boolean xperiaProFixes;
Expand Down Expand Up @@ -276,12 +277,20 @@ public boolean onKey(View v, int keyCode, KeyEvent event) {
// If there is no hard keyboard or there is a hard keyboard currently hidden,
// CTRL-1 through CTRL-9 will send F1 through F9
if ((!hardKeyboard || (hardKeyboard && hardKeyboardHidden))
&& sendFunctionKey(keyCode))
&& sendFunctionKey(key))
return true;

uchar = keyAsControl(uchar);
}

// if enabled, handle pressing f-keys using shift
if ((hardKeyboard && !hardKeyboardHidden)
&& fKeysUsingShiftNumbers
&& (curMetaState & KeyEvent.META_SHIFT_ON) != 0
&& sendFunctionKey(uchar)) {
return true;
}

if (uchar < 0x80) {
bridge.transport.write(uchar);
} else {
Expand Down Expand Up @@ -350,7 +359,7 @@ else if(uchar == 0xC5 || uchar == 0XE5) //Å or å
if (k != k0)
sendCtrl = true;
// send F1-F10 via CTRL-1 through CTRL-0
if (!sendCtrl && sendFunctionKey(keyCode))
if (!sendCtrl && sendFunctionKey(k0))
return true;
} else if ((orgMetaState & KeyEvent.META_ALT_ON) != 0) {
sendMeta = true;
Expand Down Expand Up @@ -629,44 +638,18 @@ public void sendEscape() {
}

/**
* Send Function Keys F10,F1-F9, if parameter is the ASCII code '0'-'9'
*
* @param key
* @return successful
* The ASCII code of the key, NOT the android KeyCode
* @return {@code true} if the parameter was 0-9 and a function key was sent, {@code false} otherwise.
*/
private boolean sendFunctionKey(int keyCode) {
switch (keyCode) {
case KeyEvent.KEYCODE_1:
((vt320) buffer).keyPressed(vt320.KEY_F1, ' ', 0);
return true;
case KeyEvent.KEYCODE_2:
((vt320) buffer).keyPressed(vt320.KEY_F2, ' ', 0);
return true;
case KeyEvent.KEYCODE_3:
((vt320) buffer).keyPressed(vt320.KEY_F3, ' ', 0);
return true;
case KeyEvent.KEYCODE_4:
((vt320) buffer).keyPressed(vt320.KEY_F4, ' ', 0);
return true;
case KeyEvent.KEYCODE_5:
((vt320) buffer).keyPressed(vt320.KEY_F5, ' ', 0);
private boolean sendFunctionKey(int key) {
if (key >= '0' && key <= '9') {
((vt320) buffer).keyPressed(vt320.KEY_F1 + (key == '0' ? 9 : key - '1'), ' ', 0);
return true;
case KeyEvent.KEYCODE_6:
((vt320) buffer).keyPressed(vt320.KEY_F6, ' ', 0);
return true;
case KeyEvent.KEYCODE_7:
((vt320) buffer).keyPressed(vt320.KEY_F7, ' ', 0);
return true;
case KeyEvent.KEYCODE_8:
((vt320) buffer).keyPressed(vt320.KEY_F8, ' ', 0);
return true;
case KeyEvent.KEYCODE_9:
((vt320) buffer).keyPressed(vt320.KEY_F9, ' ', 0);
return true;
case KeyEvent.KEYCODE_0:
((vt320) buffer).keyPressed(vt320.KEY_F10, ' ', 0);
return true;
default:
return false;
}
return false;
}

/**
Expand Down Expand Up @@ -722,6 +705,7 @@ public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
|| PreferenceConstants.KEYBOARDFIX_XPERIAPRO.equals(key)
|| PreferenceConstants.CAMERA.equals(key)
|| PreferenceConstants.KEYBOARDFIX_DESIREZSKANDINAVIAN.equals(key)
|| PreferenceConstants.KEYBOARDFIX_SHIFT_FKEYS.equals(key)
|| PreferenceConstants.KEYBOARDFIX_DPAD_ESCAPE.equals(key)) {
updateSettings();
}
Expand All @@ -739,6 +723,7 @@ private void updateSettings() {
desireZSkandinavianFixes = prefs.getString(PreferenceConstants.KEYBOARDFIX_DESIREZSKANDINAVIAN,
PreferenceConstants.KEYBOARDFIX_DESIREZSKANDINAVIAN_OFF);
dPadEscape = prefs.getBoolean(PreferenceConstants.KEYBOARDFIX_DPAD_ESCAPE, false);
fKeysUsingShiftNumbers = prefs.getBoolean(PreferenceConstants.KEYBOARDFIX_SHIFT_FKEYS, false);
}


Expand Down
Expand Up @@ -67,6 +67,7 @@ public class PreferenceConstants {
public static final String KEYBOARDFIX_DESIREZSKANDINAVIAN_ON = "only_scandinavian_keys";
public static final String KEYBOARDFIX_DESIREZSKANDINAVIAN_ALL = "true";
public static final String KEYBOARDFIX_DPAD_ESCAPE = "dpadescape";
public static final String KEYBOARDFIX_SHIFT_FKEYS = "shiftfkeys";


public static final String CAMERA = "camera";
Expand Down

0 comments on commit 45b52e2

Please sign in to comment.