本文整理匯總了Python中pyatspi.Registry.generateKeyboardEvent方法的典型用法代碼示例。如果您正苦於以下問題:Python Registry.generateKeyboardEvent方法的具體用法?Python Registry.generateKeyboardEvent怎麽用?Python Registry.generateKeyboardEvent使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pyatspi.Registry
的用法示例。
在下文中一共展示了Registry.generateKeyboardEvent方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_image_video_mix
# 需要導入模塊: from pyatspi import Registry [as 別名]
# 或者: from pyatspi.Registry import generateKeyboardEvent [as 別名]
def test_image_video_mix(self):
files = ["1sec_simpsons_trailer.mp4", "flat_colour2_640x480.png",
"flat_colour4_1600x1200.jpg", "flat_colour1_640x480.png",
"flat_colour3_320x180.png", "flat_colour5_1600x1200.jpg"]
samples = self.import_media_multiple(files)
seektime = self.search_by_text("0:00:00.000", self.pitivi, roleName="text")
timeline = self.get_timeline()
tpos = timeline.position
#One video, one image
for sample in samples[1:]:
self.insert_clip(sample)
self.insert_clip(samples[0])
end = self.search_clip_end(30, seektime, timeline)
cend = end / 11.139
dogtail.rawinput.absoluteMotion(tpos[0] + cend - 2, tpos[1] + 30)
registry.generateKeyboardEvent(dogtail.rawinput.keyNameToKeyCode("Shift_L"), None, KEY_PRESS)
dogtail.rawinput.press(tpos[0] + cend - 2, tpos[1] + 30)
sleep(0.5)
dogtail.rawinput.absoluteMotion(tpos[0] + cend - 40, tpos[1] + 30)
sleep(0.5)
dogtail.rawinput.release(tpos[0] + cend - 40, tpos[1] + 30)
registry.generateKeyboardEvent(dogtail.rawinput.keyNameToKeyCode("Shift_L"), None, KEY_RELEASE)
self.nextb.click()
self.assertNotEqual(seektime.text, "0:00:11.139")
示例2: test_image_video_mix
# 需要導入模塊: from pyatspi import Registry [as 別名]
# 或者: from pyatspi.Registry import generateKeyboardEvent [as 別名]
def test_image_video_mix(self):
files = [
"tears of steel.webm",
"flat_colour2_640x480.png",
"flat_colour4_1600x1200.jpg",
"flat_colour1_640x480.png",
"flat_colour3_320x180.png",
"flat_colour5_1600x1200.jpg",
]
samples = self.import_media_multiple(files)
timecode_widget = self.viewer.child(name="timecode_entry").child(roleName="text")
tpos = self.timeline.position
# One video, one image
for sample in samples[1:]:
self.insert_clip(sample)
self.insert_clip(samples[0])
sleep(0.3)
end = self.search_clip_end(30, timecode_widget, self.timeline)
cend = end / 11.139
dogtail.rawinput.absoluteMotion(tpos[0] + cend - 2, tpos[1] + 30)
registry.generateKeyboardEvent(dogtail.rawinput.keyNameToKeyCode("Shift_L"), None, KEY_PRESS)
dogtail.rawinput.press(tpos[0] + cend - 2, tpos[1] + 30)
sleep(0.5)
dogtail.rawinput.absoluteMotion(tpos[0] + cend - 40, tpos[1] + 30)
sleep(0.5)
dogtail.rawinput.release(tpos[0] + cend - 40, tpos[1] + 30)
registry.generateKeyboardEvent(dogtail.rawinput.keyNameToKeyCode("Shift_L"), None, KEY_RELEASE)
self.goToEnd_button.click()
self.assertNotEqual(timecode_widget.text, "0:00:11.139")
示例3: import_media_multiple
# 需要導入模塊: from pyatspi import Registry [as 別名]
# 或者: from pyatspi.Registry import generateKeyboardEvent [as 別名]
def import_media_multiple(self, files):
dogtail.rawinput.pressKey("Esc") # Ensure the welcome dialog is closed
self.import_button.click()
import_dialog = self.pitivi.child(name="Select One or More Files",
roleName="file chooser", recursive=False)
path_toggle = import_dialog.child(
name="Type a file name", roleName="toggle button")
if not path_toggle.checked:
path_toggle.click()
dir_path = os.path.realpath(__file__).split(
"dogtail_scripts/")[0] + "samples/"
import_dialog.child(roleName='text').text = dir_path
time.sleep(0.2)
dogtail.rawinput.pressKey("Enter")
# We are now in the samples directory, select various items.
# We use Ctrl click to select multiple items. However, since the first
# row of the filechooser is always selected by default, we must not use
# ctrl when selecting the first item of our list, in order to deselect.
ctrl_code = dogtail.rawinput.keyNameToKeyCode("Control_L")
file_list = import_dialog.child(name="Files", roleName="table")
first = True
for f in files:
time.sleep(0.5)
file_list.child(name=f).click()
if first:
registry.generateKeyboardEvent(ctrl_code, None, KEY_PRESS)
first = False
registry.generateKeyboardEvent(ctrl_code, None, KEY_RELEASE)
import_dialog.button('Add').click()
current_search_text = self.medialibrary.child(
name="media_search_entry", roleName="text").text.lower()
if current_search_text != "":
# Failure to find some icons might be because of search filtering.
# The following avoids searching for files that can't be found.
for f in files:
if current_search_text not in f.lower():
files.remove(f)
# Check if non-filtered items are now visible in the media library.
samples = []
for i in range(5):
# The time it takes for icons to appear is unpredictable,
# therefore we try up to 5 times to look for them
icons = self.medialibrary.findChildren(
GenericPredicate(roleName="icon"))
for icon in icons:
for f in files:
if icon.text == f:
samples.append(icon)
files.remove(f)
if len(files) == 0:
break
time.sleep(0.5)
return samples
示例4: pressKey
# 需要導入模塊: from pyatspi import Registry [as 別名]
# 或者: from pyatspi.Registry import generateKeyboardEvent [as 別名]
def pressKey(keyName):
"""
Presses (and releases) the key specified by keyName.
keyName is the English name of the key as seen on the keyboard. Ex: 'enter'
Names are looked up in Gdk.KEY_ If they are not found there, they are
looked up by uniCharToKeySym().
"""
keySym = keyNameToKeySym(keyName)
registry.generateKeyboardEvent(keySym, None, KEY_SYM)
doTypingDelay()
示例5: ripple_roll
# 需要導入模塊: from pyatspi import Registry [as 別名]
# 或者: from pyatspi.Registry import generateKeyboardEvent [as 別名]
def ripple_roll(self, from_percent, to_percent):
dogtail.rawinput.click(self.getTimelineX(from_percent), self.getTimelineY(0))
sleep(0.1)
registry.generateKeyboardEvent(dogtail.rawinput.keyNameToKeyCode("Shift_L"), None, KEY_PRESS)
try:
dogtail.rawinput.press(self.getTimelineX(from_percent), self.getTimelineY(0))
dogtail.rawinput.absoluteMotion(self.getTimelineX(to_percent), self.getTimelineY(0))
sleep(0.1)
dogtail.rawinput.release(self.getTimelineX(to_percent), self.getTimelineY(0))
finally:
registry.generateKeyboardEvent(dogtail.rawinput.keyNameToKeyCode("Shift_L"), None, KEY_RELEASE)
sleep(0.1)
示例6: key_down
# 需要導入模塊: from pyatspi import Registry [as 別名]
# 或者: from pyatspi.Registry import generateKeyboardEvent [as 別名]
def key_down(self, key):
"""
This is a more specific function than keyboard(). It can send specific
key-pressed events, in case you want to do keyboard combinations, like Alt+F4
The argument can only be a string. If you want to send (e.g.) Alt+F4 then you
should call it as:
key_down("Alt")
key_down("F4")
time.sleep(0.2)
key_up("Alt")
key_up("F4")
"""
if key in key_list:
controller.generateKeyboardEvent(key_codes[key_list.index(key)], None, KEY_PRESS)
示例7: keyboard
# 需要導入模塊: from pyatspi import Registry [as 別名]
# 或者: from pyatspi.Registry import generateKeyboardEvent [as 別名]
def keyboard(key):
"""
> Description
Type some text or special keys, like Backspaces, Returns etc
For all the available keys look into `Macro.KEY_LIST`
> Parameters
key (string/list): If the `key` is a string, then it is simpy typed out. If it is a list of strings, every string in the list will be typed out. If a string in the list starts with `@@` then it is recognized as a special key and it is not typed out as is
> Returns
None
> Example
sentence = 'alex is awesome'
# types out 'alex is awesome'
Macro.keyboard(sentence)
# types out '@@BackSpace'
Macro.keyboard('@@BackSpace')
# sends a backspace (deletes a character)
Macro.keyboard(['@@BackSpace'])
# types out 'alex is awesome' and then proceeds to go to the next line
Macro.keyboard([sentence, '@@Return'])
"""
if type(key) is str:
for i in key:
Macro. __generate(i)
elif type(key) in [tuple, list]:
for inner_str in key:
if inner_str.startswith('@@'):
inner_str = inner_str[2:]
if inner_str in Macro.KEY_LIST:
controller.generateKeyboardEvent(Macro.KEY_LIST[inner_str], None, KEY_PRESS)
time.sleep(0.01)
controller.generateKeyboardEvent(Macro.KEY_LIST[inner_str], None, KEY_RELEASE)
else:
print 'Annotated key \'' + inner_str + '\' does not exist in my key list'
else:
for i in inner_str:
Macro. __generate(i)
示例8: keyCombo
# 需要導入模塊: from pyatspi import Registry [as 別名]
# 或者: from pyatspi.Registry import generateKeyboardEvent [as 別名]
def keyCombo(comboString):
"""
Generates the appropriate keyboard events to simulate a user pressing the
specified key combination.
comboString is the representation of the key combo to be generated.
e.g. '<Control><Alt>p' or '<Control><Shift>PageUp' or '<Control>q'
"""
strings = []
for s in comboString.split('<'):
if s:
for S in s.split('>'):
if S:
S = keyNameAliases.get(S.lower(), S)
strings.append(S)
for s in strings:
if not hasattr(Gdk, s):
if not hasattr(Gdk, 'KEY_' + s):
raise ValueError("Cannot find key %s" % s)
modifiers = strings[:-1]
finalKey = strings[-1]
for modifier in modifiers:
code = keyNameToKeyCode(modifier)
registry.generateKeyboardEvent(code, None, KEY_PRESS)
code = keyNameToKeyCode(finalKey)
registry.generateKeyboardEvent(code, None, KEY_PRESSRELEASE)
for modifier in modifiers:
code = keyNameToKeyCode(modifier)
registry.generateKeyboardEvent(code, None, KEY_RELEASE)
doDelay()
示例9: key_up
# 需要導入模塊: from pyatspi import Registry [as 別名]
# 或者: from pyatspi.Registry import generateKeyboardEvent [as 別名]
def key_up(key):
"""
> Description
Hold a specific key up, useful when you want to do key combinations, like Alt + Shift to change the current keyboard layout
> Parameters
key (string): The key to hold up
> Returns
None
> Example
# send Alt + F4 to the current application
Macro.key_down('Alt')
Macro.key_down('F4')
time.sleep(0.2)
Macro.key_up('Alt')
Macro.key_up('F4')
"""
if key in Macro.KEY_LIST:
controller.generateKeyboardEvent(Macro.KEY_LIST[key], None, KEY_RELEASE)
示例10: __generate
# 需要導入模塊: from pyatspi import Registry [as 別名]
# 或者: from pyatspi.Registry import generateKeyboardEvent [as 別名]
def __generate(i):
inShiftKeyList = i in Macro.SHIFT_KEY_LIST
if not (i in Macro.KEY_LIST or inShiftKeyList):
print 'Cannot type the character \'' + i +'\''
needShift = inShiftKeyList or i.isupper()
if needShift:
controller.generateKeyboardEvent(Macro.KEY_LIST['Shift'], None, KEY_PRESS)
controller.generateKeyboardEvent((Macro.SHIFT_KEY_LIST if inShiftKeyList else Macro.KEY_LIST)[i], None, KEY_PRESS)
time.sleep(0.01)
controller.generateKeyboardEvent((Macro.SHIFT_KEY_LIST if inShiftKeyList else Macro.KEY_LIST)[i], None, KEY_RELEASE)
if needShift:
controller.generateKeyboardEvent(Macro.KEY_LIST['Shift'], None, KEY_RELEASE)
示例11: test_riple_roll
# 需要導入模塊: from pyatspi import Registry [as 別名]
# 或者: from pyatspi.Registry import generateKeyboardEvent [as 別名]
def test_riple_roll(self):
self.help_test_insertEndFast()
seektime = self.search_by_text("0:00:02.455", self.pitivi, roleName="text")
timeline = self.get_timeline()
tpos = timeline.position
end = self.search_clip_end(30, seektime, timeline)
dogtail.rawinput.absoluteMotion(tpos[0] + end / 2 - 2, tpos[1] + 30)
registry.generateKeyboardEvent(dogtail.rawinput.keyNameToKeyCode("Control_L"), None, KEY_PRESS)
dogtail.rawinput.press(tpos[0] + end / 2 - 2, tpos[1] + 30)
sleep(0.5)
dogtail.rawinput.absoluteMotion(tpos[0] + end / 2 - 100, tpos[1] + 30)
sleep(0.5)
dogtail.rawinput.release(tpos[0] + end / 2 - 100, tpos[1] + 30)
registry.generateKeyboardEvent(dogtail.rawinput.keyNameToKeyCode("Control_L"), None, KEY_RELEASE)
self.nextb.click()
self.assertNotEqual(seektime.text, "0:00:02.455", "Not ripled, but trimed")
#Regresion test of adding effect
#Add effect
tab = self.pitivi.tab("Effect Library")
tab.click()
conftab = self.pitivi.tab("Clip configuration")
conftab.click()
center = lambda obj: (obj.position[0] + obj.size[0] / 2, obj.position[1] + obj.size[1] / 2)
table = conftab.child(roleName="table")
icon = self.search_by_text("Agingtv ", tab, roleName="icon")
self.improved_drag(center(icon), center(table))
self.nextb.click()
seekbefore = seektime.text
#Try riple and roll
dogtail.rawinput.absoluteMotion(tpos[0] + end / 2 - 102, tpos[1] + 30)
registry.generateKeyboardEvent(dogtail.rawinput.keyNameToKeyCode("Control_L"), None, KEY_PRESS)
dogtail.rawinput.press(tpos[0] + end / 2 - 102, tpos[1] + 30)
sleep(0.5)
dogtail.rawinput.absoluteMotion(tpos[0] + end / 2 - 200, tpos[1] + 30)
sleep(0.5)
dogtail.rawinput.release(tpos[0] + end / 2 - 200, tpos[1] + 30)
registry.generateKeyboardEvent(dogtail.rawinput.keyNameToKeyCode("Control_L"), None, KEY_RELEASE)
self.nextb.click()
self.assertNotEqual(seektime.text, seekbefore, "Not ripled affter adding effect")
示例12: keyboard
# 需要導入模塊: from pyatspi import Registry [as 別名]
# 或者: from pyatspi.Registry import generateKeyboardEvent [as 別名]
def keyboard(self, key):
"""
Types the tuple 'key' to the screen. For example you can say:
["Alex was in a bad mood lately", "Return", "A", "B", "1", "2", "comma"] and it will try to print:
Alex was in a bad mood lately
AB12,
A simple string rather than a tuple may as well be passed to this function.
"""
for i in key:
if i in key_list:
controller.generateKeyboardEvent(key_codes[key_list.index(i)], None, KEY_PRESS)
time.sleep(0.01)
controller.generateKeyboardEvent(key_codes[key_list.index(i)], None, KEY_RELEASE)
else:
for j in i:
if j in key_list:
controller.generateKeyboardEvent(key_codes[key_list.index(j)], None, KEY_PRESS)
time.sleep(0.01)
controller.generateKeyboardEvent(key_codes[key_list.index(j)], None, KEY_RELEASE)
else:
print "Unkown character to be sent as event:", j
示例13: test_ripple_roll
# 需要導入模塊: from pyatspi import Registry [as 別名]
# 或者: from pyatspi.Registry import generateKeyboardEvent [as 別名]
def test_ripple_roll(self):
self.insertTwoClipsAndSeekToEnd()
timecode_widget = self.viewer.child(name="timecode_entry").child(roleName="text")
self.assertEqual(timecode_widget.text, DURATION_OF_TWO_CLIPS)
tpos = self.timeline.position
end = self.search_clip_end(30, timecode_widget, self.timeline)
dogtail.rawinput.absoluteMotion(tpos[0] + end / 2 - 2, tpos[1] + 30)
registry.generateKeyboardEvent(dogtail.rawinput.keyNameToKeyCode("Control_L"), None, KEY_PRESS)
dogtail.rawinput.press(tpos[0] + end / 2 - 2, tpos[1] + 30)
sleep(0.5)
dogtail.rawinput.absoluteMotion(tpos[0] + end / 2 - 100, tpos[1] + 30)
sleep(0.5)
dogtail.rawinput.release(tpos[0] + end / 2 - 100, tpos[1] + 30)
registry.generateKeyboardEvent(dogtail.rawinput.keyNameToKeyCode("Control_L"), None, KEY_RELEASE)
self.goToEnd_button.click()
self.assertNotEqual(timecode_widget.text, DURATION_OF_TWO_CLIPS, "Not rippled, but trimmed")
# Check if adding an effect causes a regression in behavior
self.effectslibrary.click()
self.clipproperties.click()
center = lambda obj: (obj.position[0] + obj.size[0] / 2, obj.position[1] + obj.size[1] / 2)
table = self.clipproperties.child(roleName="table")
effect_from_library = self.search_by_text(
"Agingtv", self.effectslibrary, roleName="table cell", exactMatchOnly=False
)
self.improved_drag(center(effect_from_library), center(table))
self.goToEnd_button.click()
seekbefore = timecode_widget.text
# Try ripple and roll
dogtail.rawinput.absoluteMotion(tpos[0] + end / 2 - 102, tpos[1] + 30)
registry.generateKeyboardEvent(dogtail.rawinput.keyNameToKeyCode("Control_L"), None, KEY_PRESS)
dogtail.rawinput.press(tpos[0] + end / 2 - 102, tpos[1] + 30)
sleep(0.5)
dogtail.rawinput.absoluteMotion(tpos[0] + end / 2 - 200, tpos[1] + 30)
sleep(0.5)
dogtail.rawinput.release(tpos[0] + end / 2 - 200, tpos[1] + 30)
registry.generateKeyboardEvent(dogtail.rawinput.keyNameToKeyCode("Control_L"), None, KEY_RELEASE)
self.goToEnd_button.click()
self.assertNotEqual(timecode_widget.text, seekbefore, "Not rippled after adding effect")
示例14: key_up
# 需要導入模塊: from pyatspi import Registry [as 別名]
# 或者: from pyatspi.Registry import generateKeyboardEvent [as 別名]
def key_up(self, key):
"""
It releases a pressed key. See the key_down(key) function for more info.
"""
if key in key_list:
controller.generateKeyboardEvent(key_codes[key_list.index(key)], None, KEY_RELEASE)
示例15: pressKey
# 需要導入模塊: from pyatspi import Registry [as 別名]
# 或者: from pyatspi.Registry import generateKeyboardEvent [as 別名]
def pressKey(key):
registry.generateKeyboardEvent(key, None, KEY_SYM)