当前位置: 首页>>代码示例>>Python>>正文


Python Keyboard.get_key方法代码示例

本文整理汇总了Python中pygaze.keyboard.Keyboard.get_key方法的典型用法代码示例。如果您正苦于以下问题:Python Keyboard.get_key方法的具体用法?Python Keyboard.get_key怎么用?Python Keyboard.get_key使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pygaze.keyboard.Keyboard的用法示例。


在下文中一共展示了Keyboard.get_key方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: confirm_abort_experiment

# 需要导入模块: from pygaze.keyboard import Keyboard [as 别名]
# 或者: from pygaze.keyboard.Keyboard import get_key [as 别名]
	def confirm_abort_experiment(self):

		"""
		Asks for confirmation before aborting the experiment. Displays a
		confirmation screen, collects the response, and acts accordingly.

		Exceptions:
		Raises a response_error upon confirmation.

		Returns:
		False if no confirmation was given.
		"""

		# Display the confirmation screen
		scr = Screen(disptype=DISPTYPE)
		kb = Keyboard(timeout=5000)
		yc = DISPSIZE[1]/2
		xc = DISPSIZE[0]/2
		ld = 40 # Line height
		scr.draw_text(u'Really abort experiment?', pos=(xc, yc-3*ld))
		scr.draw_text(u'Press \'Y\' to abort', pos=(xc, yc-0.5*ld))
		scr.draw_text(u'Press any other key or wait 5s to go to setup', \
			pos=(xc, yc+0.5*ld))
		self.display.fill(scr)
		self.display.show()
		# process the response:
		try:
			key, time = kb.get_key()
		except:
			return False
		# if confirmation, close experiment
		if key == u'y':
			raise Exception(u'The experiment was aborted')
		self.eyelink_graphics.esc_pressed = False
		return False
开发者ID:AA33,项目名称:PyGaze,代码行数:37,代码来源:libeyelink.py

示例2: Display

# 需要导入模块: from pygaze.keyboard import Keyboard [as 别名]
# 或者: from pygaze.keyboard.Keyboard import get_key [as 别名]
disp = Display()
scr = Screen()

# input
tracker = EyeTracker(disp)
kb = Keyboard(keylist=None, timeout=None)

# calibrate
tracker.calibrate()

# starting screen
scr.clear()
scr.draw_text(text="Press Space to start")
disp.fill(scr)
disp.show()
kb.get_key(keylist=['space'], timeout=None, flush=True)


# # # # #
# VALIDATION

# loop through points
for i in range(len(CALIBPOINTS)):
	# get coordinate
	x, y = CALIBPOINTS[i]
	# draw calibration point
	scr.clear()
	scr.draw_fixation(fixtype='dot', pos=(x,y))
	disp.fill(scr)
	# start recording
	tracker.start_recording()
开发者ID:mattfloat,项目名称:EyeTribe_test,代码行数:33,代码来源:experiment.py

示例3: libeyelink

# 需要导入模块: from pygaze.keyboard import Keyboard [as 别名]
# 或者: from pygaze.keyboard.Keyboard import get_key [as 别名]

