LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Capturing Keystrokes in linux. APIs or System calls to capture keyboard strokes (https://www.linuxquestions.org/questions/programming-9/capturing-keystrokes-in-linux-apis-or-system-calls-to-capture-keyboard-strokes-695928/)

abhinav.zoso 01-08-2009 03:19 PM

Capturing Keystrokes in linux. APIs or System calls to capture keyboard strokes
 
Hello. Me and my team are working on a project which converts English input from a QWERTY keyboard to Unicodes of local Indian languages like Kannada, Tamil etc. Basically, its a language converter. We're using Java and SWT for UI. The program should run in such a way that once the program is running, wherever the user enters, he should be able to see the converted text as output. That is, the program should be able to capture the keystrokes of the active window the user is using. We are developing this software for both windows and linux.

The only solution is using JNI. For that, we need to know linux system calls. Are there APIs in linux to capture key strokes?? I have heard that there are Win32 APIs called WinJooks(not sure) which doesthe job in windows. So wanted to know if something similar is available in linux. Any other way of doing this in java?

Any other suggestions regarding this are also welcome.

alan_ri 01-08-2009 05:37 PM

I know about this and this keyloggers but they might be buggy,so source code modification may be necessary.A little help for the second one is here.
You can do this on the kernel level also by configuring kernel's keyboard handling code.Here is a good article about that.

jcookeman 01-10-2009 02:27 AM

This is simply not a task for Java. Why would you attempt to do this in such a contrived fashion? Use C/C++ and just do it in native code. However, as far as X is concerned, you are lighting a cigarette with a flame thrower.

Take a look at XKB. I know in my Keyboard Indicator in Gnome, I can use the Russian transliterated keyboard by selecting "Russian Phonetic". If I type English 'i', it produces Cyrillic 'и' in the window. So, I assume it would be trivial to do the same for the various other dialects you wish to do.

It appears you want to do some sort of transliteration. I would encourage you to just create the keyboard layout and submit this work into XKB upstream. I already noticed Kannada and Tamil there, but not phonetic versions.

abhinav.zoso 01-10-2009 11:14 AM

Quote:

Originally Posted by jcookeman (Post 3403300)
This is simply not a task for Java. Why would you attempt to do this in such a contrived fashion? Use C/C++ and just do it in native code. However, as far as X is concerned, you are lighting a cigarette with a flame thrower.

Take a look at XKB. I know in my Keyboard Indicator in Gnome, I can use the Russian transliterated keyboard by selecting "Russian Phonetic". If I type English 'i', it produces Cyrillic 'и' in the window. So, I assume it would be trivial to do the same for the various other dialects you wish to do.

It appears you want to do some sort of transliteration. I would encourage you to just create the keyboard layout and submit this work into XKB upstream. I already noticed Kannada and Tamil there, but not phonetic versions.

Thanks. I'm looking at various articles on how to achieve this. I found out a few links which may be useful. I'm looking into it. As you have said, C/C++ is the best way to interact with hardware. That's what i'm looking at. Just wanted to know a way to intercept the key strokes. The other way round is to simple create an editor (which we already have done click here ) which will do the conversion. But this ain't that interactive. There are quite a few softwares which do this in a very nice manner and are very popular (Baraha and Aksharamala (http://code.google.com/p/aksharamala/) ) but they all work in MS Windows. They are IMEs - Input Method Editors. We want to implement a similar software for linux which has not been done so far. So we somehow need to intercept the user key strokes.

Checked out these two links from the linux journal http://www.linuxjournal.com/article/6396 and http://www.linuxjournal.com/article/6429 but i'm yet to figure out how to make use of them. And we need to use Java for development which forces us to use JNI or some other mechanism to interact with C/C++ native code.

All we need to do is to output the converted text on to the active window. So capture the key strokes, do the conversion and put it onto the active window.


All times are GMT -5. The time now is 03:08 AM.