コード例 #1
0
ファイル: hidkeyboard.c プロジェクト: BillyZhangZ/wifi
void process_kbd_buffer(uchar_ptr buffer)
{
    _mqx_uint i;

    for(i = HID_BUFFER_SIZE - 1; i >= 2; i--) {
        switch (buffer[i]) {
            case 4: //'a'
                printf("LEFT\n");
                move_mouse(LEFT);
                break;
            case 22: //'s'
                printf("DOWN\n");
                move_mouse(DOWN);
                break;
            case 7: //'d'
                printf("RIGHT\n");
                move_mouse(RIGHT);
                break;
            case 26: //'w'
                printf("UP\n");
                move_mouse(UP);
                break;
            default:
                break;
        }
    }
}
コード例 #2
0
ファイル: main.c プロジェクト: rofl0r/libxauto
void TEST_move_mouse() {
    char *routine = "TEST_move_mouse";
    printf(testing, routine);
    //First we test with no window
    int before_x = mouse_x(0);
    int before_y = mouse_y(0);
    assert(move_mouse(0, 0, 0));
    int after_x = mouse_x(0);
    int after_y = mouse_y(0);
    assert(after_x == 0 && after_y == 0);

    //Now we try it with a valid window
    Window win = active_window();
    activate_window(win);
    assert(move_mouse(10, 10, win));
    after_x = mouse_x(win);
    after_y = mouse_y(win);
    assert(after_x == 10 && after_y == 10);

    //Finally, let's make sure it doesn't bomb with an invalid window
    //The correct action is to leave the mouse where it is
    assert(move_mouse(20, 20, 20) == FALSE);
    assert(mouse_x(0) != 20 && mouse_y(0) != 20);

    move_mouse(before_x, before_y, 0);
    printf(done, routine);
}
コード例 #3
0
/* Timer compare ISR, for ADC reads */
ISR(TIMER1_COMPA_vect, ISR_BLOCK)
{
    switch (currentState)
    {
        case STATE_X_READ:
            currentX = getResult();
#ifdef DEBUG
            phex16(currentX);
#endif           
#if defined COORD && COORD == 'X'
            setupX();
            currentState = STATE_X_START;
            move_mouse();
#else
            setupY();
            currentState = STATE_Y_START;
#endif
            break;
        case STATE_Y_START:
            ADMUX = (1<< REFS0) | (1 << MUX0); //ADC1
            ADCSRA = (1 << ADEN)|(1 << ADSC)|(1<< ADC_PRESCALER_64);
            
            currentState = STATE_Y_READ;
            break;
        case STATE_Y_READ:
            currentY = getResult();
#ifdef DEBUG
            phex16(currentY); print("\t");
#endif
            
            move_mouse();
           
#if defined COORD && COORD == 'Y'
            setupY();
            currentState = STATE_Y_START;
#else
            setupX();
            currentState = STATE_X_START;
#endif
            break;
        case STATE_X_START:
            ADMUX = (1 << REFS0) | (1 << MUX2); //ADC4
            ADCSRA = (1 << ADEN)|(1 << ADSC)|(1<< ADC_PRESCALER_64);
           
            currentState = STATE_X_READ;
            break;
    }
} 
コード例 #4
0
ファイル: shape.c プロジェクト: wvdschel/bellcore-mgr
void stretch_window(void)
{
  int dx, dy;
  int x0, x1, y0, y1;

  SETMOUSEICON(&mouse_box);
  move_mouse(screen, mouse, &mousex, &mousey, 0);
  SETMOUSEICON(DEFAULT_MOUSE_CURSOR);

  x0 = ACTIVE(x0);
  y0 = ACTIVE(y0);
  x1 = x0 + BIT_WIDE(ACTIVE(border));
  y1 = y0 + BIT_HIGH(ACTIVE(border));
  if (2 * (mousex - x0) < x1 - x0)
    x0 = x1;
  dx = mousex - x0;
  if (2 * (mousey - y0) < y1 - y0)
    y0 = y1;
  dy = mousey - y0;
  /* x0,y0 is corner farthest from mouse. x0+dx,y0+dx is mouse position */

  get_rect(screen, mouse, x0, y0, &dx, &dy, 0);
  do_button(0);

  /* look for shape event here */
  do_event(EVENT_SHAPE, active, E_MAIN);

  (void)shape(x0, y0, dx, dy);
}
コード例 #5
0
ファイル: game.c プロジェクト: tivervac/UGentProjects
void mouse_down(MouseDownEvent * ev, GameState * state) {
	if (ev->button == 1) {
		Mouse * mouse = &state->mouse;

		if (in_world_screen(mouse->screen_x, mouse->screen_y)) {
			if (state->action == BUILD_TOWER) {
				//er wordt een toren neergezet
				Entity* entity;
				entity = place_tower(&state->world, state->blueprint.entity.tower.tower_type, mouse->world_x, mouse->world_y);
				if (entity != NULL) {
					if (state->money - entity->tower.cost >= 0) {
						//pas state aan nu de toren geplaatst is
						state->money -= entity->tower.cost;
						state->towers_length++;
						state->towers = (Entity**) realloc(state->towers, state->towers_length * sizeof(Entity*));
						state->towers[state->towers_length - 1] = entity; 
						state->world.entities[mouse->tile_x][mouse->tile_y] = *entity;
						state->refresh_paths = 1;
						//beweeg de muis om te zien of aan te tonen dat hier nu geen toren meer kan staan
						move_mouse(state);
					} else{
						//niet genoeg geld
						destroy_tower(&state->world, entity);
					}
				}
			} else if (state->action == DESTROY_TOWER) {
				//toren moet verwijderd worden
				if (state->world.entities[mouse->tile_x][mouse->tile_y].type == TOWER) {
					register int i = 0;
					Entity *tower = state->towers[i];
					while (!(convert_world2tile_x(tower->all.world_x) == mouse->tile_x && convert_world2tile_y(tower->all.world_y) == mouse->tile_y)) {
						tower = state->towers[i];
						i++;
					}
					//je krijgt de helft van de kost terug als je de toren terug "verkoopt"
					state->money += tower->tower.cost / 2;
					destroy_tower(&state->world, tower);
					if (i != 0) {
						i--;
					}
					//schuif in de array alle elementen na de verwijderde toren ייn plaats terug
					for (i = i; i < state->towers_length - 1; i++) {
						state->towers[i] = state->towers[i + 1];
					}
					state->towers_length--;
					if (state->towers_length != 0) {
						state->towers = (Entity**) realloc(state->towers, state->towers_length * sizeof(Entity*));
					}
					state->refresh_paths = 1;
				}
			}
		}
		else { /* Outside of world frame => buttons */
			set_button_action(state); /* DO NOT CHANGE */
		}
	}
	else if (ev->button == 2) {
		state->action = NONE;
	}
}
コード例 #6
0
ファイル: prank.c プロジェクト: 0x00pf/0x00sec_code
int
main(void)
{
    int                    fd;
    struct uinput_user_dev uidev;
    struct input_event     ev;
    int                    dx, dy;
    int                    i;

    /* Open the device */
    if ((fd = open ("/dev/uinput", O_WRONLY | O_NONBLOCK)) < 0) die ("error: open");

    /* We want to produce key events... left button click*/
    if(ioctl(fd, UI_SET_EVBIT,  EV_KEY) < 0)    die ("error: ioctl");
    if(ioctl(fd, UI_SET_KEYBIT, BTN_LEFT) < 0)  die ("error: ioctl");

    /* And we also want to produce mouse events */
    if(ioctl(fd, UI_SET_EVBIT,  EV_REL) < 0)    die ("error: ioctl");
    if(ioctl(fd, UI_SET_RELBIT, REL_X) < 0)     die ("error: ioctl");
    if(ioctl(fd, UI_SET_RELBIT, REL_Y) < 0)     die ("error: ioctl");

    /* Time to register our virtual device */
    memset (&uidev, 0, sizeof(uidev));
    snprintf (uidev.name, UINPUT_MAX_NAME_SIZE, "uinput-sample");

    uidev.id.bustype = BUS_USB;
    uidev.id.vendor  = 0x1;
    uidev.id.product = 0x1;
    uidev.id.version = 1;

    if (write (fd, &uidev, sizeof(uidev)) < 0) die("error: write");
    if (ioctl(fd, UI_DEV_CREATE) < 0) die("error: ioctl");
    /* We are done! Fun starts */


    sleep(2);


    while (1)
      {
        for (i = 0; i < 100; i++)
	  {
	    move_mouse (fd, rand() % 10 -5 , rand()%10 - 5);
	  }
	sleep (2);
	click (fd);
	sleep (5);
      }

    sleep(2);

    if (ioctl (fd, UI_DEV_DESTROY) < 0) die ("error: ioctl");

    close (fd);

    return 0;
}
コード例 #7
0
ファイル: game.c プロジェクト: tivervac/UGentProjects
//hulpmethode die kijkt of de gegeven enemy dood is 
int is_dead(Enemy* enemy, GameState* state) {
	if (enemy->health <= 0 && enemy->alive) {
		enemy->alive = 0;
		state->money += INCOME_FEE * (enemy->enemy_type + 1);
		state->score += STD_SCORE * (enemy->enemy_type + 1);
		//Kijk of het vakje moet herkleurd worden indien je niet genoeg geld had om de huidige toren te bouwen
		move_mouse(state);
		return 1;
	}
	return 0;
}
コード例 #8
0
ファイル: cubes.c プロジェクト: cjxgm/clabs
int gl_init( void )
{
    glEnable( GL_BLEND );

    glBlendFunc( GL_SRC_ALPHA, ( bmode ) ?
                 GL_ONE : GL_ONE_MINUS_SRC_ALPHA );

    move_mouse( width, height );

    return( 0 );
}
コード例 #9
0
ファイル: mscursor.c プロジェクト: nidheeshdas/Algosim
void GrMouseDisplayCursor(void)
{
    if (MOUINFO->msstatus != 2) return;
    if (MOUINFO->cursor == NULL) return;
    if (MOUINFO->displayed != FALSE) return;
    move_mouse();
    draw_mouse();
    MOUINFO->displayed = TRUE;
    MOUINFO->docheck = TRUE;
    MOUINFO->blockflag = 0;
}
コード例 #10
0
ファイル: shape.c プロジェクト: wvdschel/bellcore-mgr
/*{{{  shape_window -- reshape a window with the mouse*/
void shape_window(void)
{
  int dx = 16, dy = 16;

  SETMOUSEICON(&mouse_box);
  move_mouse(screen, mouse, &mousex, &mousey, 0);
  SETMOUSEICON(DEFAULT_MOUSE_CURSOR);
  get_rect(screen, mouse, mousex, mousey, &dx, &dy, 0);
  do_button(0);

  /* look for shape event here */
  do_event(EVENT_SHAPE, active, E_MAIN);

  (void)shape(mousex, mousey, dx, dy);
}
コード例 #11
0
ファイル: slider.c プロジェクト: kingcope/LikeOS
static void move_slider(GuiObject * slid, int pos_neg)
{
	GuiWinThread *win_thread;
	
	check_object(slid, "slid", "move_slider");
	check_window(slid->win, "move_slider");
	win_thread = (slid->win)->win_thread;
	
	do {
		usleep(sleep_time);
		do_window_functions(win_thread);
		new_position(slid, pos_neg);
		if (GuiGetMessage() == GuiMouseEvent)
			move_mouse();
	}
	while (GuiMouseGetButton() == GuiMouseLeftButton);
}
コード例 #12
0
static void interpret_message(broadcast_message_t *message)
{
    if (message->type == MOVE) {
        move_mouse(&message->delta_point.from_point, &message->delta_point.to_point);
    }
    else if (message->type == LEFT_DOWN_CLICK) {
        left_down();
    }
    else if (message->type == RIGHT_DOWN_CLICK) {
        right_down();
    }
    else if (message->type == LEFT_UP_CLICK) {
        left_up();
    }
    else if (message->type == RIGHT_UP_CLICK) {
        right_up();
    }
}
コード例 #13
0
ファイル: help.c プロジェクト: CivilPol/sdcboot
int
main (int argc, char *argv[])
{
  /* These have been moved from global to local variables */
  /* this reduces binary size and improves code structure. RP */
  /* Also size of home_page and help_page reduced from 257. RP 11-mar-04 */
  char home_page[20] = "index.htm";
  char help_page[20] = "help.htm";
  char base_dir[257];

  char *showcommand = 0;
  char *oldscreen;
  int oldcursorx = wherex (), oldcursory = wherey ();
  int i;			/* counter for loop */
  int forcemono = 0, fancyscheme = 0;
  int AsciiExtendedChars = 1;
  int codepage = 0;

  cat = catopen("htmlhelp", 0);

  if (getenv ("HELPPATH") == NULL)
    {
      get_base_dir (base_dir, argv[0]);
      strcat (base_dir, "..\\help\\"); /* default location */

      if (lang_add(base_dir, home_page) != 0)
      {
         char testpath[257];
         get_base_dir (base_dir, argv[0]);
         strcat (base_dir, "..\\help\\"); /* bookshelf location */

         strcpy(testpath, base_dir);
         strcat(testpath, home_page);
         if (checkForFile(testpath) != 0)
         {
            get_base_dir (base_dir, argv[0]); /* try same dir as exe */
            strcpy(testpath, base_dir);
            strcat(testpath, home_page);
            if (checkForFile(testpath) != 0)
            {
               *base_dir = '\0'; /* try current dir */
               strcpy(testpath, home_page);
               if (checkForFile(testpath) != 0)
               {
                  get_base_dir (base_dir, argv[0]);
                  strcat (base_dir, "..\\help\\");
               }
            }
         }
      }
    }
  else
    {
      strcpy (base_dir, getenv ("HELPPATH"));
      if (lang_add(base_dir, home_page) != 0)
      {
         strcpy (base_dir, getenv ("HELPPATH"));
         if (base_dir[0] != '\0')
         {
            if (base_dir[strlen(base_dir)-1] != '\\' &&
                base_dir[strlen(base_dir)-1] != '/');
	            strcat (base_dir, "\\");
         }
      }

    }

  if (getenv ("HELPCMD"))
    {
      if (strstr (getenv ("HELPCMD"), "/A"))
	AsciiExtendedChars = 0;
      if (strstr (getenv ("HELPCMD"), "/M"))
	forcemono = 1;
      if (strstr (getenv ("HELPCMD"), "/F1"))
         fancyscheme = 1;
      if (strstr (getenv ("HELPCMD"), "/F2"))
         fancyscheme = 2;
    }

  for (i = 1; i < argc; i++)
    {
      if (argv[i][0] == '/')
	{
	  switch (argv[i][1])
	    {

	    default:
	      printf ("%s -- %s\n", hcatInvArg, argv[i] + 1);
		   printf ("%s\n", hcatHowGetUsage);
         break;

	    case '?':
	      show_usage ();
	      return 0;

	    case 'a':
	    case 'A':
	      if (argv[i][2] == 0)
		AsciiExtendedChars = 0;
	      break;

       case 'c':
       case 'C':
       codepage = atoi(argv[i]+2);
       if (codepage == 0)
       {
          printf("%s (/Cnnn)\n", hcatCodepagePlease);
          printf("%s:\n%s\n", hcatCodepagesSupported, supportedCodepages);
          return 0;
       }
       break;

	    case 'f':
	    case 'F':
	      fancyscheme = atoi(argv[i] + 2);
         if (fancyscheme < 1 || fancyscheme > 2)
            fancyscheme = 1;
         break;

	    case 'h':
	    case 'H':
	      if (argv[i][2] == 0)	/* Only put /h or /H */
		{
        printf ("%s\n", hcatInvArg);
		  printf ("%s\n", hcatHowGetUsage);
		  return 0;
		}
	      else
		{
           strncpy(help_page, argv[i] + 2, 14);
		}
	      break;

	    case 'l':
	    case 'L':
	      strcat (base_dir, argv[i] + 2);
	      checkForFile (base_dir);
	      get_home_page (home_page, base_dir);
	      get_base_dir (base_dir, base_dir);
	      break;

	    case 'm':
	    case 'M':
	      if (argv[i][2] == '\0')
		forcemono = 1;
	      else
		{
		  printf ("%s -- %s\n", hcatInvArg, argv[i] + 1);
		  printf ("%s\n", hcatHowGetUsage);
		  return 0;
		}
	      break;

	    case 'o':		/* Override index file path/name */
	    case 'O':
	      strcpy (base_dir, argv[i] + 2);
         if (lang_add(base_dir, home_page) != 0)
         {
	         strcpy (base_dir, argv[i] + 2);
	         checkForFile (base_dir);
	         get_home_page (home_page, base_dir);
	         get_base_dir (base_dir, base_dir);
         }
	    }
	}
      else if (showcommand == 0)
	{
	  showcommand = malloc (strlen (argv[i]) + 11);
	  if (!showcommand)
	    {
	      printf ("%s\n", hcatMemErr);
	      return 0;
	    }
	  sprintf (showcommand, "#%s", argv[i]);
	}
      else
	{
	  printf ("%s\n", hcat2ManyTopics);
	  printf ("%s\n", hcatHowGetUsage);
	  return 0;
	}
    }

  if (fancyscheme && forcemono)
  {
     printf ("%s\n", hcatFwithN);
	  printf ("%s\n", hcatHowGetUsage);
     return 0;
  }

  /* detect (or force) the codepage to select UTF-8 and entity
     substition support */
  if (selectCodepage(codepage) != codepage && codepage > 0)
  {
     printf("%s\n", hcatCodepageNotSupported);
     printf("%s:\n%s\n", hcatCodepagesSupported, supportedCodepages);
     return 0;
  }

  /* initialise user interface */
  conio_init (forcemono);

  if (forcemono == 0)
    {
      oldscreen = malloc (W * H * 2);
      if (oldscreen)
	save_window (X, Y, W, H, oldscreen);
    }

  if (MonoOrColor == COLOR_MODE && fancyscheme == 0)
    {
      TEXT_COLOR = C_TEXT_COLOR;
      BOLD_COLOR = C_BOLD_COLOR;
      ITALIC_COLOR = C_ITALIC_COLOR;
      BORDER_BOX_COLOR = C_BORDER_COLOR;
      BORDER_TEXT_COLOR = C_BORDER_TEXT_COLOR;
      LINK_COLOR = C_LINK_COLOR;
      LINK_HIGHLIGHTED_COLOR = C_LINK_HIGHLIGHTED_COLOR;
    }
  else if (MonoOrColor == COLOR_MODE && fancyscheme == 1)
    {
      TEXT_COLOR = F1_TEXT_COLOR;
      BOLD_COLOR = F1_BOLD_COLOR;
      ITALIC_COLOR = F1_ITALIC_COLOR;
      BORDER_BOX_COLOR = F1_BORDER_COLOR;
      BORDER_TEXT_COLOR = F1_BORDER_TEXT_COLOR;
      LINK_COLOR = F1_LINK_COLOR;
      LINK_HIGHLIGHTED_COLOR = F1_LINK_HIGHLIGHTED_COLOR;
    }
  else if (MonoOrColor == COLOR_MODE && fancyscheme == 2)
    {
      TEXT_COLOR = F2_TEXT_COLOR;
      BOLD_COLOR = F2_BOLD_COLOR;
      ITALIC_COLOR = F2_ITALIC_COLOR;
      BORDER_BOX_COLOR = F2_BORDER_COLOR;
      BORDER_TEXT_COLOR = F2_BORDER_TEXT_COLOR;
      LINK_COLOR = F2_LINK_COLOR;
      LINK_HIGHLIGHTED_COLOR = F2_LINK_HIGHLIGHTED_COLOR;
    }
  else
    {
      TEXT_COLOR = M_TEXT_COLOR;
      BOLD_COLOR = M_BOLD_COLOR;
      ITALIC_COLOR = M_ITALIC_COLOR;
      BORDER_BOX_COLOR = M_BORDER_COLOR;
      BORDER_TEXT_COLOR = M_BORDER_TEXT_COLOR;
      LINK_COLOR = M_LINK_COLOR;
      LINK_HIGHLIGHTED_COLOR = M_LINK_HIGHLIGHTED_COLOR;
    }
  if (AsciiExtendedChars == 0)
    {
      strcpy (Border22f, "+-+( )+-+");
      strcpy (Border22if, "+-+( )+-+");
      BarBlock1 = '.';
      BarBlock2 = '#';
    }
  show_mouse ();
  move_mouse (80, 25);
  drawmenu ();
  html_view (showcommand, base_dir, home_page, help_page);
  free (showcommand);
  hide_mouse ();
  if ((oldscreen != 0) && (forcemono == 0))
    {
      load_window (X, Y, W, H, oldscreen);
      free (oldscreen);
    }
  conio_exit ();
  gotoxy (oldcursorx, oldcursory);

  return 0;
}
コード例 #14
0
void stdcalc()
{
    double  u=0,v=0;          /* u:输入的第1个数, v:输入的第2个数  */
    int     flag=0;        /* 输入数据是否有小数点标志:0-无 1-有 */
    int     sign=0;           /* 是否单击了运算符:0-无 其他-运算符字符 */
    int     x,y;  /* (x,y)鼠标当前位置 (xx,yy)鼠标前一位置 */
    char   s[9];              /* 存储输入的数字符号(含小数点) */
    int     fget=4;          /* 前一次单击的按钮标签 */
    int     d,dn;                /* 当前单击的按钮标签 */
	int     pn=0;                 /* 当前键盘输入的标签 */
    int     i=0,j; 
    standard();
     save_as_old_mouse(0,0);
         	        outtextxy(OUTX-15,OUTY,"0");
    	        outtextxy(OUTX,OUTY,".");
    while(1)    /* 单击右键则退出简单计算器 */
    {     
          if (kbhit()!=0)
            pn=bioskey(0);
			
		  if (rightpress()==1||pn==0x11b)
		    {mode=-1;break;}
		 
    	if(leftpress()!=1 && pn==0)    /* 鼠标左键未单击的处理 */
    	{
           move_mouse();
    	}
    	else if(MouseLeftFlag==1||pn!=0)  /* 鼠标左键单击的处理 */
    	{
    	    if(MouseLeftFlag==1){
			 MouseLeftFlag=0;   /* 置标志为0,防止单击1次左键而多次进入 */ 
             get_mouse_position(&x,&y);
             d=returnstdkey(x,y); /* 得到单击按钮的标签 */
			}
			else {
			 d=stdgetKey(pn);
			 pn=0;
			 }
			
			if(d==-1) continue;
			if(d==20||d==21||d==22||d==23) 
			{if(d==20) mode=1;if(d==21) mode=2;if(d==22) mode=3;if(d==23) mode=4;
			break;}
    	    show(std[d][0],std[d][2],std[d][1],std[d][3]);

    	    if(d==4)         /* 单击C开始使用 */
    	    {
    	        clearscreen();
    	        outtextxy(OUTX-15,OUTY,"0");
    	        outtextxy(OUTX,OUTY,".");
    	        v=u=0;
    	        sign=0;
    	        flag=0;
    	        i=0;
    	    }
    	    else if((dn=checknum(d,0))!=-1)  /* 单击'0'-'9'数字键的处理 */
    	    {
      	      if(dn==0&&u==0&&flag==0) /* 开始时始终单击'0',就显示0 */
    	      {
    	          i=0;
    	          s[i++]=itoc(dn);
    	          s[i++]='.';
    	          s[i]='\0';
    	          u=atof(s);
    	    	    outch(u);
    	      }
    	      else
    	      { 
    	       if(fget==4||fget==19||fget==3||fget==9)
    	    	  {
    	    		   clearscreen();
    	    		   i=0;
    	    		   s[i++]=itoc(dn);
    	    		   s[i++]='.';
    	    		   s[i]='\0';
    	    		   u=atof(s);
    	    		   outch(u);
    	    	  }
    	    	  if(checknum(fget,0)!=-1)
    	    	  {
    	    	     if(sign==0) /* 未单击运算符,处理第1个数u */
    	    	     {
    	    		     if(flag==0) /* 输入数据无小数点 */
    	    		     {
    	    		        clearscreen();
    	    		        u=u*10+d-'0';
    	    		        if((u>0&&u<1e8)||(u<0&&u>-1e8))
    	    		        {
    	    		           s[--i]=itoc(dn);
    	    		           s[++i]='.';
    	    		           s[++i]='\0';
    	    		           u=atof(s);
    	    		           outch(u);
    	    		        }
    	    		        else
    	    		           outch(u);
    	    		     }
    	    		     if(flag==1) /* 输入数据有小数点 */
    	    		     {
    	    		        if(i<=8)
    	    		        {
    	    		           clearscreen();
    	    		           s[i]=itoc(dn);
    	    		           s[++i]='\0';
    	    		           u=atof(s);
			                   outch(u);
    	    		        }
    	    		     }
    	    	     }
    	    	     if(sign!=0) /* 单击了运算符,处理第2个数v */
    	    	     {
    	    		    if(flag==0)
    	    		    {
    	    		       clearscreen();
    	    		       v=v*10+d-'0';
    	    		       if((v>0&&v<1e8)||(v<0&&v>-1e8))
    	    		       {
    	    		          s[--i]=itoc(dn);
    	    		          s[++i]='.';
    	    		          s[++i]='\0';
    	    		          v=atof(s);
    	    		          outch(v);
    	    		       }
    	    		       else
    	    		          outch(v);
    	    		    }
    	    		    if(flag==1)
    	    		    {
    	    		       if(i<=8)
    	    		       {
    	    		          clearscreen();
    	    		          s[i++]=itoc(dn);
    	    		          s[i]='\0';
    	    		          v=atof(s);
			                  outch(v);
    	    		       }
    	    		    }
    	    	     }
    	    	   }
    	    	   if(fget==8||fget==13||fget==14||fget==18)
    	    	   {
    	    		    clearscreen();
    	    		    i=0;
    	    		    s[i++]=itoc(dn);
    	    		    s[i++]='.';
    	    		    s[i]='\0';
    	    		    v=atof(s);
    	    		    outch(v);
    	    	   }
    	    	   if(fget==17) /* 前一次单击的是小数点按钮 */
    	    	   {
    	    		   clearscreen();
    	    		   s[i]=itoc(dn);
    	    		   s[++i]='\0';
    	    		   if(sign==0)
    	    		   {
			             u=atof(s);
			             outch(u);
    	    		   }
    	    		   if(sign!=0)
    	    		   {
			             v=atof(s);
			             outch(v);
    	    		   }
    	    	   }
    	       }
    	     
    	   }
    	   else if(d==8||d==13||d==14||d==18)  
{  /* 单击加,减,乘,除按钮的处理 */
    	      if(sign!=0)
    	      {
    	      	if(fget==8||fget==13||fget==14||fget==18);
    	      	else
    	      	{
    	      	   if(sign==14&&v==0)
    	      	   {
    	      	   	clearscreen();
    	      	   	outtextxy(OUTX-15,OUTY,"Err");
    	      	   }
    	      	   else{
    	      	   	u=calculate(u,v,sign);
    	      	   	outch(u);
    	      	   }
    	      	}
    	      }
    	      sign=d;
    	      flag=0;
    	      i=0;
    	   }
    	   else if(d==19)   /* 单击等号按钮的处理 */ 
    	   {
    	      if(sign!=0)
    	      {
    	      	if(sign=='/'&&fabs(v)<1e-6)
    	      	{
    	      	   clearscreen();
    	      	   outtextxy(OUTX-15,OUTY,"Err");
    	      	}
    	      	else
    	      	{
    	      	   u=calculate(u,v,sign);
    	      	   outch(u);
    	      	}
    	      }
    	      flag=0;
    	      sign=0;
    	      i=0;
    	   }
    	   else if(d==17)   /* 单击小数点按钮的处理 */ 
    	   {
    	     if(flag==0)
    	     	 flag=1;
    	   }
    	   else if(d==3)  /* 单击1/x按钮的处理 */ 
    	   {
    	      if(sign==0)   /* 如果是第1个数,输出u的百分数 */
    	      	{if(fabs(u)>1e-6) {u=1/u; outch(u);} else  {clearscreen();  outtextxy(OUTX-15,OUTY,"Err");}}
    	      if(sign!=0)   /* 是第2个数(单击过运算符),输出v的百分数 */
    	      	{if(fabs(v)>1e-6) {v=1/v; outch(v);} else  {clearscreen();  outtextxy(OUTX-15,OUTY,"Err");}}

    	      i=0;
    	   }
    	   else if(d==9)  /* 单击求平方根按钮的处理 */
         {
    	     if(sign==0)    /*对输入的第1个数求平方根 */
    	     {
    	     	  if(u<0)
    	     	  {
    	     	     clearscreen();
    	     	     outtextxy(OUTX-15,OUTY,"Err");
    	     	  }
    	     	  else{
    	     	     u=sqrt(u);
    	     	     outch(u);
    	     	  }
    	     }
    	     if(sign!=0) /*对输入的第2个数求平方根 */
    	     {
    	     	  if(v<0)
    	     	  {
    	     	     clearscreen();
    	     	     outtextxy(OUTX-15,OUTY,"Er");
    	     	  }
    	     	  else{
    	     	     v=sqrt(v);
    	     	     outch(v);
    	     	  }
    	     }
    	     i=0;
    	   }
    	   else if(d==16)   /* 单击+/-按钮的处理 */
    	   {
    	         if(sign==0)
    	         {
    	         	u=-u;
    	         	outch(u);
    	         }
    	         else
    	         {
    	         	v=-v;
    	         	outch(v);
    	         }
    	   }
    	   else
    	      continue;

	       fget=d;   /* 保存上次单击按钮的标签 */
       } /* End of else if(MouseLeftFlag==1) */
     }   /* End of while(rightpress()!=2) */

}
コード例 #15
0
ファイル: slider.c プロジェクト: kingcope/LikeOS
void press_slider(GuiObject * slid)
{
	GuiWindow *win;
	GuiWinThread *win_thread;
	int position, old_x, old_y;
	int x, y;
	int old_position = 0, on_bar = FALSE;
	
	check_object(slid, "slid", "press_slider");
	win = slid->win;
	check_window(win, "press_slider");
	win_thread = win->win_thread;
	old_x = slid->x;
	old_y = slid->y;
	x = mouse.x - win->x;
	y = mouse.y - win->y;

	if ((slid->type == HOR_SLIDER &&	/* on slider bar? */
	     x >= slid->x + slid->position &&
	     x <= slid->x + slid->position + slid->length) ||
	    (slid->type == VERT_SLIDER &&
	     y >= slid->y + slid->slider_length - slid->position - slid->length &&
	     y <= slid->y + slid->slider_length - slid->position)) {
		old_x = x;
		old_y = y - slid->slider_length;
		old_position = slid->position;
		on_bar = TRUE;
	}
	if (!on_bar && (slid->type == HOR_SLIDER || slid->type == VERT_SLIDER)) {
		if (slid->type == HOR_SLIDER) {
			if (x > slid->x + slid->position)
				move_slider(slid, 2);
			else
				move_slider(slid, -2);
		}
		if (slid->type == VERT_SLIDER) {
			if (y > slid->y + slid->slider_length - slid->position)
				move_slider(slid, -2);
			else
				move_slider(slid, +2);
		}
		return;
	}
	do {
		usleep(sleep_time);
		do_window_functions(win_thread);
		if (GuiGetMessage() == GuiMouseEvent) {
			move_mouse();
			x = mouse.x - win->x;
			y = mouse.y - win->y;
			position = old_position;
			if (slid->type == HOR_SLIDER || slid->type == NICE_HOR_SLIDER)
				position += x - old_x;
			else
				position += slid->slider_length - (y - old_y);
			if (position > slid->slider_length - slid->length)
					position = slid->slider_length - slid->length;
			if (position < 0)
				position = 0;
			slid->position = position;
			show_slider(slid);
			slid->object_callback(slid, slid->u_data);
		}
	}
	while (GuiMouseGetButton() == GuiMouseLeftButton);

	/* check for double click on slider bar */
	if (on_bar)
		check_double_click(slid);
}
コード例 #16
0
ファイル: mscursor.c プロジェクト: nidheeshdas/Algosim
void GrMouseUpdateCursor(void)
{
    if (MOUINFO->displayed && !MOUINFO->blockflag) {
        move_mouse();
    }
}
コード例 #17
0
ファイル: uManage.c プロジェクト: jcolag/uManage
void handle_alarm (int sig) {
    /*
     *     Check for new idling
     *     Accumulate total idle time per window use
     *     Check for changed window
     *     Log status if interesting
     *     Set for next iteration
     */
    void               *status;
    unsigned long       idle;               /* Idle time in ms */
    time_t              idle_dur;
#ifdef GUI
    int                 idx;
#endif

    if (sig != SIGALRM) {
        return;
    }
    signal(SIGALRM, SIG_IGN);

    if (opts.pause) {
        if (current.pause_since == 0) {
            time(&current.pause_since);
        }
        signal(SIGALRM, handle_alarm);
        alarm(opts.poll_period);
        return;
    }

    idle = idle_time();

    if (thr_wx_running < 0) {
        pthread_join(thr_wx, &status);
        thr_wx_running = 0;
    }
    time(&idle_dur);
    if(thr_wx_running == 0 &&
            opts.use_database &&
            idle_dur - current.weather_since > 60 * 60 * 10) {
        time(&current.weather_since);
        pthread_create(&thr_wx, NULL, get_weather_data, 0);
    }

    if(idle < current.last_idle) {
        /* New idle "session" */
        if(idle > opts.idle_threshold * (unsigned long)1000) {
            /* It has been long enough, so reset the idle timer */
            /* ...but round up. */
            time(&current.idle_start);
            current.idle_start -= (idle + 500) / 1000;
        }
        else if(current.idle_start != 0) {
            /* If we're tracking idle time and it grows, add it */
            time(&idle_dur);
            idle_dur -= current.idle_start;
            current.idle_accumulated += idle_dur;
            current.idle_start = 0;
        }
    }

#ifdef GUI
    for(idx = 0; idx < opts.menu_len; idx++) {
        if (opts.userdef[idx] == 1) {
            /* Newly active */
            time((time_t *)&opts.userdef[idx]);
        } else if (opts.userdef[idx] < 0) {
            /* Deactivated Option */
            time(&idle_dur);
            opts.userdef[idx] = -opts.userdef[idx];
            report_duration(current.csv, opts.time_format, (time_t *)&opts.userdef[idx], &idle_dur);
            if (opts.use_database) {
                write_duration_to_database(current.csv, opts.menu_items[idx], opts.cycle_db);
            }
            opts.userdef[idx] = 0;
        }
    }

    if(opts.jiggle != 0) {
        time(&idle_dur);
        /* We need to worry about jiggling the mouse */
        if(current.last_jiggle == 0) {
            time(&current.last_jiggle);
        } else if ((idle_dur - current.last_jiggle) / opts.mouse_period > 0) {
            move_mouse(opts.mouse_dist);
            current.last_jiggle = 0;
        }
    }

    if (current.jiggle_since == 0 && opts.jiggle != 0) {
        /* Feature turned on, needs to be tracked */
        time(&current.jiggle_since);
    } else if (current.jiggle_since != 0 && opts.jiggle == 0) {
        /* Feature turned off, emit duration */
        time(&idle_dur);
        report_duration(current.csv, opts.time_format, &current.jiggle_since, &idle_dur);
        current.jiggle_since = 0;
        if (opts.use_database) {
            write_keepalive_to_database(current.csv, opts.cycle_db);
        }
    }

    if (current.pause_since != 0 && opts.pause == 0) {
        /* Feature turned off, emit duration */
        time(&idle_dur);
        report_duration(current.csv, opts.time_format, &current.pause_since, &idle_dur);
        current.pause_since = 0;
        if (opts.use_database) {
            write_duration_to_database(current.csv, "Pause", opts.cycle_db);
        }
    }
#endif

    if(is_window_updated(&current, &poll_continue, opts.use_database)) {
        if (opts.use_database) {
            write_activity_to_database(current.csv, opts.cycle_db);
        }
        if (opts.text_out) {
            /* Flush in case someone monitors the output file */
            fprintf(report, "%s\n", current.csv);
            fflush(report);
        }
    }
    /* Reset this, so that we don't have problems exiting */
    current.force = 0;

    if(opts.poll_period < 1) {
        /* I might want to use this for one-off scripts */
        return;
    }
    signal(SIGALRM, handle_alarm);
    alarm(opts.poll_period);
}
コード例 #18
0
ファイル: tmouse.cpp プロジェクト: cout/consoletelnet
void TMouse::doMouse() {
	INPUT_RECORD InputRecord;
	DWORD Result;
	InputRecord.EventType = KEY_EVENT; // just in case
	while(InputRecord.EventType != MOUSE_EVENT) {
		if (!ReadConsoleInput(hConsole, &InputRecord, 1, &Result))
			return; // uh oh!  we don't know the starting coordinates!
	}
	if(InputRecord.Event.MouseEvent.dwButtonState == 0) return;
	if(!(InputRecord.Event.MouseEvent.dwButtonState &
		FROM_LEFT_1ST_BUTTON_PRESSED)) {
		Clipboard.Paste();
		return;
	}

	COORD screen_start = {0, 0};
    COORD start_coords = InputRecord.Event.MouseEvent.dwMousePosition;
	COORD end_coords = start_coords;
	BOOL done = FALSE;
	
	// init vars
	doMouse_init();
	int normal_bg = ini.get_normal_bg();
	int normal_fg = ini.get_normal_fg();
	if(normal_bg == -1) normal_bg = 0;		// FIX ME!!  This is just a hack
	if(normal_fg == -1) normal_fg = 7;
	normal = (normal_bg << 4) | normal_fg;
	inverse = (normal_fg << 4) | normal_bg;

	// make screen all one attribute
	FillConsoleOutputAttribute(hStdout, normal, ConsoleInfo.dwSize.X *
		ConsoleInfo.dwSize.Y, screen_start, &Result);
	
	while(!done) {

		switch (InputRecord.EventType) {
		case MOUSE_EVENT:
			switch(InputRecord.Event.MouseEvent.dwEventFlags) {
			case 0: // only copy if the mouse button has been released
				if(!InputRecord.Event.MouseEvent.dwButtonState) {
					doClip(start_coords, end_coords);
					done = TRUE;
				}
				break;
				
			case MOUSE_MOVED:
				end_coords = InputRecord.Event.MouseEvent.dwMousePosition;
				move_mouse(start_coords, end_coords);					
				break;
			}
			break;
		// If we are changing focus, we don't want to highlight anything
		// (Paul Brannan 9/2/98)
		case FOCUS_EVENT:
			return;			
		}
		
		WaitForSingleObject(hConsole, INFINITE);
		if (!ReadConsoleInput(hConsole, &InputRecord, 1, &Result))
			done = TRUE;
		
	}

	doMouse_cleanup();
}
コード例 #19
0
ファイル: main.c プロジェクト: cjhgo/sunsea-aka
//main
int main(int argc, char* argv[])
{
    int fd, fd_mouse;
    struct fb_var_screeninfo fb_var;
    int bits;
    int player_flag = -1;
    int i, j ;

    //open fb0
    fd = open("/dev/fb0", O_RDWR);
    if(fd < 0)
    {
        printf("open fb0 error!\n");
        exit(0);
    }

    ioctl(fd, FBIOGET_VSCREENINFO, &fb_var);
    w = fb_var.xres;
    h = fb_var.yres;
    bits = fb_var.bits_per_pixel;
    printf("Framebuffer:%d * %d\n", w ,h);
    printf("Bits:%d\n", bits);
    fbmem = mmap(0, w*h*sizeof(int), PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); 		//use 32
//	fbmem = mmap(0, w*h*sizeof(short), PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);		//use 16

    //draw background
    fb_bg(X - 30, Y - 30,  0xeedc82);
    fb_grid(X, Y,  0x000000);

    fb_small_black_point(7 * SPACE + X, 7 * SPACE + Y);
    fb_small_black_point(3 * SPACE + X, 3 * SPACE + Y);
    fb_small_black_point(11 * SPACE + X, 3 * SPACE + Y);
    fb_small_black_point(3 * SPACE + X, 11 * SPACE + Y);
    fb_small_black_point(11 * SPACE + X, 11 * SPACE + Y);

    fb_black_point(7 * SPACE + X, 7 * SPACE + Y);
    pos_flag[7][7] = 2;
    fb_num(chess_num++, 7 * SPACE + X, 7 * SPACE + Y, 0xffffff);

    //mouse
    fd_mouse = open_mouse();
    cx = w / 2;
    cy = h / 2;

    while(1)
    {
        move_mouse(&fd_mouse);
        player(&fd_mouse, &player_flag);

        if(player_flag == 0)
        {
            computer();						//computer
            player_flag = -1;
        }

    }

    close(fd_mouse);
    close(fd);

    return 0;
}