#.........这里部分代码省略.........
                "calibrate after recording has started!")

        # # # # #
        # EyeLink calibration and validation

        # attempt calibrate; confirm abort when esc pressed
        while True:
            self.eyelink_graphics.esc_pressed = False
            pylink.getEYELINK().doTrackerSetup()
            if not self.eyelink_graphics.esc_pressed:
                break
            self.confirm_abort_experiment()

        # If we are using the built-in EyeLink event detection, we don't need
        # the RMS calibration routine.
        if self.eventdetection == 'native':
            return

        # # # # #
        # RMS calibration

        # present instructions
        self.display.fill()  # clear display
        self.scr.draw_text(text= \
         "Noise calibration: please look at the dot\n\n(press space to start)",
         pos=(self.resolution[0]/2, int(self.resolution[1]*0.2)),
         center=True, fontsize=self.fontsize)
        self.scr.draw_fixation(fixtype='dot')
        self.display.fill(self.scr)
        self.display.show()
        self.scr.clear()  # clear screen again

        # wait for spacepress
        self.kb.get_key(keylist=['space'], timeout=None)

        # start recording
        self.log("PYGAZE RMS CALIBRATION START")
        self.start_recording()

        # show fixation
        self.display.fill()
        self.scr.draw_fixation(fixtype='dot')
        self.display.fill(self.scr)
        self.display.show()
        self.scr.clear()

        # wait for a bit, to allow participant to fixate
        clock.pause(500)

        # get samples
        # samplelist, prefilled with 1 sample to prevent sl[-1] from producing
        # an error; first sample will be ignored for RMS calculation
        sl = [self.sample()]
        t0 = clock.get_time()  # starting time
        while clock.get_time() - t0 < 1000:
            s = self.sample()  # sample
            if s != sl[-1] and s != (-1, -1) and s != (0, 0):
                sl.append(s)

        # stop recording
        self.log("PYGAZE RMS CALIBRATION END")
        self.stop_recording()

        # calculate RMS noise
        Xvar = []
        Yvar = []
开发者ID:neuropil,项目名称:PyGaze,代码行数:70,代码来源:libeyelink.py

示例4: SMItracker

# 需要导入模块: from pygaze.keyboard import Keyboard [as 别名]
# 或者: from pygaze.keyboard.Keyboard import get_key [as 别名]

#.........这里部分代码省略.........
			vres = iViewXAPI.iV_Validate()
			# handle validation errors
			if vres != 1:
				verr = errorstring(vres)
			else:
				verr = None
##				# TEST #
##				res = iViewXAPI.iV_GetAccuracyImage(byref(imageData))
##				self.log("IMAGEBUFFERSTART")
##				self.log(imageData.imageBuffer)
##				self.log("IMAGEBUFFERSTOP")
##				print("Image height: %s, image width: %s, image size: %s" % (imageData.imageHeight,imageData.imageWidth, imageData.imageSize))
##				print imageData.imageBuffer
##				########
		# handle calibration errors
		else:
			cerr = errorstring(cres)

		# return succes
		if cerr == None:
			print("libsmi.SMItracker.calibrate: calibration was succesful")
			if verr == None:
				print("libsmi.SMItracker.calibrate: validation was succesful")

				# present instructions
				self.disp.fill() # clear display
				self.screen.draw_text(text="Noise calibration: please look at the dot\n\n(press space to start)", pos=(self.dispsize[0]/2, int(self.dispsize[1]*0.2)), center=True)
				self.screen.draw_fixation(fixtype='dot')
				self.disp.fill(self.screen)
				self.disp.show()
				self.screen.clear() # clear screen again

				# wait for spacepress
				self.kb.get_key(keylist=['space'], timeout=None)

				# show fixation
				self.disp.fill()
				self.screen.draw_fixation(fixtype='dot')
				self.disp.fill(self.screen)
				self.disp.show()
				self.screen.clear()

				# wait for a bit, to allow participant to fixate
				clock.pause(500)

				# get samples
				sl = [self.sample()] # samplelist, prefilled with 1 sample to prevent sl[-1] from producing an error; first sample will be ignored for RMS calculation
				t0 = clock.get_time() # starting time
				while clock.get_time() - t0 < 1000:
					s = self.sample() # sample
					if s != sl[-1] and s != (-1,-1) and s != (0,0):
						sl.append(s)
				# calculate RMS noise
				Xvar = []
				Yvar = []
				for i in range(2,len(sl)):
					Xvar.append((sl[i][0]-sl[i-1][0])**2)
					Yvar.append((sl[i][1]-sl[i-1][1])**2)
				XRMS = (sum(Xvar) / len(Xvar))**0.5
				YRMS = (sum(Yvar) / len(Yvar))**0.5
				self.pxdsttresh = (XRMS, YRMS)

				# calculate pixels per cm
				pixpercm = (self.dispsize[0]/float(self.screensize[0]) + self.dispsize[1]/float(self.screensize[1])) / 2
				# get accuracy
				res = 0; i = 0
