mmask_t mousemask(mmask_t mask, mmask_t *oldmask) { PDC_LOG(("mousemask() - called\n")); if (oldmask) *oldmask = SP->_trap_mbe; /* The ncurses interface doesn't work with our move events, so filter them here */ mask &= ~(BUTTON1_MOVED | BUTTON2_MOVED | BUTTON3_MOVED); mouse_set(mask); return SP->_trap_mbe; }
void inputTest(WINDOW *win) { int w, h, bx, by, sw, sh, i, c, num = 0; int line_to_use = 3; char buffer[80]; WINDOW *subWin; static const char spinner[4] = "/-\\|"; int spinner_count = 0; wclear(win); getmaxyx(win, h, w); getbegyx(win, by, bx); sw = w / 3; sh = h / 3; if ((subWin = subwin(win, sh, sw, by + h - sh - 2, bx + w - sw - 2)) == NULL) return; #ifdef A_COLOR if (has_colors()) { init_pair(2, COLOR_WHITE, COLOR_RED); wbkgd(subWin, COLOR_PAIR(2) | A_BOLD); } else #endif wbkgd(subWin, A_BOLD); box(subWin, ACS_VLINE, ACS_HLINE); wrefresh(win); nocbreak(); wclear (win); mvwaddstr(win, 1, 1, "Press keys (or mouse buttons) to show their names"); mvwaddstr(win, 2, 1, "Press spacebar to finish"); wrefresh(win); keypad(win, TRUE); raw(); noecho(); wtimeout(win, 200); #ifdef PDCURSES mouse_set(ALL_MOUSE_EVENTS | REPORT_MOUSE_POSITION); PDC_save_key_modifiers(TRUE); // PDC_return_key_modifiers(TRUE); #endif curs_set(0); /* turn cursor off */ while (1) { while (1) { c = wgetch(win); if (c == ERR) { spinner_count++; if (spinner_count == 4) spinner_count = 0; mvwaddch(win, line_to_use, 3, spinner[spinner_count]); wrefresh(win); } else break; } #ifdef PDCURSES // wmove(win, line_to_use + 1, 18); // wclrtoeol(win); #endif mvwaddstr(win, line_to_use, 5, "Key Pressed: "); wclrtoeol(win); wprintw( win, "(%x) ", c); if( has_key( c)) wprintw(win, "%s", keyname(c)); else if (isprint(c) || c > 0xff) waddch( win, c); else wprintw(win, "%s", unctrl(c)); #ifdef PDCURSES if (c == KEY_MOUSE) { int button = 0, status = 0; request_mouse_pos(); if (BUTTON_CHANGED(1)) button = 1; else if (BUTTON_CHANGED(2)) button = 2; else if (BUTTON_CHANGED(3)) button = 3; else if (BUTTON_CHANGED(4)) /* added 21 Jan 2011: BJG */ button = 4; else if (BUTTON_CHANGED(5)) button = 5; if( button) status = (button > 3 ? Mouse_status.xbutton[(button) - 4] : Mouse_status.button[(button) - 1]); wmove(win, line_to_use, 5); wclrtoeol(win); wprintw(win, "Button %d: ", button); if (MOUSE_MOVED) waddstr(win, "moved: "); else if (MOUSE_WHEEL_UP) waddstr(win, "wheel up: "); else if (MOUSE_WHEEL_DOWN) waddstr(win, "wheel dn: "); else if (MOUSE_WHEEL_LEFT) waddstr(win, "wheel lt: "); else if (MOUSE_WHEEL_RIGHT) waddstr(win, "wheel rt: "); else if ((status & BUTTON_ACTION_MASK) == BUTTON_PRESSED) waddstr(win, "pressed: "); else if ((status & BUTTON_ACTION_MASK) == BUTTON_CLICKED) waddstr(win, "clicked: "); else if ((status & BUTTON_ACTION_MASK) == BUTTON_DOUBLE_CLICKED) waddstr(win, "double: "); else if ((status & BUTTON_ACTION_MASK) == BUTTON_TRIPLE_CLICKED) waddstr(win, "triple: "); else waddstr(win, "released: "); wprintw(win, "Posn: Y: %d X: %d", MOUSE_Y_POS, MOUSE_X_POS); if (button && (status & BUTTON_MODIFIER_MASK)) { if (status & BUTTON_SHIFT) waddstr(win, " SHIFT"); if (status & BUTTON_CONTROL) waddstr(win, " CONTROL"); if (status & BUTTON_ALT) waddstr(win, " ALT"); } } else if (PDC_get_key_modifiers()) { waddstr(win, " Modifier(s):"); if (PDC_get_key_modifiers() & PDC_KEY_MODIFIER_SHIFT) waddstr(win, " SHIFT"); if (PDC_get_key_modifiers() & PDC_KEY_MODIFIER_CONTROL) waddstr(win, " CONTROL"); if (PDC_get_key_modifiers() & PDC_KEY_MODIFIER_ALT) waddstr(win, " ALT"); if (PDC_get_key_modifiers() & PDC_KEY_MODIFIER_NUMLOCK) waddstr(win, " NUMLOCK"); } #endif wrefresh(win); if (c == ' ') break; line_to_use++; if( line_to_use == 10) line_to_use = 3; } wtimeout(win, -1); /* turn off timeout() */ curs_set(1); /* turn cursor back on */ #ifdef PDCURSES mouse_set(0L); PDC_save_key_modifiers(FALSE); // PDC_return_key_modifiers(FALSE); #endif wclear(win); mvwaddstr(win, 2, 1, "Press some keys for 5 seconds"); mvwaddstr(win, 1, 1, "Pressing ^C should do nothing"); wrefresh(win); werase(subWin); box(subWin, ACS_VLINE, ACS_HLINE); for (i = 0; i < 5; i++) { mvwprintw(subWin, 1, 1, "Time = %d", i); wrefresh(subWin); napms(1000); flushinp(); } delwin(subWin); werase(win); flash(); wrefresh(win); napms(500); flushinp(); mvwaddstr(win, 2, 1, "Press a key, followed by ENTER"); wmove(win, 9, 10); wrefresh(win); echo(); keypad(win, TRUE); raw(); wgetnstr(win, buffer, 3); flushinp(); wmove(win, 9, 10); wdelch(win); mvwaddstr(win, 4, 1, "The character should now have been deleted"); Continue(win); refresh(); wclear(win); echo(); buffer[0] = '\0'; mvwaddstr(win, 3, 2, "The window should have moved"); mvwaddstr(win, 4, 2, "This text should have appeared without you pressing a key"); mvwaddstr(win, 6, 2, "Enter a number then a string separated by space"); mvwin(win, 2, 1); wrefresh(win); mvwscanw(win, 7, 6, "%d %s", &num, buffer); mvwprintw(win, 8, 6, "String: %s Number: %d", buffer, num); Continue(win); refresh(); wclear(win); echo(); mvwaddstr(win, 3, 2, "Enter a 5 character string: "); wgetnstr(win, buffer, 5); mvwprintw(win, 4, 2, "String: %s", buffer); Continue(win); }
int main(int argc, char *argv[]) { WINDOW *win; int key, old_option = -1, new_option = 0, i; bool quit = FALSE; setlocale(LC_ALL, ""); if (initTest(&win, argc, argv)) return 1; for( i = 1; i < argc; i++) if( argv[i][0] == '-') switch( argv[i][1]) { case 'l': case 'L': setlocale( LC_ALL, argv[i] + 2); break; case 'i': case 'I': background_index = (short)atoi( argv[i] + 2); break; #ifdef PDCURSES case 'b': case 'B': PDC_set_blink( TRUE); break; case 'm': case 'M': PDC_return_key_modifiers( TRUE); break; case 'r': /* allow user-resizable windows */ { int min_lines, max_lines, min_cols, max_cols; if( sscanf( argv[i] + 2, "%d,%d,%d,%d", &min_lines, &max_lines, &min_cols, &max_cols) == 4) { ttytype[0] = min_lines; ttytype[1] = max_lines; ttytype[2] = min_cols; ttytype[3] = max_cols; } } break; #endif default: break; } #ifdef A_COLOR if (has_colors()) { init_pair(1, COLOR_WHITE, COLOR_BLUE); wbkgd(win, COLOR_PAIR(1)); } else #endif wbkgd(win, A_REVERSE); #ifdef PDCURSES /* for x11, sdl1, and win32a, treat the close of the windows as KEY_EXIT */ PDC_set_function_key( FUNCTION_KEY_SHUT_DOWN, KEY_EXIT ); #endif erase(); display_menu(old_option, new_option); while (1) { noecho(); keypad(stdscr, TRUE); raw(); #ifdef PDCURSES mouse_set(ALL_MOUSE_EVENTS | REPORT_MOUSE_POSITION); #endif key = getch(); switch(key) { #ifdef PDCURSES case KEY_MOUSE: { const int tmarg = (LINES - (MAX_OPTIONS + 2)) / 2; int selected_opt; request_mouse_pos(); selected_opt = MOUSE_Y_POS - tmarg; if( selected_opt >= 0 && selected_opt < MAX_OPTIONS) { old_option = new_option; new_option = selected_opt; display_menu( old_option, new_option); } } if( (Mouse_status.button[0] & BUTTON_ACTION_MASK) == BUTTON_DOUBLE_CLICKED) key = 10; else break; #endif case 10: case 13: case KEY_ENTER: old_option = -1; erase(); refresh(); (*command[new_option].function)(win); erase(); display_menu(old_option, new_option); break; case KEY_PPAGE: case KEY_HOME: old_option = new_option; new_option = 0; display_menu(old_option, new_option); break; case KEY_NPAGE: case KEY_END: old_option = new_option; new_option = MAX_OPTIONS - 1; display_menu(old_option, new_option); break; case KEY_UP: old_option = new_option; new_option = (new_option == 0) ? new_option : new_option - 1; display_menu(old_option, new_option); break; case KEY_DOWN: old_option = new_option; new_option = (new_option == MAX_OPTIONS - 1) ? new_option : new_option + 1; display_menu(old_option, new_option); break; case KEY_RESIZE: # ifdef PDCURSES resize_term(0, 0); # endif old_option = -1; erase(); display_menu(old_option, new_option); break; case 'Q': case 'q': quit = TRUE; } if (quit == TRUE) break; } delwin(win); endwin(); return 0; }
static void inputTest(WINDOW *win) { int answered; int repeat; int w, h, bx, by, sw, sh, i, c, num; char buffer[80]; WINDOW *subWin; wclear(win); getmaxyx(win, h, w); getbegyx(win, by, bx); sw = w / 3; sh = h / 3; if ((subWin = subwin(win, sh, sw, by + h - sh - 2, bx + w - sw - 2)) == NULL) return; #ifdef A_COLOR if (has_colors()) { init_pair(2, COLOR_WHITE, COLOR_RED); wbkgd(subWin, (chtype) COLOR_PAIR(2) | A_BOLD); } else wbkgd(subWin, A_BOLD); #else wbkgd(subWin, A_BOLD); #endif box(subWin, ACS_VLINE, ACS_HLINE); wrefresh(win); nocbreak(); MvWAddStr(win, 2, 1, "Press some keys for 5 seconds"); MvWAddStr(win, 1, 1, "Pressing ^C should do nothing"); wrefresh(win); werase(subWin); box(subWin, ACS_VLINE, ACS_HLINE); for (i = 0; i < 5; i++) { MvWPrintw(subWin, 1, 1, "Time = %d", i); wrefresh(subWin); napms(1000); flushinp(); } delwin(subWin); werase(win); flash(); wrefresh(win); napms(500); MvWAddStr(win, 2, 1, "Press a key, followed by ENTER"); wmove(win, 9, 10); wrefresh(win); echo(); noraw(); wgetch(win); flushinp(); wmove(win, 9, 10); wdelch(win); MvWAddStr(win, 4, 1, "The character should now have been deleted"); Continue(win); wclear(win); MvWAddStr(win, 1, 1, "Press keys (or mouse buttons) to show their names"); MvWAddStr(win, 2, 1, "Press spacebar to finish"); wrefresh(win); keypad(win, TRUE); raw(); noecho(); #if HAVE_TYPEAHEAD typeahead(-1); #endif #ifdef NCURSES_MOUSE_VERSION mousemask(ALL_MOUSE_EVENTS, (mmask_t *) 0); #endif #if defined(PDCURSES) mouse_set(ALL_MOUSE_EVENTS); #endif for (;;) { wmove(win, 3, 5); c = wgetch(win); wclrtobot(win); if (c >= KEY_MIN) wprintw(win, "Key Pressed: %s", keyname(c)); else if (isprint(c)) wprintw(win, "Key Pressed: %c", c); else wprintw(win, "Key Pressed: %s", unctrl(UChar(c))); #ifdef KEY_MOUSE if (c == KEY_MOUSE) { #if defined(NCURSES_MOUSE_VERSION) #define ButtonChanged(n) ((event.bstate) & NCURSES_MOUSE_MASK(1, 037)) #define ButtonPressed(n) ((event.bstate) & NCURSES_MOUSE_MASK(1, NCURSES_BUTTON_PRESSED)) #define ButtonDouble(n) ((event.bstate) & NCURSES_MOUSE_MASK(1, NCURSES_DOUBLE_CLICKED)) #define ButtonTriple(n) ((event.bstate) & NCURSES_MOUSE_MASK(1, NCURSES_TRIPLE_CLICKED)) #define ButtonRelease(n) ((event.bstate) & NCURSES_MOUSE_MASK(1, NCURSES_BUTTON_RELEASED)) MEVENT event; int button = 0; getmouse(&event); if (ButtonChanged(1)) button = 1; else if (ButtonChanged(2)) button = 2; else if (ButtonChanged(3)) button = 3; else button = 0; wmove(win, 4, 18); wprintw(win, "Button %d: ", button); if (ButtonPressed(button)) wprintw(win, "pressed: "); else if (ButtonDouble(button)) wprintw(win, "double: "); else if (ButtonTriple(button)) wprintw(win, "triple: "); else wprintw(win, "released: "); wprintw(win, " Position: Y: %d X: %d", event.y, event.x); #elif defined(PDCURSES) int button = 0; request_mouse_pos(); if (BUTTON_CHANGED(1)) button = 1; else if (BUTTON_CHANGED(2)) button = 2; else if (BUTTON_CHANGED(3)) button = 3; else button = 0; wmove(win, 4, 18); wprintw(win, "Button %d: ", button); if (MOUSE_MOVED) wprintw(win, "moved: "); else if ((BUTTON_STATUS(button) & BUTTON_ACTION_MASK) == BUTTON_PRESSED) wprintw(win, "pressed: "); else if ((BUTTON_STATUS(button) & BUTTON_ACTION_MASK) == BUTTON_DOUBLE_CLICKED) wprintw(win, "double: "); else wprintw(win, "released: "); wprintw(win, " Position: Y: %d X: %d", MOUSE_Y_POS, MOUSE_X_POS); #endif /* NCURSES_VERSION vs PDCURSES */ } #endif /* KEY_MOUSE */ wrefresh(win); if (c == ' ') break; } #if 0 nodelay(win, TRUE); wgetch(win); nodelay(win, FALSE); #endif #if defined(PDCURSES) mouse_set(0L); #endif refresh(); repeat = 0; do { static const char *fmt[] = { "%d %10s", "%d %[a-zA-Z]s", "%d %[][a-zA-Z]s", "%d %[^0-9]" }; char *format = strdup(fmt[(unsigned) repeat % SIZEOF(fmt)]); wclear(win); MvWAddStr(win, 3, 2, "The window should have moved"); MvWAddStr(win, 4, 2, "This text should have appeared without you pressing a key"); MvWPrintw(win, 6, 2, "Scanning with format \"%s\"", format); mvwin(win, 2 + 2 * (repeat % 4), 1 + 2 * (repeat % 4)); erase(); refresh(); wrefresh(win); echo(); noraw(); num = 0; *buffer = 0; answered = mvwscanw(win, 7, 6, format, &num, buffer); MvWPrintw(win, 8, 6, "String: %s Number: %d (%d values read)", buffer, num, answered); Continue(win); ++repeat; free(format); } while (answered > 0); }
int chkr_mouse_set(unsigned long ul) { return(mouse_set(ul)); }