About mouse controlling in c/c++
Guannan Ma
mythmgn at gmail.com
Sat May 7 04:01:50 UTC 2011
Yes.
But my nokia phone does not have a mature b-r-c
Bluetooth Remote allows you to use your phone as a remote control for
audio or video players using Bluetooth. It will control any device
which supports the Bluetooth Audio Video Remote Control (AVRCP)
profile. Suitable audio or video players are: iTunes or QuickTime
players on Apple MAC with OS X, iTunes, Spotify or WinDvd players on
Microsoft Vista with Bluetooth. More info and videos here
http://s60bluetoothremote.blogspot.com/
It;s just for audio or video.
I wrote a simple one with libxdotool today.
I can use puty to contact my laptop through wifi.
It worked.
#include <stdio.h>
#include <termios.h>
#include <stdlib.h>
#include <sys/time.h>
#include <sys/types.h>
#include <string.h>
#include <unistd.h>
#include <xdo.h>
#define POS_PLUS 5
#define D_POS_PLUS 50
/** !@description
Nokia Symbian S60 V3
Arrow key UP ----> 27 91 65
Arrow key LEFT ----> 27 91 68
Down ----> 27 91 66
Right ---> 27 91 67
Confirm key----> 10 (simulate pressing enter)
*
*
*
*
*
*/
int setTTY() {
int ttyDevice = STDOUT_FILENO;
printf("%s\n","Noncanonical terminal mode is enabled");
/* [-]icanon
enable erase, kill, werase, and rprnt special characters*/
/*min N with -icanon, set N characters minimum for a completed read */
system("stty -icanon");
printf(">");
/* Make sure file descriptor is for a TTY device. */
if ( ! isatty(ttyDevice) ) {
printf("Not a TTY device.n");
return(EXIT_FAILURE);
}
/* Flush both the input and output queues. */
else {
if (tcflush(ttyDevice, TCIOFLUSH) == 0)
;
//printf("The input and output queues have been flushed\n");
else
perror("tcflush error");
}
}
int nonCanonical(int sign) {
struct termios ttystate;
//get the terminal state
tcgetattr(STDIN_FILENO, &ttystate);
if (sign==1) {
/*turn off canonical mode*/
ttystate.c_lflag &= ~ICANON; /* To diable canonical input*/
ttystate.c_lflag &= ~ECHO; // To disable user see what he types
/*ttystate.c_lflag &= ~ISIG; To disable Control signals using
control Keys
minimum of number input read.*/
ttystate.c_cc[VMIN] = 1;
} else {
/*turn on canonical mode*/
ttystate.c_lflag |= ICANON; /*To enable Canonical mode*/
ttystate.c_lflag |= ECHO; /*To enable user see what he pressed*/
}
/*set the terminal attributes.*/
tcsetattr(STDIN_FILENO, TCSANOW, &ttystate);
return 1;
}
int handlerKeyPress(char *display) {
static fd_set rfds;
struct timeval tv;
char a,b,c;
char str[20];
xdo_t *p_xt=xdo_new(display);
while (1==1) {
// Set up stdin buffer probe
FD_ZERO(&rfds);
FD_SET(0, &rfds);
tv.tv_sec = 0;
tv.tv_usec = 0;
if (!select(1, &rfds, NULL, NULL, &tv)) {
// No input available
//skips++;
} else {
// Input available immediately
a = getchar();
//printf("%d\n",c);
switch(a) {
/**< */
case 27:
b=getchar();
c=getchar();
switch(c) {
/**< Arrow Up */
case 65:
xdo_mousemove_relative(p_xt,0,-POS_PLUS);
break;
/**< Arrow Down */
case 66:
xdo_mousemove_relative(p_xt,0,POS_PLUS);
break;
/**< Arrow Right */
case 67:
xdo_mousemove_relative(p_xt,POS_PLUS,0);
break;
/**< Arrow Left */
case 68:
xdo_mousemove_relative(p_xt,-POS_PLUS,0);
break;
};
break;
/**< left click */
case 'q':
xdo_click(p_xt,CURRENTWINDOW,1);
break;
case 'p':
/**< right click */
xdo_click(p_xt,CURRENTWINDOW,3);
break;
/**< mouse left button down */
case 'w':
xdo_mousedown(p_xt,CURRENTWINDOW,1);
break;
/**< mouse left button up */
case 'e':
xdo_mouseup(p_xt,CURRENTWINDOW,1);
break;
/**< for longer distance mouse move */
case 'y':
xdo_mousemove_relative(p_xt,0,-D_POS_PLUS);
break;
case 'n':
xdo_mousemove_relative(p_xt,0,D_POS_PLUS);
break;
case 'g':
xdo_mousemove_relative(p_xt,-D_POS_PLUS,0);
break;
case 'j':
xdo_mousemove_relative(p_xt,D_POS_PLUS,0);
break;
/**< Delete key */
case 127:
xdo_keysequence(p_xt,CURRENTWINDOW,"BackSpace",12000);
break;
/**< copy paste and cancel */
case 'c':
xdo_keysequence(p_xt,CURRENTWINDOW,"Control_L+c",12000);
break;
case 'v':
xdo_keysequence(p_xt,CURRENTWINDOW,"Control_L+v",12000);
break;
case 'z':
xdo_keysequence(p_xt,CURRENTWINDOW,"Control_L+z",12000);
}
}
}
xdo_free(p_xt);
}
int main(int argc, char **argv) {
if(argc<=1) {
printf("rmctool needs a DISPLAY argument\n");
}
setTTY();
nonCanonical(1);
handlerKeyPress(argv[1]);
return EXIT_SUCCESS;
}
On Thu, May 5, 2011 at 10:40 AM, Chhatoi Pritam Baral
<chhatoipritam at gmail.com> wrote:
> There are quite a few apps available that do that. Search for apps for your
> phone with the keywords: "Bluetooth remote control".
> It's actually your phone side thing. My Sony Ericsson comes pre-installed
> with five different Bluetooth-Remote-Control presets, and sony supplies
> another software to configure your own keys/mouse-movements for new presets
> --
> ubuntu-users mailing list
> ubuntu-users at lists.ubuntu.com
> Modify settings or unsubscribe at:
> https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
>
>
More information about the ubuntu-users
mailing list