Ali Saad
Ali Saad

Reputation: 110

pressing keys together in pyautogui to make them make a function?

I have been recently trying to create a program that makes new folder in python(pyautogui). Here is my code:

import pyautogui;# import the library
pyautogui.press('ctrl');# makes our program to press 'ctrl'
pyautogui.press('n');# makes our program to press 'n'

Apparently what it does instead is pressing ctrl and n individually and I want from them to be pressed together. Please help.

Upvotes: 2

Views: 862

Answers (1)

albert
albert

Reputation: 8593

According to the docs:

The press() function is really just a wrapper for the keyDown() and keyUp() functions, which simulate pressing a key down and then releasing it up.

As you want to combine several key presses, you need to call keyDown() and keyUp() separately:

pyautogui.keyDown('ctrl')
pyautogui.press('n')
pyautogui.keyUp('ctrl')

Upvotes: 1

Related Questions