On Screen Keyboard Problem
hi all!
i'm currently developing an on screen keyboard to be use for my touch screen application. i'm using qt 3.3 in unix/x11.
i have already a keyboard layout, and codes with in the keyboard keys. i used XSendEvent() function to send an event.
all the letters from a-z and special characters works fine, except for the function keys f1-f12, tab, enter and arrow keys.
heres my code in creating event:
Code:
XKeyEvent createKeyEvent(Display *display, Window &win,
Window &winRoot, bool press,
int keycode, int modifiers)
{
XKeyEvent event;
event.display = display;
event.window = win;
event.root = winRoot;
event.subwindow = None;
event.time = CurrentTime;
event.x = 1;
event.y = 1;
event.x_root = 1;
event.y_root = 1;
event.same_screen = TRUE;
event.state = modifiers;
event.keycode = XKeysymToKeycode(display,keycode);
if(press)
event.type = KeyPress;
else
event.type = KeyRelease;
return event;
}
for the sendkey event:
Code:
int tsKeyboardWidget::SendKeys(int keycode)
{
//modifier=pubModifier->text().toInt();
// Obtain the X11 display.
Display *display = XOpenDisplay(NULL);
if(display == NULL)
return -1;
// Get the root window for the current display.
Window winRoot;// = XRootWindow(display,1);
// Find the window which has the current keyboard focus.
Window winFocus;
int revert=RevertToParent;
//int RevertToParent=0;
XGetInputFocus(display, &winFocus,&revert);
winFocus=winFocus+1;
// Send a fake key press event to the window.
XSelectInput(display, winFocus,FocusChangeMask|KeyPressMask|KeyReleaseMask);
XMapWindow(display, winFocus);
XKeyEvent event = createKeyEvent(display, winFocus, winRoot, true, keycode, modifier);
XSendEvent(event.display, event.window, True, KeyPressMask, (XEvent *)&event);
event = createKeyEvent(display, winFocus, winRoot, false, keycode, modifier);
XSendEvent(event.display, event.window, True, KeyPressMask, (XEvent *)&event);
XCloseDisplay(display);
return 0;
}
for button press, for example when i press the button A.
Code:
void tsKeyboardWidget::btnA_clicked()
{
SendKeys(Qt::Key_A);
}
when i send Qt::Key_A it works.
my problem is, when i send the Qt::Key_Tab or Qt::Key_Enter, nothing happens.
is there something wrong with code? or is there another way to send the TAB or ENTER key as what the real keyboard does?
thnks...
Re: On Screen Keyboard Problem
Hi
Qt::Key_Tab isn't the same as keycode required in createKeyEvent.
The keycodes on X11 can be found here:
http://cvsweb.xfree86.org/cvsweb/xc/....h?rev=1.1.1.4
You need to either make a mapping between QT::Key_XX and XK_XX, or use XK_XX directly.
cheers,
leif