Click here to Skip to main content
15,867,308 members
Please Sign up or sign in to vote.
1.50/5 (2 votes)
See more: , +
Hi,

I work for a university psychology department. I'm an Android programmer, but I've never made a custom Android keyboard before, and I think that's what we'll need to do for our next study.

Problem: create a custom keyboard in Android that works like a standard American English keyboard, but logs all keystrokes to a log file. (If you're worried about this, don't be; this will be for consenting psych study participants only, who have signed an authorization, waiver, etc. We comply with HIPAA.)

Solution: Create a custom keyboard, which I'm pretty sure I can do. I plan to follow this tutorial: http://code.tutsplus.com/tutorials/create-a-custom-keyboard-on-android--cms-22615[^]

Once I have the keyboard implemented and working, how do I log keystrokes from it? I don't even know where to start. What are some different ways this could be accomplished? How do you capture the character values? How do you write those to a log file?

Thanks!
Posted
Comments
Afzaal Ahmad Zeeshan 24-Jun-15 20:53pm    
I am not worried about the privacy user would be threatened about, I am worried about you. You say you're an Android developer yet you have no idea how to log events?

Simple, when ever user presses the buttons your app would be able to get that key and write it to the EditText control, in the same function why not write the character to the log file? Perhaps something same, or a service? What have you thought of until now?
Steve Krakov 24-Jun-15 21:21pm    
Thanks Afzaal.
So I'm in my sophomore year of college doing a double major in Computer Science and Psychology. My "post" is Junior Android Developer for the Psych department development team. So far, I've only made point fixes to existing code (plus I wrote a simple Android game that I converted over from a Java project from a CS course). This is only my second time making an app from the ground up, and my first time doing anything with the keyboard.

I've figured out what the onKey method does, and figured that I would add whatever it is I need to log the keys there. Within the onKey method, I'm already adding commitText and sendKeyEvent to send events to the external application. So I figured I'd have to put some method in there to similarly send the character to some log file, but I was looking for what method to use to write the character to a log file.
Sergey Alexandrovich Kryukov 24-Jun-15 22:09pm    
What have you tried so far?
—SA
Steve Krakov 2-Jul-15 17:39pm    
I have tried googling, searching through forum posts here and on Reddit and Stack Overflow for previous questions that relate to my own, and reading through the Google Android documentation.
So far, no luck. I still don't know what method might be able to log key strokes.
Do you know of any such method?
Sergey Alexandrovich Kryukov 2-Jul-15 17:49pm    
Software is not created by luck. Your whole approach is wrong. You should not try to find how to log. You should look for pure technical aspects and combine them yourself. 1) You know how to implement a keyboard; 2) lean how to log any data, not related to keystrokes; 3) figure out what makes a key stroke information; 4) combine it all together.
Isn't that obvious?
—SA

1 solution

It's weird that you failed to create a working keyboard even after reading that really detailed step-by-step tutorial you referenced. Even though I'm against using some available source code when learning some techniques, you could do it and see how it works. One of the articles with complete code sample is this: http://www.fampennings.nl/maarten/android/09keyboard/index.htm[^].

I'm sure you can find more complete samples: http://bfy.tw/VUh[^].

—SA
 
Share this answer
 
Comments
Steve Krakov 28-Jun-15 17:38pm    
Thanks Sergey!
I have read this article on fampennings before and it's really thorough. It's a great resource.
However, I do already have a working keyboard now -- that's not the problem. Making the keyboard itself was pretty straightforward.
The problem I'm having is this: what kinds of methods would I start researching or trying, to log the actual keystrokes to a log file?
So far, my research has lead me to this conclusion: I should put the key logging code in the onKey method of the soft keyboard main java file. I have already added the commitText and sendKeyEvent methods within onKey -- those are necessary for base keyboard functionality.
Any ideas about what method to put in there, now, to log the keystrokes?
Sergey Alexandrovich Kryukov 28-Jun-15 20:23pm    
And what's the problem with that?
—SA
Steve Krakov 2-Jul-15 17:36pm    
Sergey, I'm not sure what you're after. I will try to explain.
The problem is that I don't know what methods to research, so I am posting here and asking for advice. This is a place people go to for help.
Do you know what methods to research that might do what I described?
Sergey Alexandrovich Kryukov 2-Jul-15 17:45pm    
Sorry if you are unhappy for my attempt to help you or don't even consider it as help. Perhaps I did not pay attention for the tutorial you tried to use. But I still think that looking at the code sample I references should help you. Here is my idea: if you successfully implement the keyboard, it will also have the point where you handle the click on the on-screen "key". It is also apparent that this handle gets full information on what key is clicked. So how the logging of some of this information can possibly be a problem? Therefore, the problem is apparently reduced to having some implementation of the keyboard and understanding what it does. Isn't it logical? And here you have enough of code samples.

Perhaps what you need at this moment is reading this article: What have you tried so far?.

Good luck.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900