@@ -66,6 +66,7 @@ public class CodeBoardIME extends InputMethodService
6666 private Timer timerLongPress = null ;
6767 private KeyboardUiFactory mKeyboardUiFactory = null ;
6868 private KeyboardLayoutView mCurrentKeyboardLayoutView = null ;
69+ private boolean longPressedSpaceButton = false ;
6970
7071 @ Override
7172 public void onKey (int primaryCode , int [] KeyCodes ) {
@@ -272,8 +273,19 @@ public void onKey(int primaryCode, int[] KeyCodes) {
272273// }
273274 }
274275 if (ke != 0 ) {
276+
275277 Log .i (getClass ().getSimpleName (), "onKey: keyEvent " + ke );
276- ic .sendKeyEvent (new KeyEvent (0 , 0 , KeyEvent .ACTION_DOWN , ke , 0 , meta ));
278+
279+ /*
280+ * The if statement was added in order to prevent the space button
281+ * from having an action down event attached to it.
282+ * Reason being that we first want to check
283+ * whether the space button has been long pressed or not
284+ * and afterwards produce the right output to the screen.
285+ * TODO: Investigate whether KeyEvent.ACTION_UP is still required.
286+ */
287+ if (primaryCode != 32 ) { ic .sendKeyEvent (new KeyEvent (0 , 0 , KeyEvent .ACTION_DOWN , ke , 0 , meta )); }
288+
277289 ic .sendKeyEvent (new KeyEvent (0 , 0 , KeyEvent .ACTION_UP , ke , 0 , meta ));
278290 } else {
279291 //All non-letter characters are handled here
@@ -342,6 +354,21 @@ public void onViewClicked(boolean focusChanged) {
342354 }
343355
344356 public void onRelease (int primaryCode ) {
357+
358+ /*
359+ * After the space button is released,
360+ * we check whether it was long pressed or not.
361+ * If it was, we don't do anything,
362+ * but If it wasn't, we print a "space" to the screen.
363+ */
364+ if ((primaryCode == 32 ) && (! longPressedSpaceButton )) {
365+
366+ InputConnection ic = getCurrentInputConnection ();
367+ ic .commitText (String .valueOf ((char ) primaryCode ), 1 );
368+ }
369+
370+ longPressedSpaceButton = false ;
371+
345372 clearLongPressTimer ();
346373 }
347374
@@ -374,6 +401,9 @@ public void onKeyLongPress(int keyCode) {
374401 }
375402
376403 if (keyCode == 32 ) {
404+
405+ longPressedSpaceButton = true ;
406+
377407 InputMethodManager imm = (InputMethodManager )
378408 getSystemService (Context .INPUT_METHOD_SERVICE );
379409 if (imm != null )
0 commit comments