开发者ID:AA33,项目名称:PyGaze,代码行数:70,代码来源:libsmi.py

示例5: EyelinkGraphics

# 需要导入模块: from pygaze.keyboard import Keyboard [as 别名]
# 或者: from pygaze.keyboard.Keyboard import get_key [as 别名]

#.........这里部分代码省略.........

        """
		desc:
			Gets the mouse position and state.
			
		returns:
			desc:	A (pos, state) tuple.
			type:	tuple.		
		"""

        button, pos, time = self.mouse.get_clicked()
        if button == None:
            button = -1
        if pos == None:
            pos = self.mouse.get_pos()
        return pos, button

    def get_input_key(self):

        """
		Gets an input key.

		Returns:
		A list containing a single pylink key identifier.
		"""

        # Don't try to collect key presses when the display is no longer
        # available. This is necessary, because pylink polls key presses during
        # file transfer, which generally occurs after the display has been
        # closed.
        if not self.display_open:
            return None
        try:
            key, time = self.kb.get_key(keylist=None, timeout="default")
        except:
            self.esc_pressed = True
            key = "q"
        if key == None:
            return None
            # Escape functions as a 'q' with the additional esc_pressed flag
        if key == "escape":
            key = "q"
            self.esc_pressed = True
            # Process regular keys
        if key == "return":
            keycode = pylink.ENTER_KEY
            self.state = None
        elif key == "space":
            keycode = ord(" ")
        elif key == "q":
            keycode = pylink.ESC_KEY
            self.state = None
        elif key == "c":
            keycode = ord("c")
            self.state = "calibration"
        elif key == "v":
            keycode = ord("v")
            self.state = "validation"
        elif key == "a":
            keycode = ord("a")
        elif key == "i":
            self.extra_info = not self.extra_info
            keycode = 0
        elif key == "up":
            keycode = pylink.CURS_UP
        elif key == "down":
开发者ID:neuropil,项目名称:EyeTribe_test,代码行数:70,代码来源:eyelinkgraphics.py

示例6: EyeTribeTracker

# 需要导入模块: from pygaze.keyboard import Keyboard [as 别名]
# 或者: from pygaze.keyboard.Keyboard import get_key [as 别名]

#.........这里部分代码省略.........

	def calibrate(self):

		"""Calibrates the eye tracking system
		
		arguments
		None
		
		keyword arguments
		None

		returns
		success	-- returns True if calibration succeeded, or False if
				   not; in addition a calibration log is added to the
				   log file and some properties are updated (i.e. the
				   thresholds for detection algorithms)
		"""
		
		# CALIBRATION
		# determine the calibration points
		calibpoints = []
		for x in [0.1,0.5,0.9]:
			for y in [0.1,0.5,0.9]:
				calibpoints.append((int(x*self.dispsize[0]),int(y*self.dispsize[1])))
		random.shuffle(calibpoints)
		
		# show a message
		self.screen.clear()
		self.screen.draw_text(text="Press Space to start the calibration or Q to quit.")
		self.disp.fill(self.screen)
		self.disp.show()
		
		# wait for keyboard input
		key, keytime = self.kb.get_key(keylist=['q','space'], timeout=None, flush=True)
		if key == 'q':
			quited = True
		else:
			quited = False
		
		# run until the user is statisfied, or quits
		calibrated = False
		calibresult = None
		while not quited and not calibrated:
			# start a new calibration
			self.eyetribe.calibration.start(pointcount=len(calibpoints))
			
			# loop through calibration points
			for cpos in calibpoints:
				self.draw_calibration_target(cpos[0], cpos[1])
				# wait for a bit to allow participant to start looking at
				# the calibration point (#TODO: space press?)
				clock.pause(1000)
				# start calibration of point
				self.eyetribe.calibration.pointstart(cpos[0],cpos[1])
				# wait for a second
				clock.pause(1000)
				# stop calibration of this point
				result = self.eyetribe.calibration.pointend()
				# the final calibration point returns a dict (does it?)
				if type(result) == dict:
					calibresult = copy.deepcopy(result)
				# check if the Q key has been pressed
				if self.kb.get_key(keylist=['q'],timeout=10,flush=False)[0] == 'q':
					# abort calibration
					self.eyetribe.calibration.abort()
					# set quited variable and break this for loop
