LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-24-2009, 02:08 AM   #1
abhinav.zoso
LQ Newbie
 
Registered: Jan 2009
Posts: 14

Rep: Reputation: 0
Question How to send characters on to the active window using X Window?


I want to design a software which converts english to local Indian languages like Hindi, Tamil etc. I want to capture the key strokes of the user, convert it from english to appropriate language and send it to the current active window. I am able to capture the key presses using the input device event interface. Now I need to send it on to the current active window. I know that display is managed by the X Window system. How to send the characters on to the active window?
 
Old 01-24-2009, 05:02 AM   #2
wje_lq
Member
 
Registered: Sep 2007
Location: Mariposa
Distribution: FreeBSD,Debian wheezy
Posts: 811

Rep: Reputation: 179Reputation: 179
Your other thread indicates you're using Java. I have no idea how to do this in Java. In C/C++, you call XSendEvent(). You may find it prudent to call XFlush() after each sent keystroke as well. Try it without XFlush() first; your overall program may do some other activity that flushes the artificial event to the X server.

Hope this helps a little.
 
Old 01-24-2009, 01:21 PM   #3
abhinav.zoso
LQ Newbie
 
Registered: Jan 2009
Posts: 14

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by wje_lq View Post
Your other thread indicates you're using Java. I have no idea how to do this in Java. In C/C++, you call XSendEvent(). You may find it prudent to call XFlush() after each sent keystroke as well. Try it without XFlush() first; your overall program may do some other activity that flushes the artificial event to the X server.

Hope this helps a little.
Java cuz thats what I have been told to use. I am using JNI to integrate the C code with Java. There is nothing much Java code is doing other than calling the native C code. As I have told, I have made use of the input device event interface. And I am able to capture EVERYTHING typed on the keyboard. Though its more like a key logger . This device interface returns codes for every key press and release. I'm not sure if they are scan codes. Now, I need to do the conversion and send them on to the active window. Can you elaborate more on XSendEvent() ? I went through a bit on X Window. Looks like X Window has its own keymap or something like that. So how can I send the characters (converted) which I am able to capture on to the active window using XSendEvent() ? Please help
 
Old 01-24-2009, 02:08 PM   #4
wje_lq
Member
 
Registered: Sep 2007
Location: Mariposa
Distribution: FreeBSD,Debian wheezy
Posts: 811

Rep: Reputation: 179Reputation: 179
The first thing to do is to find out just what you get when you do your keystroke logging. That's not an X question, and I can't help with that, although Mr. Google might be able to, or someone might come along to this thread. Who knows?

Anyway, once you've figured out just what you're getting, you're in luck. Help should be as close as your bash prompt. Do this:
Code:
man X   # upper case X
Then search for the word keyboards

Read that whole section carefully. You'll notice that it distinguishes between keycodes, which can vary from one piece of hardware to the next, and keysyms, which do not vary that way.

You have two ways of going about this.

The more careful way is to find some way to translate from the keystroke logging to meaningful key data, find the data in /usr/include/X11/keysymdef.h, convert from the keysym to the keycode, and use that keycode in XSendEvent().

To do this, you might be interested in several of these functions:
Code:
XStringToKeysym()
XKeysymToString()
XKeycodeToKeysym()
XKeysymToKeycode()
XConvertCase()
The less careful way is to assume (perhaps after experimentation) that the data you get from your logger can be directly used as keycodes for X, and plug those into XSendEvent() directly.

Your pick.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Minimize active window in KDE? Ander Linux - General 4 07-25-2019 03:15 AM
Getting the id of the active window via bash 23meg Programming 7 03-31-2011 02:22 PM
Selecting active window Suse 10.3/compiz cueman SUSE / openSUSE 0 10-28-2007 12:51 PM
determining active x window tcorreia Programming 1 08-22-2004 05:52 AM
determining active x window tcorreia Linux - General 1 08-20-2004 03:55 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:39 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration