1

I am using Python (2.4) and trying to simulate a key press (CTRL, SHIFT). But my python is built into a Media application/framework (From Peavey) that allows me to do very basic coding in Python but does not have the capability to install/import any modules, libraries.

So I can't use any of the libraries/modules for key press such as : Keyboard, pyinput, ctype, Win32, wintype etc.

Is there any way to simulate a Keypress without using "import" at the top of the script?

Thank you in advance...

I have tried the following:

import keyboard  # using module keyboard
while True:  # making a loop
    try:  # used try so that if user pressed other than the given key error will not be shown
        if keyboard.is_pressed('q'):  # if key 'q' is pressed 
            print('You Pressed A Key!')
            break  # finishing the loop
        else:
            pass
    except:
        break  # if user pressed a key other than the given key the loop will break

But when executed, it gives me Error stating:

Traceback (most recent call last):
  File "key.py", line 1, in ?
    import keyboard  # using module keyboard
ImportError: No module named keyboard

And I can't import the library when I use the code in production.

sfkhan
  • 63
  • 10
  • Maybe this can help you (but you need to import some library here): https://stackoverflow.com/questions/21905946/python-selenium-how-to-use-browser-shortcuts – Peter Apr 04 '19 at 13:51
  • Maybe you can try copying and modifying some of the functionalities of said lib. It might work, but I do not know whether `dumpkeys` http://man7.org/linux/man-pages/man1/dumpkeys.1.html exist in Peavey. – pnv Apr 04 '19 at 13:59
  • @Peter, I am unable to use any sort of imports unfortunately. Otherwise it would have been a simple to do task.. Thank you for your reply. – sfkhan Apr 04 '19 at 14:01

1 Answers1

0

To my knowledge, there is no way to simulate keypresses without using external python libraries. If the problem is you not having access to the terminal/shell, use

os.system(command)

where command is either "pip install [library]" or "pip3 install [library]"

if you encounter any problems with this, maybe try using "git clone [library source]

  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Aug 12 '23 at 03:42