开发者ID:ajlambert,项目名称:PyGaze,代码行数:70,代码来源:libeyetribe.py

示例7:

# 需要导入模块: from pygaze.keyboard import Keyboard [as 别名]
# 或者: from pygaze.keyboard.Keyboard import get_key [as 别名]

# # # # #
# welcome

scr.draw_text("Welcome to the PyGaze Supertest!\n\nYou're going to be testing \
your PyGaze installation today, using this interactive tool. Press Space \
to start!\n\n\nP.S. If you see this, the following functions work: \
\n- Screen.draw_text \
\n- Disp.fill \
\n- Disp.show \
\nAwesome!")
disp.fill(scr)
t1 = disp.show()
log.write(["welcome", t1])
kb.get_key()


# # # # #
# test Keyboard

# test set_keylist, set_timeout and get_key
scr.clear()
scr.draw_text("The keylist has been set to ['1','5','e','s','left','space']; \
please confirm that you can press these keys and not any other key. Note that \
if you press Space, the test will advance to the next phase! \
\n\n\nThis tests: \
\n- Keyboard.set_keylist \
\n- Keyboard.get_key \
\n- Keyboatd.set_timeout")
disp.fill(scr)
开发者ID:AA33,项目名称:PyGaze,代码行数:32,代码来源:PyGaze_supertest.py

示例8: EyelinkGraphics

# 需要导入模块: from pygaze.keyboard import Keyboard [as 别名]
# 或者: from pygaze.keyboard.Keyboard import get_key [as 别名]

#.........这里部分代码省略.........
			return 'blue'
		return 'black'

	def draw_line(self, x1, y1, x2, y2, colorindex):

		"""Unused"""

		# Find out how this can be used
		print 'draw_line() %s %s %s %s' % (x1, y1, x2, y2)
		
	def draw_lozenge(self, x, y, width, height, colorindex):

		"""Unused"""

		# Find out how this can be used
		print 'draw_lozenge() %s %s %s %s' % (x, y, width, height)

	def get_mouse_state(self):

		"""Unused"""

		pass

	def get_input_key(self):

		"""
		Gets an input key.

		Returns:
		A list containing a single pylink key identifier.
		"""

		try:
			key, time = self.kb.get_key(keylist=None, timeout='default')
		except:
			self.esc_pressed = True
			key = 'q'
		if key == None:
			return None
		# Escape functions as a 'q' with the additional esc_pressed flag
		if key == 'escape':
			key = 'q'
			self.esc_pressed = True
		# Process regular keys
		if key == "return":
			keycode = pylink.ENTER_KEY
			self.state = None
		elif key == "space":
			keycode = ord(" ")
		elif key == "q":
			keycode = pylink.ESC_KEY
			self.state = None
		elif key == "c":
			keycode = ord("c")
			self.state = "calibration"
		elif key == "v":
			keycode = ord("v")
			self.state = "validation"
		elif key == "a":
			keycode = ord("a")
		elif key == "up":
			keycode = pylink.CURS_UP
		elif key == "down":
			keycode = pylink.CURS_DOWN
		elif key == "left":
			keycode = pylink.CURS_LEFT
开发者ID:AA33,项目名称:PyGaze,代码行数:70,代码来源:eyelinkgraphics.py

示例9:

# 需要导入模块: from pygaze.keyboard import Keyboard [as 别名]
# 或者: from pygaze.keyboard.Keyboard import get_key [as 别名]

# # # # #
# welcome

scr.draw_text("Welcome to the PyGaze Supertest!\n\nYou're going to be testing \
your PyGaze installation today, using this interactive tool. Press Space \
to start!\n\n\nP.S. If you see this, the following functions work: \
\n- Screen.draw_text \
\n- Disp.fill \
\n- Disp.show \
\nAwesome!")
disp.fill(scr)
t1 = disp.show()
log.write(["welcome", t1])
kb.get_key()


