Controlling The Keyboard Through Python Language

This is a very interesting use for the keyboard through Python language.

  1. Firstly Install the Python in your system.

  2. After Installing the pip command download this file and install with python. You can also follow this article for installing pip command in windows.

  3. After Successful Installation of pip then open command prompt and write command : pip install pyautogui. I have already installed.

    OUTPUT

  4. After this write command in CMD : python.

  5. It will open python terminal of python.

  6. Before try keyboard open notepad in your computer.

  7. Write code in terminal : import pyautogui then press enter

  8. Again write code in next line : pyautogui.click(100,100); pyautogui.typewrite(“I’m Neeraj Kumar”, interval=1) then press enter and fastly click mouse on notepad file.

  9. You will see that “I’m Neeraj Kumar” text automatic write character by character in 1 second intervals.

    OUTPUT

    OUTPUT

  10. Another Example of Keyboard use.

  11. Write code in python terminal as below,

    “pyautogui.click(100,100); pyautogui.typewrite(['a', 'c', 'left', 'b', 'right', 'd'],interval=5)”

    This code write abcd in notepade file.

    CODE

    OUTPUT
  12. In the next example you can click any key with Keyboard.

  13. Write code in python terminal. pyautogui.KEYBOARD_KEYS.

  14. It shows the test of each keyboard button that can work with python using text like below image.

    TEXT

  15. After checking if this is working or not write code again as below.

    pyautogui.press(‘capslock’)

    If caps lock button is OFF then it will ON and if ON then OFF.

  16. Now we see How to hotkeys using this.

  17. Task Manager Button is ctrl+shift+esc. So open task manager through this.write code as below.

    pyautogui.hotkey('ctrl','shift','esc')

  18. It will open Task Manager.

    You can also do multiple things with keyboard using pyautogui library.

Next Recommended Readings