+#ifdef USE_PTHREADS
+ /*
+ * We might have this situation in a multithreaded application that
+ * has wgetch() reading in more than one thread. putp() and below
+ * may use SP explicitly.
+ */
+ if (_nc_use_pthreads && sp != CURRENT_SCREEN) {
+ SCREEN *save_sp;
+
+ /* cannot use use_screen(), since that is not in tinfo library */
+ _nc_lock_global(curses);
+ save_sp = CURRENT_SCREEN;
+ _nc_set_screen(sp);
+ rc = _nc_keypad(sp, flag);
+ _nc_set_screen(save_sp);
+ _nc_unlock_global(curses);
+ } else
+#endif
+ {
+#ifdef USE_TERM_DRIVER
+ rc = CallDriver_1(sp, td_kpad, flag);
+ if (rc == OK)
+ sp->_keypad_on = flag;
+#else
+ if (flag) {
+ (void) NCURSES_PUTP2_FLUSH("keypad_xmit", keypad_xmit);
+ } else if (!flag && keypad_local) {
+ (void) NCURSES_PUTP2_FLUSH("keypad_local", keypad_local);
+ }
+
+ if (flag && !sp->_tried) {
+ _nc_init_keytry(sp);
+ sp->_tried = TRUE;
+ }
+ sp->_keypad_on = flag;
+ rc = OK;
+#endif