// this function responds to mouse movement and provides information on how the object should be rotated // axis returns 1 or 2 (rotation about x or y axis) // dir returns 1 or -1, indicating the direction of rotation // return value of notdone = 1 except for click or drag in the lower left corner of the window int get_axis(int *axis, float *dir) { float x0,x1,y0,y1; int notdone; getmouse(&x0,&y0,¬done); if (!notdone) return notdone; getmouse(&x1,&y1,¬done); if (fabs(x1-x0) > fabs(y1-y0)) { *axis=2; if (x1>x0) { *dir = 1.; } else { *dir = -1; } }else { *axis=1; if (y1>y0) { *dir = -1.; } else { *dir = 1; } } return notdone; }
int main() { int xi,yi,xo,yo,x,y; int gdriver=DETECT,gmode; initgraph(&gdriver,&gmode,"D:\\BORLANDC\\BGI"); // int xmax=getmaxx(); // int ymax=getmaxy(); initmouse(); showmouse(); getmouse(&xi,&yi); getmouse(&xo,&yo); int h,r ; float m=pow((xo-xi),2); float n=pow((yo-yi),2); r=sqrt(m+n); xi=xi + ((xo-xi)/2); yi=yi +((yo-yi)/2); // circle(xi,yi,10); h=1-r; x=0;y=r; while(x<=y) { crc(x,y,xi,yi); if(h<0) { h=h+(2*x)+1 ; } else { h=h+(2*(x-y))+1 ; y=y-1; } x++; } getch(); closegraph(); return 0; }
static void postevent(SDL_Event *Event) { event_t event; switch (Event->type) { case SDL_KEYDOWN: event.type = ev_keydown; event.data1 = getkey(&Event->key.keysym); D_PostEvent(&event); break; case SDL_KEYUP: event.type = ev_keyup; event.data1 = getkey(&Event->key.keysym); D_PostEvent(&event); break; case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONUP: event.type = ev_mouse; event.data1 = getmouse(SDL_GetMouseState(NULL, NULL)); event.data2 = 0; event.data3 = 0; D_PostEvent(&event); break; case SDL_MOUSEMOTION: event.type = ev_mouse; event.data1 = getmouse(Event->motion.state); event.data2 = Event->motion.xrel << 5; event.data3 = -Event->motion.yrel << 5; D_PostEvent(&event); break; case SDL_QUIT: I_Exit(0); default: break; } }
void runner() { clearviewport(); fstream f3; f3.open("product",ios::app|ios::nocreate); f3.seekg(0); if(f3.fail()) { cmpdtls(); staff(); //outtextxy(40,40,"This is a deault file"); } int val; int x,y,btn; int cnr; showmouse(); int whcnt=0; do { pro[whcnt].getdata(); rep: showmouse(); draw(); getmouse(btn,x,y); draw(); while(!(btn&1)==1) { getmouse(btn,x,y); if(cnr==0) draw(); cnr++; } while((btn&1)==1) getmouse(btn,x,y); f3.write((char*)&pro[whcnt],sizeof(product)); whcnt++; if(!((x>450&&x<500&&y>450&&y<460)||(x>550&&x<600&&y>450&&y<460))) goto rep; }while((x>450&&x<500&&y>450&&y<460)); f3.close(); clearviewport(); }
int main(int argc, char *argv[]) { MEVENT mort; int ch; initscr(); refresh(); noecho(); keypad(stdscr, TRUE); mousemask(ALL_MOUSE_EVENTS, NULL); while(1) { ch = getch(); if(ch == KEY_MOUSE) { getmouse(&mort); move(0, 0); clrtoeol(); printw("%d\t%d", mort.y, mort.x); refresh(); continue; } if(ch == '\n') break; } endwin(); return 0; }
int main() { initscr(); char* menu[]={ "HONG SHAO YU", "HU PI JIAN JIAO", "XI HONG SI", "QUIT", NULL }; noecho(); WINDOW* w=newwin(7,14,(LINES-7)/2-1,(COLS-7)/2-1); showmenu(w,menu,-1); keypad(w,TRUE); mousemask(ALL_MOUSE_EVENTS,NULL); curs_set(0); while(1){ int ch=wgetch(w); if(ch!=KEY_MOUSE) continue; MEVENT e; getmouse(&e); if(e.bstate&BUTTON1_PRESSED){ mvprintw(0,0,"%02d %02d",e.y,e.x); } } endwin(); return 0; }
int _getmouse(lua_State* const state) { lua_settop(state, 0); MEVENT* event = lua::make<MEVENT>(state); getmouse(event); return 1; }
int main() { int x, y, c; MEVENT event; initscr(); curs_set(1); keypad(stdscr, TRUE); mousemask(ALL_MOUSE_EVENTS, NULL); initTable(); printTable(SIZE, SIZE); while (result == FALSE) { c = wgetch(stdscr); if (KEY_MOUSE == c) { if (OK == getmouse(&event)) { x = event.x; y = event.y; toggle_on_click(x, y); } } } start_color(); init_pair(1, COLOR_GREEN, COLOR_RED); attron(COLOR_PAIR(1)); printw("Wow You Win...."); getch(); endwin(); return 0; }
int main(void) { MEVENT mort; int ch; initscr(); noecho(); keypad(stdscr,TRUE); mousemask(BUTTON1_CLICKED,NULL); while(1) { ch = getch(); if( ch == KEY_MOUSE ) { getmouse(&mort); move(0,0); clrtoeol(); printw("Mouse clicked at %d, %d",mort.y,mort.x); refresh(); continue; } if( ch == '\n' ) break; } endwin(); return 0; }
void main_loop() { MEVENT event; int i; wdata_lock_mutex(&data); wdata_set_view(&data, config()->view); wdata_unlock_mutex(&data); for (;;) { wdata_lock_mutex(&data); draw(&data); wdata_unlock_mutex(&data); i = ui_getchar(); if (i == KEY_RESIZE) { handle_resize(); } else if (i == KEY_MOUSE) { if (getmouse(&event) == OK) { wdata_lock_mutex(&data); states_handlemouse(&data, &event); wdata_unlock_mutex(&data); } } else { wdata_lock_mutex(&data); states_handlekey(&data, i); wdata_unlock_mutex(&data); } } }
bool Listener::Impl::Listen() const { int key = getch(); switch(key) { case KEY_MOUSE: { MEVENT mouse_event; if(getmouse(&mouse_event) == OK) { //Call the callback if (m_mouse_callback) m_mouse_callback(mouse_event); return true; } break; } default: { if (m_keyboard_callback) { m_keyboard_callback(key); } return true; } } return false; }
static int term_getkey( ) { Term.mouse.justPressed = 0; Term.mouse.justReleased = 0; Term.mouse.justMoved = 0; while (1) { int got = getch(); if (got == KEY_RESIZE) { ensure_size( ); } else if (got == KEY_MOUSE) { MEVENT mevent; getmouse (&mevent); Term.mouse.x = mevent.x; Term.mouse.y = mevent.y; Term.mouse.shift = (mevent.bstate & BUTTON_SHIFT) != 0; Term.mouse.control = (mevent.bstate & BUTTON_CTRL) != 0; if (mevent.bstate & BUTTON1_PRESSED) { Term.mouse.justPressed = 1; Term.mouse.isPressed = 1; } else if (mevent.bstate & BUTTON1_RELEASED) { if (Term.mouse.isPressed) { Term.mouse.justReleased = 1; Term.mouse.isPressed = 0; } } else { Term.mouse.justMoved = 1; } return TERM_MOUSE; } else { if (got == KEY_ENTER) got = 13; // KEY_ENTER -> ^M for systems with odd values for KEY_ENTER if (got == ERR) return TERM_NONE; else return got; } } }
//pthread function void *thr_mouse() { MEVENT event; int ch; char smbuf[3]; int x, y; FILE* fp; while(1) { ch =getch(); if( ch== KEY_MOUSE) { getmouse(&event); y= event.y-2; x= event.x-2; if(x<14 && y<14 && x>0 && y>0) { if(is_33(x, y)) addlog("3x3 not allowed", 3,1); else if(board[y][x]!=0) addlog("try again", 3,1); else { smbuf[0]=y; smbuf[1]=x; smbuf[2]='\0'; fp = fdopen(pipefd[1],"w"); fprintf(fp,"%s",smbuf); fflush(fp); return; } } } } }
/* Determine if a mouse click occurred over one of the controls. */ static int getmouseevent(int *control) { MEVENT event; int i, x; if (getmouse(&event) != OK || event.bstate != BUTTON1_CLICKED) return 0; if (event.y >= yDice && event.y < yDice + cyDie) { x = xDice; for (i = ctl_dice ; i < ctl_dice_end ; ++i) { if (event.x >= x && event.x < x + cxDie) { *control = i; return 1; } x += cxDie + cxDieSpacing; } } if (event.y == yButton && event.x >= xButton && event.x < xButton + cxButton) { *control = ctl_button; return 1; } if (event.y >= ySlots && event.y < ySlots + cySlots) { if (event.x >= xSlots && event.x < xSlots + cxSlot) { *control = ctl_slots + (event.y - ySlots); return 1; } if (event.x >= xSlots + cxSlot + cxSlotSpacing && event.x < xSlots + cxSlot * 2 + cxSlotSpacing) { *control = ctl_slots + (ctl_slots_count / 2) + (event.y - ySlots); return 1; } } return 0; }
int check_enter_key_or_s(WINDOW *window) { switch(wgetch_nodelay(window)) { #if defined(KEY_MOUSE) && defined(ENABLE_MOUSE) case KEY_MOUSE: { MEVENT event; if(getmouse(&event) == OK) { /* When the user clicks left mouse button */ if((event.bstate & BUTTON1_CLICKED) || (event.bstate & BUTTON1_DOUBLE_CLICKED)) return 1; } } break; #endif case KEY_ENTER: #ifdef PADENTER case PADENTER: #endif case '\n': case '\r': case 's': case 'S': return 1; case 'F': return 2; } return 0; }
void InputManager::getInput() { int c = getch(); if (c != ERR) { MEVENT m_event; if ((c == KEY_MOUSE) && (getmouse(&m_event) != ERR)) { if (m_event.bstate & BUTTON1_CLICKED) { int y = m_event.y; int x = m_event.x; EventMouse m; m.setMouseY(y); m.setMouseX(x); m.setMouseAction(LEFT_BUTTON_CLICK); onEvent((Event*) &m); } } else { EventKeyboard k; k.setKey(c); onEvent((Event*) &k); } } }
int curses_get_mouse(int *mousex, int *mousey, int *mod) { int key = '\033'; #ifdef NCURSES_MOUSE_VERSION MEVENT event; if (getmouse(&event) == OK) { /* When the user clicks left mouse button */ if(event.bstate & BUTTON1_CLICKED) { /* See if coords are in map window & convert coords */ if (wmouse_trafo(mapwin, &event.y, &event.x, TRUE)) { key = 0; /* Flag mouse click */ *mousex = event.x; *mousey = event.y; if (curses_window_has_border(MAP_WIN)) { (*mousex)--; (*mousey)--; } *mod = CLICK_1; } } } #endif /* NCURSES_MOUSE_VERSION */ return key; }
static int get_m_evt_code(alphabet_game_t *alphabet_game,m_evt_code_t *m_evt_code) { alphabet_game_t *ag=alphabet_game; m_evt_code_t *mec=m_evt_code; if((NULL==ag)||(NULL==mec)){ return RET_FAILED; } init_m_evt_code(mec); int chr=NO_INPUT_DATA; mousemask(ALL_MOUSE_EVENTS,NULL); chr=wgetch(ag->scr.win); switch(chr){ case NO_INPUT_DATA://no need to deal //mvwprintw(ag->scr.win,8,1,"%s","NO_INPUT_DATA"); ag->m_evt_code.m_evt_type=M_EVT_NO_INPUT; ag->m_evt_code.m_evt_param.other_t.other=NO_INPUT_DATA; break; case KEY_MOUSE: //mouse event //mvwprintw(ag->scr.win,10,1,"%s","KEY_MOUSE"); ag->m_evt_code.m_evt_type=M_EVT_MOUSE; getmouse(&ag->m_evt_code.m_evt_param.mouse_t.mouse); break; default: //key event //mvwprintw(ag->scr.win,12,1,"%s---[%d]","KEY_EVENT",chr); ag->m_evt_code.m_evt_type=M_EVT_KEY; ag->m_evt_code.m_evt_param.key_t.key=chr; break; } return RET_SUCCESS; }
bool CWidget::focused() { #ifdef __PDCURSES__ // Update mouse position. Everytime we use mouse wheel, positions go to -1 for some reason... this fixes it. request_mouse_pos(); if(MOUSE_X_POS != -1 && MOUSE_Y_POS != -1) _mousePos.set(MOUSE_X_POS, MOUSE_Y_POS); #else MEVENT event; if(getmouse(&event) == OK) { if(event.x != -1 && event.y != -1) _mousePos.set(event.x, event.y); } #endif // Check if mouse cursor is inside the widget if(uint(_mousePos.y()) >= _pos.y() && uint(_mousePos.y()) < _pos.y() + _size.height() && uint(_mousePos.x()) >= _pos.x() && uint(_mousePos.x()) < _pos.x() + _size.width()) { return true; } return false; }
static void expand_on_mouse_click (void) { int ok_mouse; MEVENT event; ok_mouse = getmouse (&event); if (!conf.mouse_support || ok_mouse != OK) return; if (event.bstate & BUTTON1_CLICKED) { /* ignore header/footer clicks */ if (event.y < MAX_HEIGHT_HEADER || event.y == LINES - 1) return; if (set_module_from_mouse_event (&gscroll, dash, event.y)) return; reset_scroll_offsets (&gscroll); gscroll.expanded = 1; free_holder_by_module (&holder, gscroll.current); free_dashboard (dash); allocate_holder_by_module (gscroll.current); allocate_data (); render_screens (); } }
gint32 viper_kmio_fetch(MEVENT *mouse_event) { gint32 keystroke=-1; gint32 key_code=0; guint shift_op=4; #if !defined(_NO_GPM) && defined(__linux) viper_kmio_gpm(mouse_event,0); #endif key_code=getch(); if(key_code!=-1) { if(key_code!=27) { if(key_code==KEY_MOUSE) getmouse(mouse_event); return key_code; } keystroke=27; do { shift_op=shift_op<<1; key_code=getch(); if(key_code==-1) break; keystroke |= (key_code<<shift_op); } while(shift_op<24); } return keystroke; }
void dealMouse(BALL* ball) { static int iCapture = -1, mx, my; int i; mouse_msg mouse = {0}; while (mousemsg()) { double dx, dy; mouse = getmouse(); dx = (mouse.x - mx) * 1.0f; dy = (mouse.y - my) * 1.0f; mx = mouse.x; my = mouse.y; if(iCapture == -1 && mouse.msg == mouse_msg_down) { for(i = MAXBALL - 1; i > -1; --i) if(ball[i].resmouse(mouse, dx, dy)) { iCapture = i; break; } } else if (iCapture >= 0 && (mouse.msg == mouse_msg_up || mouse.msg == mouse_msg_move) ) { if(ball[iCapture].resmouse(mouse, dx, dy) == 0) iCapture = -1; } } if (iCapture >= 0) { mouse.msg = (mouse_msg_e)0; ball[iCapture].resmouse(mouse, 0, 0); } }
int main (void) { MEVENT pos; int l_mouse; chtype button; initscr(); noecho(); keypad(stdscr, TRUE); l_mouse = mousemask(BUTTON1_PRESSED, NULL); (void)l_mouse; while (1) { button = wgetch(stdscr); if (button == KEY_MOUSE) { if (getmouse(&pos) == OK) { wenclose(stdscr, pos.y, pos.x); mvwprintw(stdscr, 1, 0, "y = %2d x = %2d", pos.y, pos.x); } } wrefresh(stdscr); } endwin(); return 0; }
/*! \fn swMain::_prepare_mouse_ev( int nc ) */ Event* swMain::_prepare_mouse_ev( int nc ) { MEVENT mev; if(getmouse( &mev ) == ERR ) return 0l; MouseEvent* Mev = new MouseEvent( mev ); PostEvent( Mev ); return Mev; }
/* * Arrow keys move cursor, return location at current on non-arrow key. */ static PAIR * selectcell(WINDOW *parent, int uli, int ulj, int lri, int lrj) { static PAIR res; /* result cell */ int si = lri - uli + 1; /* depth of the select area */ int sj = lrj - ulj + 1; /* width of the select area */ int i = 0, j = 0; /* offsets into the select area */ res.y = uli; res.x = ulj; for (;;) { tail_line("Upper left [%2d,%2d] Lower right [%2d,%2d] -> %d,%d", uli, ulj, lri, lrj, uli + i, ulj + j); wmove(parent, uli + i, ulj + j); switch (wgetch(parent)) { case KEY_UP: i += si - 1; break; case KEY_DOWN: i++; break; case KEY_LEFT: j += sj - 1; break; case KEY_RIGHT: j++; break; case QUIT: case ESCAPE: return ((PAIR *) 0); #ifdef NCURSES_MOUSE_VERSION case KEY_MOUSE: { MEVENT event; getmouse(&event); if (event.y > uli && event.x > ulj) { i = event.y - uli; j = event.x - ulj; } else { beep(); break; } } /* FALLTHRU */ #endif default: res.y = uli + i; res.x = ulj + j; return (&res); } i %= si; j %= sj; } }
// 主函数 int main( int argc, char* argv[] ) { int i, ms_x = -1024, ms_y = -1024, exitflag = 0; int fps = 60; double dtime; int mode = preinit( argc, argv ); // 记录初始化模式 if ( mode < 0 ) return 0; randomize(); // 初始化随机种子 initgraph( -1, -1 ); // 打开图形窗口,以全屏模式 showmouse( mode ); sc_width = getwidth(); sc_heigh = getheight(); // 初始化所有星星 for ( i = 0; i < g_max; i++ ) { InitStar( i ); star[i].x = randomf(); } // 绘制星空,按任意键或移动鼠标退出 setfont( 12, 6, "宋体" ); setrendermode( RENDER_MANUAL ); dtime = fclock(); while ( kbmsg() ) getkey(); for ( ; !exitflag && is_run() && kbmsg() == 0; delay_fps( fps ) ) { //每秒画120帧,kbhit(1)是获取键盘任意键的消息,详见pdf // 如果有鼠标消息 while ( mousemsg() ) { mouse_msg msg = getmouse(); if ( ms_x <= -1024 ) { ms_x = msg.x; ms_y = msg.y; } // 处理鼠标,移动超出范围就退出 if ( mode == 0 ) { // 仅全屏模式才处理鼠标 int x = msg.x, y = msg.y; x -= ms_x; y -= ms_y; if ( x * x + y * y > 400 ) exitflag = 1; } } // 显示星星 double dt = 1.0 / fps; //fclock() - dtime; dtime += dt; for ( int i = 0; i < g_max; i++ ) { MoveStar( i, dt ); } // 显示FPS { char str[60]; sprintf( str, "%8.2f FPS", getfps()); outtextxy( 0, 0, str ); //显示fps } } closegraph(); // 关闭图形窗口 return 0; }
int wScreenMask::get_input () { MEVENT mouseinput; int input = getch (); if (input == KEY_MOUSE) { getmouse (&mouseinput); input = keymask[mouseinput.y][mouseinput.x]; } return input; }
/** * Recupere la position x et y de la souris. * @param[out] x la position en x * @param[out] y la position en y * @param[out] bouton l'évenement associé au clic * @return OK si reussite */ int souris_getpos(souris_t* souris) { MEVENT event; int resultat = getmouse(&event); if(resultat == OK) { souris->x = event.x; souris->y = event.y; souris->bouton = event.bstate; } return resultat; }
static int mouse_wgetch(WINDOW *win, int *fkey, bool ignore_errs) { int mouse_err = FALSE; int key; do { key = dlg_getc(win, fkey); #if USE_MOUSE mouse_err = FALSE; if (fkey && (key == KEY_MOUSE)) { MEVENT event; mseRegion *p; if (getmouse(&event) != ERR) { if ((p = dlg_mouse_region(event.y, event.x)) != 0) { key = DLGK_MOUSE(p->code); } else if ((p = dlg_mouse_bigregion(event.y, event.x)) != 0) { int x = event.x - p->x; int y = event.y - p->y; int row = (p->X - p->x) / p->step_x; key = -(p->code); switch (p->mode) { case 1: /* index by lines */ key += y; break; case 2: /* index by columns */ key += (x / p->step_x); break; default: case 3: /* index by cells */ key += (x / p->step_x) + (y * row); break; } } else { (void) beep(); mouse_err = TRUE; } } else { (void) beep(); mouse_err = TRUE; } } #endif } while (ignore_errs && mouse_err); return key; }
int main() { int c, choice = 0; WINDOW *menu_win; MEVENT event; /* 初始化 curses */ initscr(); clear(); noecho(); cbreak(); /* 禁用行缓冲,直接传递所有的信号 */ /* 将窗口放在屏幕中央 */ startx = (80 - WIDTH) / 2; starty = (24 - HEIGHT) / 2; attron(A_REVERSE); mvprintw(23, 1, "Click on Exit to quit (Works best in a virtual console)"); refresh(); attroff(A_REVERSE); /* 首先显示菜单 */ menu_win = newwin(HEIGHT, WIDTH, starty, startx); print_menu(menu_win, 1); /* 监听所有的鼠标事件 */ mousemask(ALL_MOUSE_EVENTS, NULL); while(1) { c = wgetch(menu_win); switch(c) { case KEY_MOUSE: if(getmouse(&event) == OK) { /* 用户按下鼠标左键 */ if(event.bstate & BUTTON1_PRESSED) { report_choice(event.x + 1, event.y + 1, &choice); if(choice == -1) /* 退出选项 */ goto end; mvprintw(22, 1, "Choice made is : %d String Chosen is \"%10s\"", choice, choices[choice - 1]); refresh(); } } print_menu(menu_win, choice); break; } } end: endwin(); return 0; }