1

I would like to be able to change characters as the user types text into a (cmd.Cmd) prompt using the cmd python module. So when a user types in a character I would like to be able to process that character and change it in line. Is there a way to use the cmd module to process and replace every character as it is typed or is there another module that I should be using?

edit: This is for running in a Windows environment.

2 Answers 2

2

It seems that you are searching to hook keyboard strokes on windows using python. if i am not mistaken in my assumption, hooking is not trivial on python since dll is required.

you may try pyHook, it uses Windows API to do the job.

Here is the API.

Sign up to request clarification or add additional context in comments.

Comments

0

I don't see any way to do this with cmd.Cmd either but it would be possible with curses - see Curses Programming with Python. The getch() function will return the keycode but not echo it unless curses has been told to echo() it. That would let you take the keycode and transform it however you liked (e.g. into an 'X' to hide the characters entered as a password) before displaying the character(s) on the screen.

Alternatively, though I haven't used it, the Console module seems to provide equivalent functionality for Python on Windows.

1 Comment

Thank you for the answer but I am writing a Windows app and Curses seems to only run in a UNIX/LINUX environment. The Curses docs reference a similar Windows command line tool here, but the latest release is for XP and is of course only 32-bit. I am editing my question to reflect the Windows aspect of the problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.