Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Aung Kyaw Paing
171 PointsKeyCode : KeyEvent Not Working
I am making a custom soft-keyboard using the framework. I am having problem with Space Key. I want to do something other than committing space on certain condition. Seems Like I can't even log out the Event.
This is the code
@Override public boolean onKeyDown(int keyCode, KeyEvent event) {
switch (keyCode) {
//Default built in codes up here
case KeyEvent.KEYCODE_SPACE:
Log.v("Space", "Pressed");
break;
//Other codes
}
}
And this is the Log I got
11-02 01:07:53.152 30920-30920/co.nexlabs.NexyKeyboard I/View﹕ Touch down dispatch to com.co.nexlabs.nexyKeyboard.LatinKeyboardView{422131b0 V.ED.... ......I. 0,0-540,300 #7f080001 app:id/keyboard}, event = MotionEvent { action=ACTION_DOWN, id[0]=0, x[0]=285.0, y[0]=255.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=111023292, downTime=111023292, deviceId=2, source=0x1002 } 11-02 01:07:53.170 30920-30920/co.nexlabs.NexyKeyboard I/SurfaceTextureClient﹕ [STC::queueBuffer] (this:0x5a7d0f40) fps:1.58, dur:1267.79, max:1165.25, min:102.54 11-02 01:07:53.203 30920-30920/co.nexlabs.NexyKeyboard D/GraphicBuffer﹕ create handle(0x5d3c9358) (w:176, h:120, f:1) 11-02 01:07:55.148 30920-30920/co.nexlabs.NexyKeyboard I/View﹕ Touch up dispatch to com.co.nexlabs.nexyKeyboard.LatinKeyboardView{422131b0 V.ED.... ......I. 0,0-540,300 #7f080001 app:id/keyboard}, event = MotionEvent { action=ACTION_UP, id[0]=0, x[0]=282.5, y[0]=254.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=111025289, downTime=111023292, deviceId=2, source=0x1002 } 11-02 01:07:55.158 30920-30920/co.nexlabs.NexyKeyboard I/SurfaceTextureClient﹕ [STC::queueBuffer] (this:0x5a7d0f40) fps:0.50, dur:1988.15, max:1988.15, min:1988.15 11-02 01:07:55.229 30920-30920/co.nexlabs.NexyKeyboard D/GraphicBuffer﹕ close handle(0x5d3c9358) (w:176 h:120 f:1)
I am really not sure how to format it. Cleaner version here => http://stackoverflow.com/questions/26691823/keycode-keyevent-space-not-working
Aung Kyaw Paing
171 Points@Harry James, Yes, I am experiencing the same problem on all 3 methods. And idea how to fix it?
Harry James
14,780 PointsMoved to answer
Aung Kyaw Paing
171 PointsI got it! Thanks for the help. The Problem was in OnKey(). So on tapping a key, it checks if it's in word separator list. If it's true, then it stops all other function and would compose the text, which is in this case is Space(u0200). I deleted it from word separator list and it works like charm! Thanks for your help. How do I vote up??
Harry James
14,780 PointsWoohoo! Glad to hear you got the problem fixed!
I'll move my comment into an answer so that you can mark it as Best Answer to resolve this post.
1 Answer
Harry James
14,780 PointsIf it's on all 3 methods, are you returning true at some point and, if so, where are you returning true?
If not, make sure that you are! It's stated in the Documentation [here](http://developer.android.com/reference/android/app/Activity.html#onKeyUp(int, android.view.KeyEvent) (Put another bracket on the end of the link - The Markdown formatting messes it up...)
that you should return true to prevent this event from being propagated further, or false to indicate that you have not handled this event and it should continue to be propagated.
Harry James
14,780 PointsHarry James
14,780 PointsHello Aung!
I've never actually created a keyboard in Android before but have some ideas in my head as to what it could be causing the problem. Just to check if they're a possibility as to why this is happening, I'd be interested to know whether you experience the same problem if you change onKeyDown() to onKeyUp()?