LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 09-26-2007, 11:07 AM   #1
LonelyStar
LQ Newbie
 
Registered: Sep 2007
Posts: 11

Rep: Reputation: 0
Getting Key and Create events from all window children with Xt


Hello,

I want to write a plugin for codeblocks, that can record Keyboard macros.

I am currently trying around with Xt how to get keyevents. This is my Program so far:

Code:
#include <iostream>

#include <X11/Xlib.h>
#include <X11/Xatom.h>
#include <X11/Intrinsic.h>
#include <X11/StringDefs.h>
#include <X11/Shell.h>
#include <X11/Xmd.h>
#include <X11/Xlibint.h>   /* for resource_mask */

using namespace std;

void AddWindow(Display* disp,Window* w)
{
    XSelectInput(disp,*w,KeyPressMask|KeyReleaseMask|SubstructureNotifyMask);
    Window root1,parent,*children;
    unsigned children_num,i;
    XQueryTree(disp,*w,&root1,&parent,&children,&children_num);
    for(i=0;i<children_num;++i)
    {
        AddWindow(disp,&children[i]);
    }
    Xfree(children);
}

int main(int argc,char *argv[])
{
    XtToolkitInitialize();
    XtSetLanguageProc(0,0,0);
    XtAppContext app_context=XtCreateApplicationContext();
    Display *disp=XtOpenDisplay(app_context,0,"XtTest","XtTest",0,0,&argc,argv);

    Window w=0;
    int revert_to=0;
    XGetInputFocus(disp,&w,&revert_to);

    AddWindow(disp,&w);

    XEvent ev;
    while(1)
    {
        XtAppNextEvent(app_context,&ev);
        XtDispatchEvent(&ev);
        switch(ev.type)
        {
            case KeyPress:
            cout<<"KeyPress"<<std::endl;
            break;
            case KeyRelease:
            cout<<"KeyRelease"<<std::endl;
            break;
            case MapNotify:
            cout<<"Window creation/deletion"<<std::endl;
            break;
            case CreateNotify:
            std::cout<<"Create window event"<<std::endl;
            break;
            default:
            std::cout<<"Unkown event type="<<ev.type<<std::endl;
            break;
        }
    }
    return 0;
}
It works, when i start it in gnome-terminal but only as long as I do not enter the menu or do anything which involves a new window.
As you can see, in AddWindow I am trying to get events from all childwindows. It does not help, I do not get key or CreateNotify events nor do I get Key events while in the menu or a dialog.

Any help?
Thanks!
Nathan

Last edited by LonelyStar; 09-26-2007 at 11:08 AM. Reason: Changed eMail notification
 
Old 09-27-2007, 03:56 AM   #2
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
I don't get a window at all.

Wouldn't you better adding an eventhandler
man XtAddEventHandler to grab keypresses on the mainwindow?
these should(?) propogate down.

Is there a reason why you are processing the Event queue directly
instead of using XtAppMainLoop
and event handlers?

what distro?
 
Old 09-27-2007, 04:10 AM   #3
LonelyStar
LQ Newbie
 
Registered: Sep 2007
Posts: 11

Original Poster
Rep: Reputation: 0
Hi,

Thanks for your reply!
It does not open a window, it just "connects" to the focues window, which is the gnome-terminal in my case.

Using XtAddEventHandler and XtAppMainLoop does not make a difference. I did not use them beacuse ... well, bevause I am used to have a event loop as in my example.

My distro is gentoo.

Nathan
 
Old 09-27-2007, 06:05 AM   #4
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
well, a new window such as a new terminal will not be a child window
the menu probably has an event handler for the keypress
with the propogate set to off
 
Old 09-27-2007, 07:27 AM   #5
LonelyStar
LQ Newbie
 
Registered: Sep 2007
Posts: 11

Original Poster
Rep: Reputation: 0
I just find out about the X record extension. Maybe I have more luck with that.
Thanks for the replies.
Nathan
 
  


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
LXer: Open source is key to reaching 500 million Indian children LXer Syndicated Linux News 1 05-09-2007 01:40 AM
How to get key press and release events on kernel 2.6 for a application in C? abhijeet Programming 2 04-24-2007 12:37 AM
how do you create two children using fork() rdtgr Programming 6 12-03-2006 10:18 AM
root window has no children on display :0.0 jax8 Linux - Newbie 2 04-15-2004 08:26 PM

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

All times are GMT -5. The time now is 06:39 PM.

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