@@ -732,7 +732,7 @@ static PyObject *
732732PyCursesWindow_GetCh (PyCursesWindowObject * self , PyObject * args )
733733{
734734 int x , y ;
735- chtype rtn ;
735+ int rtn ;
736736
737737 switch (PyTuple_Size (args )) {
738738 case 0 :
@@ -758,7 +758,7 @@ static PyObject *
758758PyCursesWindow_GetKey (PyCursesWindowObject * self , PyObject * args )
759759{
760760 int x , y ;
761- chtype rtn ;
761+ int rtn ;
762762
763763 switch (PyTuple_Size (args )) {
764764 case 0 :
@@ -777,7 +777,11 @@ PyCursesWindow_GetKey(PyCursesWindowObject *self, PyObject *args)
777777 PyErr_SetString (PyExc_TypeError , "getkey requires 0 or 2 arguments" );
778778 return NULL ;
779779 }
780- if (rtn <=255 )
780+ if (rtn == ERR ) {
781+ /* getch() returns ERR in nodelay mode */
782+ PyErr_SetString (PyCursesError , "no input" );
783+ return NULL ;
784+ } else if (rtn <=255 )
781785 return Py_BuildValue ("c" , rtn );
782786 else
783787#if defined(__NetBSD__ )
@@ -1953,6 +1957,10 @@ PyCurses_KeyName(PyObject *self, PyObject *args)
19531957
19541958 if (!PyArg_ParseTuple (args ,"i ",& ch )) return NULL ;
19551959
1960+ if (ch < 0 ) {
1961+ PyErr_SetString (PyExc_ValueError , "invalid key number" );
1962+ return NULL ;
1963+ }
19561964 knp = keyname (ch );
19571965
19581966 return PyString_FromString ((knp == NULL ) ? "" : (char * )knp );
@@ -2347,16 +2355,16 @@ static PyObject *
23472355PyCurses_UngetCh (PyObject * self , PyObject * args )
23482356{
23492357 PyObject * temp ;
2350- chtype ch ;
2358+ int ch ;
23512359
23522360 PyCursesInitialised
23532361
23542362 if (!PyArg_ParseTuple (args ,"O;ch or int" ,& temp )) return NULL ;
23552363
23562364 if (PyInt_Check (temp ))
2357- ch = (chtype ) PyInt_AsLong (temp );
2365+ ch = (int ) PyInt_AsLong (temp );
23582366 else if (PyString_Check (temp ))
2359- ch = (chtype ) * PyString_AsString (temp );
2367+ ch = (int ) * PyString_AsString (temp );
23602368 else {
23612369 PyErr_SetString (PyExc_TypeError , "argument must be a ch or an int" );
23622370 return NULL ;
0 commit comments