本文整理汇总了Python中pygame.KMOD_SHIFT属性的典型用法代码示例。如果您正苦于以下问题:Python pygame.KMOD_SHIFT属性的具体用法?Python pygame.KMOD_SHIFT怎么用?Python pygame.KMOD_SHIFT使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类pygame
的用法示例。
在下文中一共展示了pygame.KMOD_SHIFT属性的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _pygame_update_modifiers
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import KMOD_SHIFT [as 别名]
def _pygame_update_modifiers(self, mods=None):
# Available mod, from dir(pygame)
# 'KMOD_ALT', 'KMOD_CAPS', 'KMOD_CTRL', 'KMOD_LALT',
# 'KMOD_LCTRL', 'KMOD_LMETA', 'KMOD_LSHIFT', 'KMOD_META',
# 'KMOD_MODE', 'KMOD_NONE'
if mods is None:
mods = pygame.key.get_mods()
self._modifiers = []
if mods & (pygame.KMOD_SHIFT | pygame.KMOD_LSHIFT):
self._modifiers.append('shift')
if mods & (pygame.KMOD_ALT | pygame.KMOD_LALT):
self._modifiers.append('alt')
if mods & (pygame.KMOD_CTRL | pygame.KMOD_LCTRL):
self._modifiers.append('ctrl')
if mods & (pygame.KMOD_META | pygame.KMOD_LMETA):
self._modifiers.append('meta')
示例2: _handle_mods
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import KMOD_SHIFT [as 别名]
def _handle_mods(self) -> None:
"""Update key mods"""
mods = pygame.key.get_mods()
self._modifiers.shift = mods & pygame.KMOD_SHIFT
self._modifiers.ctrl = mods & pygame.KMOD_CTRL
self._modifiers.alt = mods & pygame.KMOD_ALT
示例3: handleKeyDown
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import KMOD_SHIFT [as 别名]
def handleKeyDown(self,key,unicode):
""" Handles keypresses and determine which keys are valid for TextBox input type """
# If not editable nothing to do
if not self.editable: return
# Check if textbox was clicked and in editmode
if self.cursorActive:
# We are handling this so clear queue for others
pygame.event.clear()
# If all is selected each key will clear textbox
if self.allSelected:
self.text = ""
self.allSelected = False
# Process navigation (left,right) and modify (del, backspace) keys
if key == K_BACKSPACE:
if self.cursorChar == 0: return
self.text = self.text[0:self.cursorChar - 1] + self.text[self.cursorChar:]
self.cursorChar = self.cursorChar - 1
if self.cursorChar < 0: self.cursorChar = 0
return
if key == K_DELETE:
if self.cursorChar==len(self.text): return
self.text = self.text[0:self.cursorChar] + self.text[self.cursorChar + 1:]
return
if key == K_LEFT:
self.cursorChar = self.cursorChar - 1
if self.cursorChar < 0: self.cursorChar = 0
return
if key == K_RIGHT:
self.cursorChar = self.cursorChar + 1
if self.cursorChar > len(self.text): self.cursorChar = len(self.text)
return
# On enter/return call use function with current text and the (unmodified) metadata we received when initialized
if key == K_KP_ENTER or key == K_RETURN:
if not self.onEnter == None: self.onEnter(self, self.text,self.linkedData)
return# we don't want to add return char (chr 13) to text string
# Remap keys of numpad to numerical keys
isNumlockOn=(pygame.key.get_mods() & pygame.KMOD_NUM) ==4096
#print ("isNumlockOn: ",isNumlockOn)
if isNumlockOn:
if key in range(K_KP0,K_KP9+1):
key=K_0+(key-K_KP0)
if key == K_KP_PERIOD: key = K_PERIOD
# Check for valid input depending on input type the user selected when initialized
if not self.inputType==self.TEXT and (pygame.key.get_mods() & pygame.KMOD_SHIFT): return #shift (uppercase and specials chars only allowed in text
if self.inputType==self.INT and key==K_PERIOD: return #float/period not allowed if int
if self.inputType==self.INT or self.inputType==self.FLOAT:
if key not in range(K_0,K_COLON) and not key==K_PERIOD: return #only numbers/period allowed for int/float
if self.inputType==self.HEX and (key not in range (K_0,K_9) and key not in range(K_a,K_f)): return
if self.inputType==self.FLOAT and (key==K_KP_PERIOD or key==K_PERIOD) and "." in self.text:return # only allow one . in a float
# Process the input which made it through the validation block above
if len(self.text)<self.maxlength:
if self.inputType==self.HEX: unicode=unicode.upper() #if hex we want uppercase characters
self.text=self.text[0:self.cursorChar]+unicode+self.text[self.cursorChar:]
self.cursorChar=self.cursorChar+1