In the UI test automation that I was doing my best in UWSC, there was an element that did not accept key input by any means (Ore GrapeCity), so the command that I would use when writing an automation script with pyAutoGUI is [PyAuto Gui's documentation](https:: I extracted it from //pyautogui.readthedocs.io/en/latest/index.html).
By the way, the environment I'm doing my best is as follows OS:Windows Server 2003 R2 App development language: Visual Basic 6 Python version used for automation this time: 2.7.18
The site that I referred to in writing this article
Thanks to the great ancestors! …… Visit the Great Predecessors page for how to install modules with pip
pyautogui.moveTo(100, 200) #Coordinate(100,200)Mouse cursor moves to
pyautogui.moveTo(None,500) #Coordinate(100,500)Mouse cursor moves to
pyautogui.moveTo(600,None) #Coordinate(600,500)Mouse cursor moves to
pyautogui.click() #Fire a click event where the mouse cursor is
pyautogui.click(x=100, y=200) #Mouse cursor coordinates(100,200)Go to and click event fire
pyautogui.click(button='right')#Right click with this
pyautogui.click(clicks=2) #Double click with left click button
pyautogui.click(clicks=2, interval=0.25) #Left click button click → 0.Wait 25 seconds → left click button click
pyautogui.click(button='right', clicks=3, interval=0.25) #Right mouse button triple click, interval 0.25 seconds
pyautogui.write('Hello World!') # ただ単に「Hello World!」が出力される
pyautogui.write('hello world!', interval=0.25) #0 character by character.Every 25 seconds"hello world!"Is output
pyautogui.press('enter') #Enter key is pressed
pyautogui.press('f1') #Function 1[F1]The key is pressed
pyautogui.press('left') #Left arrow[←]The key is pressed
pyautogui.keyDown('shift') # [Shift]Hold down the key. As it is until keyUp
pyautogui.press('left') #Because it's a press[←]Key pressed and released
pyautogui.press('left') #Because it's a press[←]Key pressed and released
pyautogui.press('left') #Because it's a press[←]Key pressed and released
pyautogui.keyUp('shift') # [Shift]Key goes up(Release the key)
write ()
functionpyautogui.press(['left', 'left', 'left']) #Realized version with array elements
pyautogui.press('left',presses=3) #If you hit the same button repeatedly, you can specify the number of times with the presses option
pyautogui.press('left',presses=3, interval=0.25) # write()You can adjust the input interval with the interval option as well as
pyautogui.hotkey('ctrl', 'shift', 'esc') #[Ctrl]+[Shift]+[Esc]Start task manager with
Of course you can write it like this ...
pyautogui.keyDown('ctrl')
pyautogui.keyDonw('shift')
pyautogui.keyDown('esc')
pyautogui.keyUp('esc')
pyautogui.keyUp('shift')
pyautogui.keyup('ctrl')
It's easier to use the hotkey function.
Here is a list of virtual keys that can be used with pyAutoGui.
['\t', '\n', '\r', ' ', '!', '"', '#', '$', '%', '&', "'", '(',
')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', ':', ';', '<', '=', '>', '?', '@', '[', '\\', ']', '^', '_', '`',
'a', 'b', 'c', 'd', 'e','f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~',
'accept', 'add', 'alt', 'altleft', 'altright', 'apps', 'backspace',
'browserback', 'browserfavorites', 'browserforward', 'browserhome',
'browserrefresh', 'browsersearch', 'browserstop', 'capslock', 'clear',
'convert', 'ctrl', 'ctrlleft', 'ctrlright', 'decimal', 'del', 'delete',
'divide', 'down', 'end', 'enter', 'esc', 'escape', 'execute', 'f1', 'f10',
'f11', 'f12', 'f13', 'f14', 'f15', 'f16', 'f17', 'f18', 'f19', 'f2', 'f20',
'f21', 'f22', 'f23', 'f24', 'f3', 'f4', 'f5', 'f6', 'f7', 'f8', 'f9',
'final', 'fn', 'hanguel', 'hangul', 'hanja', 'help', 'home', 'insert', 'junja',
'kana', 'kanji', 'launchapp1', 'launchapp2', 'launchmail',
'launchmediaselect', 'left', 'modechange', 'multiply', 'nexttrack',
'nonconvert', 'num0', 'num1', 'num2', 'num3', 'num4', 'num5', 'num6',
'num7', 'num8', 'num9', 'numlock', 'pagedown', 'pageup', 'pause', 'pgdn',
'pgup', 'playpause', 'prevtrack', 'print', 'printscreen', 'prntscrn',
'prtsc', 'prtscr', 'return', 'right', 'scrolllock', 'select', 'separator',
'shift', 'shiftleft', 'shiftright', 'sleep', 'space', 'stop', 'subtract', 'tab',
'up', 'volumedown', 'volumemute', 'volumeup', 'win', 'winleft', 'winright', 'yen',
'command', 'option', 'optionleft', 'optionright']
It ’s a place that seems to be used unexpectedly
['kana', 'kanji','ctrlright','decimal','numlock']
Or something?
This is a copy. Yes. Please sing. Japanese is copy. I did my best. Me too. Is Unicode wrong? Or does it have to be Shift-JIS? When The answer was given by the ancestor.
import pyperclip as clipboard
clipboard.copy("Japanese string")
pyautogui.hotkey('ctrl','v')
This is it. later
unicodedecodeerror 'ascii' codec can't decode
If you unfortunately meet, let's borrow the wisdom of our predecessors and change the default character code to UTF-8.
Basically, I just summarized the example of Welcome to PyAutoGUI's documentation! + My own trial and It's a record of the error, but I hope there are people who can help with this alone. Let's have a good automation life!
Recommended Posts