def process_keys(remote, xbmc):
 done = 0
 try:
  xbmc.previous_key
 except:
  xbmc.previous_key = ''
 xbmc.connect()
 datalen = 0
 try:
  data = remote.recv(1024)
  datalen = len(data)
 except Exception as e:
  if (str(e) == 'timed out'):
   return 2
  time.sleep(2)
  raise e
 if (datalen == 13):
  keycode = data.encode('hex')[10:12]
  if (keycode == 'ff'):
   xbmc.release_button()
   return done
  try:
   if (xbmc.previous_key == '43'):
    xbmc.previous_key = keycode
    if (keycode == '31'):
     return 3
    elif (keycode == '30'):
     return 4
   xbmc.previous_key = keycode
   if g_keymap[keycode]:
    xbmc.send_remote_button(g_keymap[keycode])
  except Exception as e:
   print ('Unknown data: %s' % str(e))
 return done

def process_keys ( remote , xbmc ) : done = 0 try : xbmc . previous_key except : xbmc . previous_key = '' xbmc . connect ( ) datalen = 0 try : data = remote . recv ( 1024 ) datalen = len ( data ) except Exception as e : if ( str ( e ) == 'timed out' ) : return 2 time . sleep ( 2 ) raise e if ( datalen == 13 ) : keycode = data . encode ( 'hex' ) [ 10 : 12 ] if ( keycode == 'ff' ) : xbmc . release_button ( ) return done try : if ( xbmc . previous_key == '43' ) : xbmc . previous_key = keycode if ( keycode == '31' ) : return 3 elif ( keycode == '30' ) : return 4 xbmc . previous_key = keycode if g_keymap [ keycode ] : xbmc . send_remote_button ( g_keymap [ keycode ] ) except Exception as e : print ( 'Unknown data: %s' % str ( e ) ) return done
return codes: 0 - key was processed normally 2 - socket read timeout 3 - ps and then skip plus was pressed 4 - ps and then skip minus was pressed fixme: move to enums .