Hi,
I am working on a project and I am monitoring the keyboard with the keyboard module.
My application works in real-time (on-the-fly) and read strings entered from user (with the keyboard module as mentioned)
What I want to do is hide user input when some specific conditions are True.
I have searched all the web and didn't manage to find something that does what I want.
To give it a more detailed explanation lets say that the user enters some text and this text string-by-string is being checked for some condition from my program.
If everything is OK, then nothing happens but if not, then I want the next user input not to be shown in the position he is writing.
I found solutions that do exactly this in the terminal like the msvcrt module (How to temporarily disable keyboard input using Python ) or do the above functionality with the input() function.
Is there something that prevent the text ,entered from the keyboard, from showing to the screen, but send it to a buffer for editing first.
Thanks in advance.
! I am on windows
Related
When I was programming in Mindstorms Robot Inventor, and decided to put an input in my code, I bumped into this NameErrorThis is the Error
Is it Even possible to put an input in Mindstorms??
The Python available isn’t the complete Python standard library. The terminal view in the code editor doesn’t provide for a way to put in input either, so unfortunately no.
What you can do instead is use the buttons on the hub as a type of input. This wouldn’t be free-form text, but if you’re using input() as a user-controlled wait before progressing, you can do that.
_ = hub.right_button.was_pressed() # clear out any button press
while not hub.right_button.was_pressed():
# do something
# do something after the button was pressed
You can string multiple of the above in a row if you want to do multiple actions separated by waiting for you to let it continue, or even take different actions based on which button was pressed.
Finally, you could do a very slow text input using the buttons and the display screen to scroll through the alphabet, confirm the letter, and finish the input.
I am writing a DoodleJump game for the terminal in Python with curses. I use getch() to get the user input to know in which direction the character should move. When I get the user input my environment gets updated simultaneously but I want that it just keeps on moving and not update when I get the user input.
Does anybody know how I can achieve this? I tried using nodelay() but that still doesn't cut it. Thanks in advance
please try with:
time.sleep(seconds)
This will wait the seconds you want before continue.
Sources:
https://www.pythoncentral.io/pythons-time-sleep-pause-wait-sleep-stop-your-code/
Hope it help, have a nice day,
David.
curses refreshes the window associated with getch. You could prevent refreshes (or hide them) by turning off echo, and using a window that won't have changes made to it (even one that you create just for that purpose).
I am trying to write a macro using python.
I want it to do a repeated task within another program.
I believe the program that I am attempting write this macro only
accepts raw input from keyboard and mouse input stream.
Using python libraries such as pynput.mouse, mouse, pyautogui, so on
seem to be sending a different type of keyboard/mouse input that the program
will not recognize. (Those libraries do work to control and move the mouse
around my computer screen but do not work in the program)
It was suggested that the program accepts only input directly from the keyboard
and mouse (ports?).
How can I write code that sends data as "raw" to the program, or reroute it through the correct (port?) input stream so that the program reads it as "raw"
I hope I was able to explain this clearly.
Please see the following post: ctypes mouse_events
It explains how to do this with raw win32 messages which will do the trick.
G'day,
I've just posted this question here. Following on from that, is there a means to lock keyboard user input to the terminal, when it's running behind another window? My system requires a user to scan their barcode (barcode scanner acts as a keyboard. ie. outputs a string of letters and presses enter) inside the terminal. However, the system also requires that a log CSV file be displayed on the attached monitor. As such, with the terminal in the background, the cursor automatically reverts to the log CSV file when opened, which disables the users' barcode scan from being entered into the terminal.
I'm still relatively new to Python, and haven't completely figured out the functionality of this system. I will eventually set it up such that when the system boots, the log file will automatically open on top, with the terminal (and cursor input) running in the background.
Again, I don't have any code to demonstrate my attempts, but I have done extensive research. The only thing I've found that may offer this functionality is xdotool. I could automatically rearrange the windows such that the terminal was always at the back, and somehow automatically allocate the terminal as the 'active' window?
Any help here would be great!
Thanks!
I have to write a script to emulate some keyboard event in a different program in background.This is my code:
pwin = win32ui.FindWindow(None,r'someprograme')
pwin.SendMessage(win32con.WM_KEYDOWN,18)
pwin.SendMessage(win32con.WM_KEYDOWN,68)
pwin.SendMessage(win32con.WM_KEYUP,18)
pwin.SendMessage(win32con.WM_KEYUP,68)
pwin.SendMessage(win32con.WM_KEYDOWN,13)
pwin.SendMessage(win32con.WM_KEYUP,13)
But it seems nothing happened.So what should i do?I've tried PostMessage func it seems it still can not do it.
After a quick look at the WM_KEYDOWN docs:
Posted to the window with the keyboard focus when a nonsystem key is pressed. A nonsystem key is a key that is pressed when the ALT key is not pressed.
But looking up your keycodes, you're trying to send ALT-D (followed by ENTER, which is fine). It sounds like you're trying to drive the menus; if that's what you want to do, WM_KEYDOWN is not the way to do it.
The problem is that keyboard menu navigation is driven by Windows, not by the app (except for a handful of apps that override normal menu processing, like some versions of Visual Studio). When you're looking at Notepad, and you hit ALT-F to open the File menu, the Notepad code gets a bunch of menu-related messages (WM_INITMENU, etc.), not the keystrokes.
If you use a WM spy program (I think the free Visual Studio Express still comes with Spy++ and ManagedSpy, but if not, search for an equivalent), you can see what the application is actually seeing when you drive it with the keyboard, and then you can figure out how to emulate that from your Python script.
On top of everything else, depending on how the program is written, it may not accept keystrokes when it doesn't have focus.
By the way, if you're just getting started with Windows GUI automation, you might want to look at something higher level, like pywinauto. That way, you don't have to work out what menu-related messages to send to open the Data menu; you just do something like app.Foo.MenuSelect('Data').