[solved/workarround]onKeyDown for second assignment of keys

Put your problem here if it does not fit any of the other categories.

[solved/workarround]onKeyDown for second assignment of keys

Postby scheich » Wed Dec 02, 2009 8:04 pm

Hi!

Is it possible to capture the second assignment of the keys with the onkeyDown-method?
I want to capture the german "Umlaute", but I always get two events, one for the FN(ALT)-key and then the one for the first assignment.

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.         public boolean onKeyDown(int keyCode, KeyEvent event) {
  2.  
  3.  
  4.  
  5.                 if(event.getAction() == KeyEvent.ACTION_DOWN)
  6.  
  7.                 {
  8.  
  9.                         switch(keyCode)
  10.  
  11.                         {
  12.  
  13.                         case KeyEvent.KEYCODE_A:
  14.  
  15.                                 if(!a) checkEvent(1);
  16.  
  17.                                 return true;
  18.  
  19.                         case KeyEvent.KEYCODE_B:
  20.  
  21.                                 if(!b) checkEvent(2);
  22.  
  23.                                 return true;
  24.  
  25.                         case KeyEvent.KEYCODE_C:
  26.  
  27.                                 if(!c) checkEvent(3);
  28.  
  29.                                 return true;
  30.  
  31.                 }
  32.  
  33.                 return super.onKeyDown(keyCode, event);
  34.  
  35.         }
Parsed in 0.031 seconds, using GeSHi 1.0.8.4
Last edited by scheich on Fri Dec 04, 2009 4:58 pm, edited 2 times in total.
scheich
Junior Developer
Junior Developer
 
Posts: 16
Joined: Thu Nov 26, 2009 9:58 pm

Top

Postby scheich » Fri Dec 04, 2009 2:08 pm

I found a page about a KeyMap.
Do I need this for my problem?
If so, somebody already implemented this with the onKeyDown-method?

Greetz, scheich
scheich
Junior Developer
Junior Developer
 
Posts: 16
Joined: Thu Nov 26, 2009 9:58 pm

Postby scheich » Fri Dec 04, 2009 3:48 pm

Found a "solution", think it's just a workaround:

Just used a boolean for it.

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public boolean onKeyDown(int keyCode, KeyEvent event) {
  2.  
  3.                 if (KeyEvent.isModifierKey(keyCode)) {
  4.  
  5.                         mod = true;
  6.  
  7.                         return true;
  8.  
  9.                 }
  10.  
  11.                 {
  12.  
  13.                         switch(keyCode)
  14.  
  15.                         {
  16.  
  17.                         case KeyEvent.KEYCODE_A:
  18.  
  19.                                 if (mod) {
  20.  
  21.                                         Toast.makeText(getApplicationContext(), "ääää",
  22.  
  23.                                                         Toast.LENGTH_SHORT).show();
  24.  
  25.                                 }
  26.  
  27.                                 if (!mod) {
  28.  
  29.                                         Toast.makeText(getApplicationContext(), "aaaa",
  30.  
  31.                                                         Toast.LENGTH_SHORT).show();
  32.  
  33.                                 }
  34.  
  35.                                 return true;
  36.  
  37. [...]
  38.  
  39.  
Parsed in 0.033 seconds, using GeSHi 1.0.8.4


Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. ]public boolean onKeyUp(int keyCode, KeyEvent event) {
  2.  
  3.                 if (KeyEvent.isModifierKey(keyCode)) {
  4.  
  5.                         mod = false;
  6.  
  7.                         return true;
  8.  
  9.                 }
  10.  
  11.                 return super.onKeyUp(keyCode, event);
  12.  
  13.         }
Parsed in 0.035 seconds, using GeSHi 1.0.8.4


EDIT: This will of Course only work for android devices with ModifierKey(FN/ALT)
scheich
Junior Developer
Junior Developer
 
Posts: 16
Joined: Thu Nov 26, 2009 9:58 pm

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: Google [Bot], Yahoo [Bot] and 18 guests