Python Automation Series #11: How to automate your mouse and keyboard in Python ?

In this tutorial, you will learn how to automate your mouse and keyboard to save your time using a module called PYAUTOGUI.
PYAUTOGUI lets your Python scripts control the mouse and keyboard to automate interactions with other applications, like moving the mouse , clicking , scrolling or typing in the windows of other application to fill out forms and so on
Official documentation link for pyautogui module:
pyautogui.readthedocs.io
Github link for the code : github.com/BekBrace/keyboard-...
DEV profile : dev.to/bekbrace
Github profile: github.com/BekBrace

Пікірлер: 163

  • @blackcitadel37
    @blackcitadel37 Жыл бұрын

    I wish i had watched this video before. My tendinitis and the 800 documents i have (now had :D) to check manually until Monday for work thank you a hell of a lot, sir. Awesome content.

  • @BekBrace

    @BekBrace

    Жыл бұрын

    Much appreciated my friend

  • @batsukhtsogt7615
    @batsukhtsogt76153 жыл бұрын

    Thank you, been looking for this for a while. You are a real life saver.

  • @BekBrace

    @BekBrace

    3 жыл бұрын

    I’m glad my friend 🙂

  • @mbogitechconpts
    @mbogitechconpts3 жыл бұрын

    Wow! Great video.

  • @leonkennedy6726
    @leonkennedy67262 жыл бұрын

    Thanks man , very useful tutorial and a good intro to automation

  • @BekBrace

    @BekBrace

    Ай бұрын

    Cheers

  • @hamzazain3578
    @hamzazain357811 ай бұрын

    Bro..y ou got a calming voice and a really easy to understand method of teaching, REP+ and hope you find success and it was a really fun experiance learning this from your video.

  • @BekBrace

    @BekBrace

    11 ай бұрын

    Thank you very much my friend 🙏😊

  • @anokhautomation4453
    @anokhautomation44532 жыл бұрын

    Wow wow... Very very informative and interesting tutorial. 👌👌

  • @BekBrace

    @BekBrace

    2 жыл бұрын

    Thank you my friend

  • @joeyjohnsonson4341
    @joeyjohnsonson43412 жыл бұрын

    dude’s voice is great

  • @BekBrace

    @BekBrace

    2 жыл бұрын

    Thanks so much 🙂

  • @donthackme2

    @donthackme2

    Ай бұрын

    it's 2:30 am and the video made me even sleepier

  • @BekBrace

    @BekBrace

    Ай бұрын

    That's not a very nice thing to say

  • @donthackme2

    @donthackme2

    Ай бұрын

    @@BekBrace why? I'm not English so can you explain please? I wanted to say that I was tired because it was 2 am but I wanted to watch the video(which I enjoyed) and you voice is calm and charming and it made me even sleepier

  • @BekBrace

    @BekBrace

    Ай бұрын

    Oh, I misunderstood. Usually when you say this, that means that the person talking is boring 😜 But thank you very much for the sweet compliment ❤️🙏

  • @iydl
    @iydl2 жыл бұрын

    Thank you so much man, I modified my typing thing a bit so I had a delay before it did it and so it did it like 10 times so now I can spam my friends on discord. Thank you so much!!!!!

  • @BekBrace

    @BekBrace

    2 жыл бұрын

    Hehehe 🤭 Great job my friend

  • @Ankumeh589
    @Ankumeh589Ай бұрын

    Best tutorial

  • @kamranmohaghegh2884
    @kamranmohaghegh2884 Жыл бұрын

    Thank you Bek, it is a very useful video. Clear sound and speed for the training :-bd

  • @BekBrace

    @BekBrace

    Жыл бұрын

    Thank you very much 😊

  • @ConnorP94
    @ConnorP94 Жыл бұрын

    Is there anyway to make it type the same text but +1 for example cp1, cp2,cp3 ect?

  • @tasty7963
    @tasty79633 ай бұрын

    its not giving me the height and width of my screen and im not sure if it imported pyautogui, but i dit watch that part multiple times to check

  • @AnasMations
    @AnasMations2 жыл бұрын

    This is so helpful, thank you!!

  • @teen_python_go9947
    @teen_python_go99473 жыл бұрын

    Woah!! 'Tis amazin' sir!! Thanks a lot for helpin'!! Love from India!!

  • @BekBrace

    @BekBrace

    3 жыл бұрын

    Thank you LIT Python 🙏

  • @electrocrane
    @electrocrane2 жыл бұрын

    Man this is a pure life saver ! thank you very much , have a nice day :)

  • @BekBrace

    @BekBrace

    2 жыл бұрын

    I am glad, friend :) Have a good day ahead too

  • @electrocrane

    @electrocrane

    2 жыл бұрын

    @@BekBrace man i literally used this pyautogui to cut all my lengthy editing steps in premier pro , so now i can press one button and it'll directly apply one effect to the clip , no need of drag and type over and over again now , PURE LIFESAVER :) trying to learn more for further improvement .

  • @partivkartikeya2269
    @partivkartikeya2269 Жыл бұрын

    Thanks a lot bro.. your video was very helpful to complete my project work..

  • @BekBrace

    @BekBrace

    Жыл бұрын

    I’m glad brother 🙏 All the best to you

  • @RathElTigre
    @RathElTigre6 ай бұрын

    How i can make that the mouse moves and click but only if press a key?

  • @pica_noris3461
    @pica_noris34613 жыл бұрын

    Neat ! Thanks a lot for this video , very helpful

  • @BekBrace

    @BekBrace

    3 жыл бұрын

    Pica _Noris Thank you for watching 😊

  • @lauranalo2254
    @lauranalo22543 жыл бұрын

    I did the drawing thing and it's very cool 😀

  • @N0WARE
    @N0WARE11 ай бұрын

    Thanks Never been so excited to try code before :D

  • @BekBrace

    @BekBrace

    11 ай бұрын

    You're welcome, brother / sister

  • @clevertonlacerda1300
    @clevertonlacerda13003 жыл бұрын

    Thank you for make this video, it will help me a lot of with my tasks!!

  • @BekBrace

    @BekBrace

    3 жыл бұрын

    I’m very happy you found it useful 👍

  • @tuckerlangston8528

    @tuckerlangston8528

    2 жыл бұрын

    You all prolly dont care but does any of you know a trick to get back into an Instagram account? I stupidly forgot my password. I would love any tips you can offer me

  • @youneedspeed4773
    @youneedspeed47733 ай бұрын

    Thanks a lot man. really helped me :)

  • @BekBrace

    @BekBrace

    3 ай бұрын

    Gladly ☺️

  • @shishirbhargav9627
    @shishirbhargav96273 жыл бұрын

    Amazing Video thank you for such informative content love from india

  • @BekBrace

    @BekBrace

    3 жыл бұрын

    Best regards from Poland

  • @RapFanMan1
    @RapFanMan12 жыл бұрын

    the question is how can i know for example google chrome on desktop axis coordinates what are ???

  • @maoraltman3700
    @maoraltman37003 жыл бұрын

    best vid on the topic thx so much

  • @BekBrace

    @BekBrace

    3 жыл бұрын

    Thank you very much Maor

  • @YoutubeShorts-vm5di
    @YoutubeShorts-vm5di Жыл бұрын

    Best tutorial for this, ever!!!

  • @BekBrace

    @BekBrace

    Жыл бұрын

    Many thanks for your kind words

  • @FrogInALog_
    @FrogInALog_ Жыл бұрын

    I need help, I do not want the user to be able to click of type while it is going, please help

  • @svetlana9699
    @svetlana96993 жыл бұрын

    Great tutorial !

  • @BekBrace

    @BekBrace

    3 жыл бұрын

    Thank you! Cheers!

  • @Acid_Sakib
    @Acid_SakibАй бұрын

    can anyone help me how to break a while loop by pressing esc key?

  • @MemesGuy
    @MemesGuy5 ай бұрын

    is there a way to loop this?

  • @haowu5776
    @haowu57762 жыл бұрын

    Great video ❤️. Can we capture the mouse/keyboard event?

  • @angelos-zw3zn
    @angelos-zw3zn3 ай бұрын

    how can you run this program?

  • @daviizinkks
    @daviizinkks2 ай бұрын

    thanks bro ! i made a script that automatically search things you want in edge , thanks so much

  • @BekBrace

    @BekBrace

    2 ай бұрын

    You're very welcome 🤗

  • @RodrigoVieira099
    @RodrigoVieira09911 ай бұрын

    Thanks a lot for this!

  • @BekBrace

    @BekBrace

    11 ай бұрын

    You're very welcome!

  • @crazydudes9782
    @crazydudes97823 жыл бұрын

    how about dual monitor?

  • @Garfield_Minecraft
    @Garfield_Minecraft Жыл бұрын

    This would be so useful I can use my voice controll the computer Thanks im learning python code

  • @BekBrace

    @BekBrace

    Жыл бұрын

    Great ! Keep learning my friend

  • @BhramaM4334
    @BhramaM4334 Жыл бұрын

    thanks. this helped me a lot!

  • @BekBrace

    @BekBrace

    Жыл бұрын

    you are very welcome

  • @Funnyvideos____2
    @Funnyvideos____2 Жыл бұрын

    Helpful video actually

  • @BekBrace

    @BekBrace

    Жыл бұрын

    Cool

  • @romanmelon5845
    @romanmelon5845 Жыл бұрын

    thanks, I use this lib to avoid my company tracking myself during work day =) For now have tool that writes me simple code))

  • @BekBrace

    @BekBrace

    Жыл бұрын

    That's awesome !

  • @sebasy6915
    @sebasy69152 жыл бұрын

    Hello Bec. Thank you! . I have a question: I try to use complex characters like " \" in a windows path, but pyautogui.typewrite does not work typing this kind of characters. Help me please. Thank you again!

  • @BekBrace

    @BekBrace

    2 жыл бұрын

    Hi There! what are you trying to achieve ?

  • @sebasy6915

    @sebasy6915

    2 жыл бұрын

    Hi. I'm working in a boot that open a specific route in CMDER . Sample: pyautogui. Typewrite ("C\archives \programming epository ") but the result is : C archives programming repository. Thank you!

  • @Scorpienmovies
    @Scorpienmovies2 жыл бұрын

    Hey Bek, that was great and informative content, thank you so much for the Video. Do you know, if it is allowed in the terms and services to use pyautogui in the workspace?

  • @BekBrace

    @BekBrace

    2 жыл бұрын

    Thank You so much :) Didn't see anything in the documentations that says otherwise pyautogui.readthedocs.io/en/latest/

  • @highschoolwallaywalasamina4987
    @highschoolwallaywalasamina49872 жыл бұрын

    i have made this program for 100 iterations that takes 15 minutes in using many applications, so how can i run this automation program in the background? that i wanna save my 15 minutes or do another program or task?

  • @BekBrace

    @BekBrace

    2 жыл бұрын

    That's an excellent question, and I've been looking myself for an automation solution that can run in the background , as long as I know there is no way we can do that, but I'll keep searching for an answer to that question

  • @aradhyakumarchandra8900
    @aradhyakumarchandra89002 жыл бұрын

    Thank you so much !! The video was great 👍. I have a question that will the pyautogui.hotkeys() command work if I want to press the windows key and up arrow key together to maximize my window ? Please clear my doubt.

  • @BekBrace

    @BekBrace

    2 жыл бұрын

    Thank you friend 🙂 No, i doubt it as it will be regarded as key interruption

  • @aradhyakumarchandra8900

    @aradhyakumarchandra8900

    2 жыл бұрын

    Thank you so much 😁😁

  • @Handlebrake2

    @Handlebrake2

    2 жыл бұрын

    @@BekBrace so we can't use window commands?

  • @muhamadameen5690
    @muhamadameen5690 Жыл бұрын

    very useful , thanks

  • @BekBrace

    @BekBrace

    Жыл бұрын

    You're very welcome

  • @shigaraki6615
    @shigaraki66155 ай бұрын

    very clear

  • @BekBrace

    @BekBrace

    5 ай бұрын

    Glad to hear 🍀

  • @liloflorida752
    @liloflorida7523 жыл бұрын

    I had a dream about pyautogui !

  • @sknfer

    @sknfer

    3 жыл бұрын

    waaaat ????

  • @hhory2614
    @hhory26142 жыл бұрын

    Hello Bek! Your video was really useful, I can't thank enough. May I ask, is there a way to make python work in the "background"? What I mean is, how can I do anything else, while the code is running in a specific windows only? Can you advise a tutorial for that? I'd be thankful.

  • @BekBrace

    @BekBrace

    2 жыл бұрын

    Hello my friend, and thank you very much for your comment. Actually, this is very good question, and I have been looking for a solution for this issue; I do some automation macros in VBA for excel, and I have the same issue: I cannot do anything till the macro finishes When I get an answer I will let you know for sure

  • @EvadingTaxes

    @EvadingTaxes

    2 жыл бұрын

    yes you can do that by renaming the file to .pyw

  • @dualnubs4663

    @dualnubs4663

    Жыл бұрын

    @@EvadingTaxes how bro can you explain or there is a specific vid for that?

  • @qwerty_____146
    @qwerty_____14622 күн бұрын

    Hi Bro. Thank you a lot.

  • @BekBrace

    @BekBrace

    22 күн бұрын

    You are welcome

  • @YT-GAMER-X
    @YT-GAMER-X Жыл бұрын

    You're voice is so satisfying

  • @prabirchandrasen7852
    @prabirchandrasen78522 жыл бұрын

    Really very helpful sir

  • @BekBrace

    @BekBrace

    2 жыл бұрын

    Thank you 😊

  • @joseantonioperedarios2811
    @joseantonioperedarios28113 жыл бұрын

    Thanks for the video. I have tried to use this module. But when scheduling three consecutive clicks outside of Visual Studio Code, the script only do one click. Why will it be?

  • @BekBrace

    @BekBrace

    3 жыл бұрын

    Hello Jose ! Thank you for your comment. I am not sure that I fully understand, what do you mean by " outside of Visual Studio Code " ?

  • @joseantonioperedarios2811

    @joseantonioperedarios2811

    3 жыл бұрын

    @@BekBrace Thanks for answering. I want my script to click on a window of an accounting program, then navigate its menus. I wrote the coordinates of each menu. But when I run the script, it only gives 1 click and not the others that I programmed. Does it have something to do with pillow?

  • @BekBrace

    @BekBrace

    3 жыл бұрын

    @@joseantonioperedarios2811 ohhh I see what you mean. pillow is an images library so I don’t know how it could help in this particular situation, but honestly I never encountered this issue; I’ll try to find a solution and get back to you, meanwhile, you can search the web for an answer

  • @joseantonioperedarios2811

    @joseantonioperedarios2811

    3 жыл бұрын

    @@BekBrace Thanks a lot. I will continue my search.

  • @jakobwolf6274
    @jakobwolf6274 Жыл бұрын

    I know this tutorial is very old but I still have a Question: Is it also possible to hold right click with pyautogui?

  • @BekBrace

    @BekBrace

    Жыл бұрын

    no problem :) as far as I know pyautogui does not have a built-in function for holding down the right-click. However, you can achieve this behavior by combining pyautogui.mouseDown() and pyautogui.mouseUp() functions with the appropriate mouse button parameter.

  • @Jinxone741
    @Jinxone741 Жыл бұрын

    Thanks man . one question what Function to type a variable

  • @BekBrace

    @BekBrace

    Жыл бұрын

    Come again ?

  • @chaimingkai7235
    @chaimingkai7235 Жыл бұрын

    hi is there anyway we could record down our moves and replay it?

  • @BekBrace

    @BekBrace

    Жыл бұрын

    You mean like a macro recorder ?

  • @chaimingkai7235

    @chaimingkai7235

    Жыл бұрын

    @@BekBrace yep

  • @chairliftt
    @chairliftt Жыл бұрын

    thank you very much for this video! i just want to doublecheck: once you've created your mouse input function, you could then just inplement this in a while loop, right? to just keep it going for however long? let's say i have 500 papers to click through, i can just let it run? sorry if you covered this in the video. thank you again!

  • @BekBrace

    @BekBrace

    Жыл бұрын

    Yes exactly 😊 You can do precisely that

  • @chairliftt

    @chairliftt

    Жыл бұрын

    @@BekBrace Wow, thank you so much for the quick reply! Cheers!

  • @mxh1t
    @mxh1t Жыл бұрын

    can pls share mouse move and click , using win32

  • @BekBrace

    @BekBrace

    Жыл бұрын

    sure

  • @gatonegro187
    @gatonegro1873 ай бұрын

    I want to move mouse with a xbox controller so this should be helpful thanks

  • @alexj7693
    @alexj76932 жыл бұрын

    What extension packs do you use?

  • @BekBrace

    @BekBrace

    2 жыл бұрын

    For Python: Visual Studio Intellicode Python Prettier MagicPython

  • @alexj7693

    @alexj7693

    2 жыл бұрын

    @@BekBrace thank you!

  • @jesuisravi
    @jesuisravi2 жыл бұрын

    I don't see the code by which you moved to Paint. How did you get there?

  • @BekBrace

    @BekBrace

    2 жыл бұрын

    Line 18 through 22

  • @jesuisravi

    @jesuisravi

    2 жыл бұрын

    @@BekBrace good. Thanks

  • @aditya5531
    @aditya55312 жыл бұрын

    Thanks a lot

  • @BekBrace

    @BekBrace

    2 жыл бұрын

    Glad you liked it

  • @darkthepsychopath
    @darkthepsychopath10 ай бұрын

    pls give python program to change mouse sensitivity

  • @BekBrace

    @BekBrace

    10 ай бұрын

    Ok 👌

  • @lookman06
    @lookman062 жыл бұрын

    Hi, how to know where is our mouse coordinates?

  • @BekBrace

    @BekBrace

    2 жыл бұрын

    Using : pyautogui.position()

  • @emiliorambaldi2894
    @emiliorambaldi28942 жыл бұрын

    import pyautogui ModuleNotFoundError: No module named 'pyautogui' Where is that module?

  • @BekBrace

    @BekBrace

    2 жыл бұрын

    You've got to install first : pip install pyautogui Then you can import it.

  • @sknfer
    @sknfer3 жыл бұрын

    perfect vieo

  • @BekBrace

    @BekBrace

    3 жыл бұрын

    Thank you very much 🙏

  • @emiliorambaldi2894
    @emiliorambaldi28942 жыл бұрын

    In my python there is not module named pyautogui

  • @BekBrace

    @BekBrace

    2 жыл бұрын

    You must install it as shown in the tutorial 🙂

  • @yassinewaterlaw6597
    @yassinewaterlaw65972 жыл бұрын

    How we can install pyautogui module ??

  • @BekBrace

    @BekBrace

    2 жыл бұрын

    Have you watched the video ?

  • @yassinewaterlaw6597

    @yassinewaterlaw6597

    2 жыл бұрын

    @@BekBrace i've fixed the probleme thank you

  • @trevor9776
    @trevor97762 жыл бұрын

    can we do all this using c language

  • @BekBrace

    @BekBrace

    2 жыл бұрын

    Unlikely, but maybe I'm not sure

  • @schiribeats
    @schiribeats Жыл бұрын

    canÄt import pyautogui it gets error

  • @BekBrace

    @BekBrace

    Жыл бұрын

    What's the error ?

  • @schiribeats

    @schiribeats

    Жыл бұрын

    @@BekBrace Traceback (most recent call last): File "", line 1, in import pyautogui ModuleNotFoundError: No module named 'pyautogui'

  • @Abstract_Code
    @Abstract_Code2 жыл бұрын

    Bro can you please tell me what is your color scheme called it looks so cool.🙏🙏

  • @BekBrace

    @BekBrace

    2 жыл бұрын

    You mean Vscode theme ?

  • @Abstract_Code

    @Abstract_Code

    2 жыл бұрын

    @@BekBrace yes please

  • @LimeSpeedCrystal
    @LimeSpeedCrystal Жыл бұрын

    How to typewrite with a delay?????????

  • @BekBrace

    @BekBrace

    Жыл бұрын

    What's that now ?

  • @alimustafa2682
    @alimustafa2682 Жыл бұрын

    The voice though !!

  • @BekBrace

    @BekBrace

    Жыл бұрын

    Thanks Ali

  • @madsgrefsrud1139
    @madsgrefsrud11392 жыл бұрын

    what app is that

  • @BekBrace

    @BekBrace

    2 жыл бұрын

    What do you mean

  • @operator415baza

    @operator415baza

    2 жыл бұрын

    Bracket

  • @notanymorestopmotionlego2328
    @notanymorestopmotionlego23283 жыл бұрын

    I use this to make hack client

  • @jasonstranthon5183
    @jasonstranthon5183 Жыл бұрын

    In none of your videos do you explain to a noob how to get that interface you have. I installed python and run it and it just looks like normal windows command prompt & keeps saying "pip' did you mean 'zip' when I try to install autogui? Plus nowhere can i find the simple looking GUI you have in this vid....how do I get that ? Seriously, there should be a non convoluted way to install this....its easier to just use c++ at this point.....

  • @BekBrace

    @BekBrace

    Жыл бұрын

    In this vid ? you mean "in this video" ! I have no idea what you're talking about when you say "the interface you have". what's the issue with pip ? pip is a package manager through which you can install modules/packages/dependencies that you may use in your app. Again with the "simple GUI you have" - what do you mean ?! Go ahead then work with C++, or try to explain your point of view in a clearer way

  • @tugaric
    @tugaric2 жыл бұрын

    Thank you jesus not an indian accent 😭 tears of joy

  • @BekBrace

    @BekBrace

    2 жыл бұрын

    Hehe, that would be offensive to our indian friends but thanks for your comment ,😊

  • @gatonegro187
    @gatonegro1873 ай бұрын

    I want to move mouse with a xbox controller so, so I don't have to get Elon Musk's Neurolink chip drilled into my skull, this should be helpful thanks

  • @lloydchristmas_iii4310
    @lloydchristmas_iii4310 Жыл бұрын

    Win 32 is alot faster then puautogui

  • @BekBrace

    @BekBrace

    Жыл бұрын

    Ok

  • @lloydchristmas_iii4310

    @lloydchristmas_iii4310

    Жыл бұрын

    @@BekBrace either way it works...

  • @admiralevan
    @admiralevan Жыл бұрын

    Trying to do shit in power automate makes me want to eat glass. It kept deleting my flows or crashing and not saving flows. SIMPLE SHIT WHY ARE YOU SO BAD MICROSOFT

  • @BekBrace

    @BekBrace

    Жыл бұрын

    What about Linux ?