LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
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 06-18-2009, 06:16 AM   #1
im_reev
LQ Newbie
 
Registered: Mar 2009
Posts: 2

Rep: Reputation: 0
Smile setxkbmap to change the keyboard


Hi all,

This is my first post. hoping to get solution to my problem here.

I stuck up while generating fake keyboard events from a keyboard for different keyboard layouts like arabic, german, english etc.

setxkbmap is a utility which changes the keyboard layout from one language to another based upon the arguement.
i am using the X11 API to generate the fake event.

Actual problem is, I am not able to generate the various language character events evne though I am changing the keyboard layout prior to the call.

in the below example i am able to show english character 'a' but german char ssharp and arabic character beh are not being displayed correctly.

if i send only arabic characters or german characters than all the characters are displyed correctly.

Logially my code supposed to be working fine but it is not producing the desired result.
It gives an error message for arabic characters like bad access value integer out of range.
This error generally comes if we have not set the correct keyboard layout and try to fire other language char. i.e. if the keyboard layout is set to german and we are firing arabic keyboard events.


Quote:
void writestring()
{
Display *disp_tgt;
Window cur_win;
int focus_state;
int keycode;

disp_tgt = XOpenDisplay(NULL);

/*to change the keyboard layout as US english*/
system(setxkbmap us);

/*get the keycode from the keysym defined in X11*/
keycode = XKeysymToKeycode(disp_tgt, XK_a);

/*send the fake key press event for the keycode kc a in this case*/
XTestFakeKeyEvent(disp_tgt, keycode, TRUE, CurrentTime);
/*send the fake key release event for the keycode kc a in this case*/
XTestFakeKeyEvent(disp_tgt, keycode, FALSE, CurrentTime);

/*forcing the event to be processed*/
XFlush(disp_tgt);

/*to change the keyboard layout as german / deutch*/
system(setxkbmap de);

keycode = XKeysymToKeycode(disp_tgt, XK_ssharp);
XTestFakeKeyEvent(disp_tgt, keycode, TRUE, CurrentTime);
XTestFakeKeyEvent(disp_tgt, keycode, FALSE, CurrentTime);

XFlush(disp_tgt);

system(setxkbmap ar);

keycode = XKeysymToKeycode(disp_tgt, XK_Arabic_alef);
XTestFakeKeyEvent(disp_tgt, keycode, TRUE, CurrentTime);
XTestFakeKeyEvent(disp_tgt, keycode, FALSE, CurrentTime);

XFlush(disp_tgt);

XCloseDisplay(disp_tgt);
}

Hoping to get the comments soon as it is very urgent for me!!
Please bear as this post seems to be very lengthy, but i think it was required to clear myself to you.

Best Regards,
Reev
 
Old 06-22-2009, 03:07 AM   #2
im_reev
LQ Newbie
 
Registered: Mar 2009
Posts: 2

Original Poster
Rep: Reputation: 0
Hi all,
i get the solution to my problem so i thought to share it with you.
The problem is coming because of the API XKeysymToKeycode.
This API was not returning the correct values for the keysym passed to it for various languages.
for german and english in combinationit is working fine but for rest of the languages it return 0 or wrong values. that is the reason to get the wrong character displayed.

Though i do not know why this API is not behaving in correct manner but work around for this problem is passing keycode directly for the keyevents.

for example for german ssharp you can pass 20 as keycode after setting setxkbmap de.
similarly for twosuperior symbol in french you can pass 49 and so on.

for the detailed list of keycode for any particular language you can use xmodmap utility.

for example for french language, you have to set the keyboard layout as french using setxkbmap fr. and than redirect the output of the command xmodmap -pke to some text file.

hope this solve issues for some people.

Happy Programming
Regards,
Reev
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
setxkbmap doesn't work after upgrade platypeanArchcow Linux - Newbie 1 05-07-2009 06:53 PM
setxkbmap - Error loading new keyboard description Jaa Debian 1 09-08-2006 12:29 PM
nr.2 setxkbmap ?? chstani Linux - Newbie 5 09-17-2005 11:54 PM
XFCE & setxkbmap spes_hominis Slackware 3 07-12-2005 04:55 PM
setxkbmap no accents bobbens Linux - Software 0 03-17-2005 01:17 PM


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

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration