как на сях или с++ получить координаты мыши в linuxe ?
чтонить типа
#include <stdio.h>
int main (void)
{
y = каким-то образом получить текущие глобальные координаты
x = ....
printf(x\n");
return 0;
}
возможно ли это?
получить координаты мыши С\C++
Модератор: Модераторы разделов
-
zshgm
- Сообщения: 311
- ОС: Debian
получить координаты мыши С\C++
newblog.kz - заработай на своих статьях :)
-
diesel
- Бывший модератор
- Сообщения: 5989
- ОС: OS X, openSuSE, ROSA, Debian
Re: получить координаты мыши С\C++
http://www.sbin.org/doc/Xlib/chapt_09.html - там есть примеры
http://doc.trolltech.com/4.5/qcursor.html#pos - или так
http://doc.trolltech.com/4.5/qcursor.html#pos - или так
-
zshgm
- Сообщения: 311
- ОС: Debian
Re: получить координаты мыши С\C++
diesel писал(а): ↑10.08.2009 14:54http://www.sbin.org/doc/Xlib/chapt_09.html - там есть примеры
http://doc.trolltech.com/4.5/qcursor.html#pos - или так
а возможно сделать без громоздких библиотек типа QT ? стандартными? чтобы ничего доустанавливать не нужно было?
newblog.kz - заработай на своих статьях :)
-
komcumir
- Сообщения: 273
- ОС: Alt 5.0
Re: получить координаты мыши С\C++
на сях
Код: Выделить всё
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xos.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
Display *display;
int screen_number;
unsigned int modbut;
//Window win;
int new_x, new_y,temp;
if ( ( display = XOpenDisplay ( NULL ) ) == NULL ) {
puts ("Can not connect to the X server!\n");
exit ( 1 );
}
screen_number = DefaultScreen ( display );
Window w = XRootWindow( display, screen_number );
Window w1;
XQueryPointer(display, w, &w1, &w1, &new_x, &new_y, &temp, &temp, &modbut);
printf("%i:%i\n", new_x, new_y);
return 0;
}-
zshgm
- Сообщения: 311
- ОС: Debian
Re: получить координаты мыши С\C++
komcumir писал(а): ↑10.08.2009 15:18на сях
Код: Выделить всё
#include <X11/Xlib.h> #include <X11/Xutil.h> #include <X11/Xos.h> #include <stdio.h> #include <string.h> #include <stdlib.h> int main(int argc, char *argv[]) { Display *display; int screen_number; unsigned int modbut; //Window win; int new_x, new_y,temp; if ( ( display = XOpenDisplay ( NULL ) ) == NULL ) { puts ("Can not connect to the X server!\n"); exit ( 1 ); } screen_number = DefaultScreen ( display ); Window w = XRootWindow( display, screen_number ); Window w1; XQueryPointer(display, w, &w1, &w1, &new_x, &new_y, &temp, &temp, &modbut); printf("%i:%i\n", new_x, new_y); return 0; }
debian:~/java# gcc 1.c
1.c:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘<’ token
1.c:2:23: error: X11/Xutil.h: Нет такого файла или каталога
1.c:3:21: error: X11/Xos.h: Нет такого файла или каталога
In file included from /usr/include/stdio.h:75,
from 1.c:4:
/usr/include/libio.h:332: error: expected specifier-qualifier-list before ‘size_t’
/usr/include/libio.h:364: error: expected declaration specifiers or ‘...’ before ‘size_t’
/usr/include/libio.h:373: error: expected declaration specifiers or ‘...’ before ‘size_t’
/usr/include/libio.h:493: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘_IO_sgetn’
In file included from 1.c:4:
/usr/include/stdio.h:312: error: expected declaration specifiers or ‘...’ before ‘size_t’
/usr/include/stdio.h:319: error: expected declaration specifiers or ‘...’ before ‘size_t’
/usr/include/stdio.h:361: error: expected declaration specifiers or ‘...’ before ‘size_t’
/usr/include/stdio.h:363: error: format string argument not a string type
/usr/include/stdio.h:365: error: expected declaration specifiers or ‘...’ before ‘size_t’
/usr/include/stdio.h:678: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘fread’
/usr/include/stdio.h:684: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘fwrite’
/usr/include/stdio.h:706: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘fread_unlocked’
/usr/include/stdio.h:708: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘fwrite_unlocked’
In file included from 1.c:5:
/usr/include/string.h:39: error: expected declaration specifiers or ‘...’ before ‘size_t’
/usr/include/string.h:43: error: expected declaration specifiers or ‘...’ before ‘size_t’
/usr/include/string.h:52: error: expected declaration specifiers or ‘...’ before ‘size_t’
/usr/include/string.h:59: error: expected declaration specifiers or ‘...’ before ‘size_t’
/usr/include/string.h:62: error: expected declaration specifiers or ‘...’ before ‘size_t’
/usr/include/string.h:66: error: expected declaration specifiers or ‘...’ before ‘size_t’
/usr/include/string.h:88: error: expected declaration specifiers or ‘...’ before ‘size_t’
/usr/include/string.h:96: error: expected declaration specifiers or ‘...’ before ‘size_t’
/usr/include/string.h:102: error: expected declaration specifiers or ‘...’ before ‘size_t’
/usr/include/string.h:109: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘strxfrm’
/usr/include/string.h:184: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘strcspn’
/usr/include/string.h:188: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘strspn’
/usr/include/string.h:242: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘strlen’
/usr/include/string.h:270: error: expected declaration specifiers or ‘...’ before ‘size_t’
/usr/include/string.h:294: error: expected declaration specifiers or ‘...’ before ‘size_t’
/usr/include/string.h:298: error: expected declaration specifiers or ‘...’ before ‘size_t’
/usr/include/string.h:302: error: expected declaration specifiers or ‘...’ before ‘size_t’
/usr/include/string.h:305: error: expected declaration specifiers or ‘...’ before ‘size_t’
/usr/include/string.h:335: error: expected declaration specifiers or ‘...’ before ‘size_t’
In file included from 1.c:6:
/usr/include/stdlib.h:140: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘__ctype_get_mb_cur_max’
In file included from 1.c:6:
/usr/include/stdlib.h:337: error: expected declaration specifiers or ‘...’ before ‘size_t’
/usr/include/stdlib.h:367: error: expected declaration specifiers or ‘...’ before ‘size_t’
/usr/include/stdlib.h:369: error: nonnull argument with out-of-range operand number (argument 1, operand 4)
/usr/include/stdlib.h:471: error: expected ‘)’ before ‘__size’
/usr/include/stdlib.h:473: error: expected ‘)’ before ‘__nmemb’
/usr/include/stdlib.h:485: error: expected declaration specifiers or ‘...’ before ‘size_t’
In file included from /usr/include/stdlib.h:497,
from 1.c:6:
/usr/include/alloca.h:33: error: expected ‘)’ before ‘__size’
In file included from 1.c:6:
/usr/include/stdlib.h:502: error: expected ‘)’ before ‘__size’
/usr/include/stdlib.h:507: error: expected declaration specifiers or ‘...’ before ‘size_t’
/usr/include/stdlib.h:507: error: expected declaration specifiers or ‘...’ before ‘size_t’
/usr/include/stdlib.h:684: error: expected declaration specifiers or ‘...’ before ‘size_t’
/usr/include/stdlib.h:684: error: expected declaration specifiers or ‘...’ before ‘size_t’
/usr/include/stdlib.h:685: error: nonnull argument with out-of-range operand number (argument 1, operand 5)
/usr/include/stdlib.h:689: error: expected declaration specifiers or ‘...’ before ‘size_t’
/usr/include/stdlib.h:689: error: expected declaration specifiers or ‘...’ before ‘size_t’
/usr/include/stdlib.h:690: error: nonnull argument with out-of-range operand number (argument 1, operand 4)
/usr/include/stdlib.h:767: error: expected declaration specifiers or ‘...’ before ‘size_t’
/usr/include/stdlib.h:770: error: expected declaration specifiers or ‘...’ before ‘size_t’
/usr/include/stdlib.h:774: error: expected declaration specifiers or ‘...’ before ‘size_t’
/usr/include/stdlib.h:778: error: expected declaration specifiers or ‘...’ before ‘size_t’
/usr/include/stdlib.h:787: error: expected declaration specifiers or ‘...’ before ‘size_t’
/usr/include/stdlib.h:791: error: expected declaration specifiers or ‘...’ before ‘size_t’
/usr/include/stdlib.h:798: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘mbstowcs’
/usr/include/stdlib.h:801: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘wcstombs’
1.c: In function ‘main’:
1.c:10: error: ‘Display’ undeclared (first use in this function)
1.c:10: error: (Each undeclared identifier is reported only once
1.c:10: error: for each function it appears in.)
1.c:10: error: ‘display’ undeclared (first use in this function)
1.c:20: error: ‘Window’ undeclared (first use in this function)
1.c:20: error: expected ‘;’ before ‘w’
1.c:21: error: expected ‘;’ before ‘w1’
1.c:22: error: ‘w’ undeclared (first use in this function)
1.c:22: error: ‘w1’ undeclared (first use in this function)
нужно Xutil и Xos ставить? или это стандартные?? это случаем не QT ?
Есть ли какая-нибудь функция как в других языках программирования
титпа x=получитькоординатыблабла;
x=получитькоординатыблабла;
?? )
newblog.kz - заработай на своих статьях :)
-
komcumir
- Сообщения: 273
- ОС: Alt 5.0
Re: получить координаты мыши С\C++
нет это не qt
нужно кое какие библиотеки доставить... для работы с иксами
нужно кое какие библиотеки доставить... для работы с иксами
-
zshgm
- Сообщения: 311
- ОС: Debian
Re: получить координаты мыши С\C++
дело в том что прога будет выполняться на удаленном компе с очнь ограниченным инетом и без доступа к репозиториям..
а тут даже при установке 1.2 метра libx11-dev_1.0.3-7_i386.deb
просит кучу "нелегких" зависимостей..
libx11-dev зависит от libxau-dev (>= 1:1.0.0-1), однако:
Пакет libxau-dev не установлен.
libx11-dev зависит от libxdmcp-dev (>= 1:1.0.0-1), однако:
Пакет libxdmcp-dev не установлен.
libx11-dev зависит от libxext-dev, однако:
Пакет libxext-dev не установлен.
libx11-dev зависит от x11proto-core-dev (>= 6.8.99.8-1), однако:
Пакет x11proto-core-dev не установлен.
libx11-dev зависит от x11proto-input-dev, однако:
Пакет x11proto-input-dev не установлен.
libx11-dev зависит от x11proto-kb-dev, однако:
Пакет x11proto-kb-dev не установлен.
libx11-dev зависит от xtrans-dev, однако:
Пакет xtrans-dev не установлен.
Получается на Сях нельзя сделать крохотную софтинку которая будет выводить в консоль координаты мыши? без установки каких либо библиотек? или они только для компиляции нужны?
newblog.kz - заработай на своих статьях :)
-
komcumir
- Сообщения: 273
- ОС: Alt 5.0
Re: получить координаты мыши С\C++
Честно говоря сам мало в сях торкаю ) не знаю возможно только для компиляции ) сам писал прогу эту при жеской необходимости )
так вам для X надо или для терминала координаты?
Спасибо сказали:
-
deadhead
- Сообщения: 1913
- Статус: zzz..z
-
diesel
- Бывший модератор
- Сообщения: 5989
- ОС: OS X, openSuSE, ROSA, Debian
Re: получить координаты мыши С\C++
zshgm писал(а): ↑10.08.2009 15:11diesel писал(а): ↑10.08.2009 14:54http://www.sbin.org/doc/Xlib/chapt_09.html - там есть примеры
http://doc.trolltech.com/4.5/qcursor.html#pos - или так
а возможно сделать без громоздких библиотек типа QT ? стандартными? чтобы ничего доустанавливать не нужно было?
а первая ссылка это документация к xlib ...
Спасибо сказали:
-
zshgm
- Сообщения: 311
- ОС: Debian
Re: получить координаты мыши С\C++
Всем спасибо за помощь, написал скринсавер 
newblog.kz - заработай на своих статьях :)