How to realize the waiting key function for joystick

As the title, i failed to find a function to wait the key from joystick.
i tried to imitate iohub.client.keyboard.waitForKeys like this:

def WaitJoyKeys(window, joy, key=1, maxwait=20):
key = 1
maxwait = 20
checkInterval = 0.002
start_time = core.getTime()
timeout = start_time+maxwait
while core.getTime() < timeout - checkInterval*2:
	ltime=core.getTime()
	#print ltime

	key_state = joy.getButton(1)
	window.flip(clearBuffer=False)

	if key_state: 
		return key_state
	sleep_dur=max(checkInterval-(core.getTime()-ltime),0.0001)
	time.sleep(sleep_dur)

	while core.getTime() < timeout:
		key_state = joy.getButton(1)
		window.flip(clearBuffer=False)

		if key_state:
			return key_state

Because only window.flip can keep joy.getButton working (i’ve tried window.dispatchAllWindowEvents but failed), i used window.filp(clearBuffer=False) to keep the stimuli in the screen, but the display is not satisfactory because of the blink.
So what kinds of function could i use to keep joy.getButton working except window.flip?