# # # # #
# test EyeTracker

#EyeTracker.connected
#EyeTracker.log_var
#EyeTracker.pupil_size
#EyeTracker.send_command
#EyeTracker.wait_for_event

scr.clear()
scr.draw_text("We're now going to test the eyetracker module. Press Space to start!")
disp.fill(scr)
t1 = disp.show()
开发者ID:AA33,项目名称:PyGaze,代码行数:32,代码来源:PyGaze_trackertest.py

示例10: Dummy

# 需要导入模块: from pygaze.keyboard import Keyboard [as 别名]
# 或者: from pygaze.keyboard.Keyboard import get_key [as 别名]
class Dummy(DumbDummy):

	"""A dummy class to run experiments in dummy mode, where eye movements are simulated by the mouse"""
	

	def __init__(self, display):

		"""Initiates an eyetracker dummy object, that simulates gaze position using the mouse
		
		arguments
		display		--	a pygaze display.Display instance
		
		keyword arguments
		None
		"""

		# try to copy docstrings (but ignore it if it fails, as we do
		# not need it for actual functioning of the code)
		try:
			copy_docstr(BaseEyeTracker, Dummy)
		except:
			# we're not even going to show a warning, since the copied
			# docstring is useful for code editors; these load the docs
			# in a non-verbose manner, so warning messages would be lost
			pass

		self.recording = False
		self.blinking = False
		self.bbpos = (settings.DISPSIZE[0]/2, settings.DISPSIZE[1]/2)
		self.resolution = settings.DISPSIZE[:]
		self.simulator = Mouse(disptype=settings.DISPTYPE, mousebuttonlist=None,
			timeout=2, visible=False)
		self.kb = Keyboard(disptype=settings.DISPTYPE, keylist=None,
			timeout=None)
		self.angrybeep = Sound(osc='saw',freq=100, length=100, attack=0,
			decay=0, soundfile=None)
		self.display = display
		self.screen = Screen(disptype=settings.DISPTYPE, mousevisible=False)

	def calibrate(self):

		"""Dummy calibration"""

		print("Calibration would now take place")
		clock.pause(1000)

	def drift_correction(self, pos=None, fix_triggered=False):

		"""Dummy drift correction"""

		print("Drift correction would now take place")
		
		if fix_triggered:
			return self.fix_triggered_drift_correction(pos)
		
		if pos == None:
			pos = settings.DISPSIZE[0] / 2, settings.DISPSIZE[1] / 2

		# show mouse
		self.simulator.set_visible(visible=True)
		
		# show fixation dot
		self.draw_drift_correction_target(pos[0], pos[1])

		# perform drift check
		errdist = 60 # pixels (on a 1024x768px and 39.9x29.9cm monitor at 67 cm, this is about 2 degrees of visual angle)
		pressed = None
		while True:
			# check for keyboard input
			pressed, presstime = self.kb.get_key(keylist=['q','escape','space'], timeout=1)
			
			# quit key
			if pressed in ['q','escape']:
				# hide mouse
				self.simulator.set_visible(visible=False)
				return False
				
			# space bar
			elif pressed == 'space':
				# get sample
				gazepos = self.sample()
				# sample is close enough to fixation dot
				if ((gazepos[0]-pos[0])**2  + (gazepos[1]-pos[1])**2)**0.5 < errdist:
					# hide mouse
					self.simulator.set_visible(visible=False)
					return True
				# sample is NOT close enough to fixation dot
				else:
					# show discontent
					self.angrybeep.play()


	def fix_triggered_drift_correction(self, pos=None, min_samples=30, max_dev=60, reset_threshold=10):

		"""Dummy drift correction (fixation triggered)"""

		print("Drift correction (fixation triggered) would now take place")

		if pos == None:
			pos = settings.DISPSIZE[0] / 2, settings.DISPSIZE[1] / 2
#.........这里部分代码省略.........
开发者ID:esdalmaijer,项目名称:PyGaze,代码行数:103,代码来源:libdummytracker.py


注:本文中的pygaze.keyboard.Keyboard.get_key方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。