Background
I have a program that calls various functions based on hotkeys and the clipboard. I am using pyperclip and aoikhotkey. This combination is working very well. However, I would like to improve it even more if possible. Currently, my workflow is as follows:
Highlight target text using my mouse
Press Ctrl+c to put it in the clipboard
Press my hotkey combination to call the function which uses the clipboard content.
I would like to eliminate step 2 and have the function called by the hotkey "scrape" the content on my screen (possibly using mouse or cursor event monitoring).
Question
Does anyone have any ideas about how I can do this? I suspect that I might be able to use Tkinter somehow to accomplish this, but I don't have any experience working with Tkinter, so if anyone has any suggestions or hints, I would be grateful.
Reference
Here's a post asking a similar question, but using the Autohotkey scripting language:
Get Selected Text Without Using the Clipboard
Update
The title of this question was originally "Getting selected text without using the clipboard". However, I changed it because the comments section to this question helped clarify my actual needs and goals.
Select Text without using the Clipboard is i think not possible, you will need the Clipboard to Copy the Text (Ctrl+c) - you can do that with your Keyboard Device by pressing the keys or you can do that by command Send a Hotkey stroke:
pyautogui.hotkey('Ctrl','c')
With python Packages pyautogui and pywinauto - you can send any text or hotkeys without to having to do a pressing on a Keyboard Device. - and if you want to use with your Mouse device you can use AutoPythonLauncher Software with this you can create Clickable Images on the Screen - watch this video Click Here
Related
I have a script that is used to login in to a company-made application and click the right buttons like "continue", or "ok", etc. to perform a certain process. However, I have had to use screenshots of these buttons to click in order to do this using pyautogui. Is there any package or way to automate this process without using images. Maybe it can detect the text of the button and click it. I do not have identifiers for the buttons available and no access to the code/info behind the application. Let me know if you have any ideas. Thanks!
I have a few questions that may be helpful:
Does the layout of the buttons change? If it's always the same you can just program the correct locations and timing and not worry about reading the screen.
If you really have to read the screen, look into optical character recognition (ocr).
Is the application keyboard accessible? If so, using Tab and Enter to activate the buttons is simpler than controlling the mouse. Also, if it was made by superstars you can use find (ctrl-F) to search for the text on the buttons and go to them.
This answer is pretty vague, but I can only be as specific as the question asked.
I am trying to develop a script in Python 3.7 using Appium in which I want to enter any text in the text fields using the keyboard opened by the app. Is there any way to type the text using keyboard without using send_keys method in appium.
I am also not sure how send_keys works internally, whether it only works when the app keyboard is opened or its just simply enters the text without keyboard opened.
I would prefer to type the text, character by character, using the keyboard of the smartphone.
Actually, this is not a good idea because there is no way to touching keyboard keys as an element. I mean the appium cannot see the keyboard as elements. Also, you will need this if you only want to test the functionality of the keyboard itself. Otherwise technically element.send_keys() acts the same with no difference on std-out. Also, element.set_text() act the paste if you want.
Anyway, to reach this you should:
1- Open the keyboard by clicking on the input field
2- Find the coordinates of the keys and store them in a variable.
3- Touch the coordinates directly.
Ok, so what I want to do is allow my program to send mouse movements and keypresses (both mouse and keyboard) to a particular task without having to be tabbed into the task so I can do other things on my computer with the mouse and keyboard while the task runs. Is it possible to do this relatively simply with existing python modules?
example of what I want to do:
task='application name'
task.leftclick
task.moveX(int)
task.moveY(int)
task.keypress(r)
All while being able to use my mouse and keyboard normally on a different application.
Thanks for the help in advance!
(Python3.6)
For anyone who happens upon this post, I found https://pypi.org/project/ahk/ I haven't looked into it fully but either you can use this or create an auto hotkey script and just call that with you python code to achieve what I wanted to do in the question.
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').
I have a application running in python, i want to send the input taken from the text box of the webpage and send it as input to the application and once again the output of the application which is in text format back to the result page on web.
thanks a lot for your time :) :)
Here's my suggestion: modify your program to include a button for doing the transformation. When you click it, it should take the contents of the clipboard, do whatever transformation you want, and put the result back on the clipboard.
Once you do that, to use it you select the text from the widget, use the keyboard to copy it to the clipboard, press the button on the GUI, then click back in the widget and use the keyboard to paste.
Alternately, your program can just poll the clipboard every couple of seconds, do the transformation and put the results back (make sure your automatic polling ignores any changes caused by itself). With that you can do a select-all, copy, wait a couple seconds, then paste.
This is pretty trivial to do in both Tkinter and wxPython, and I would guess it is equally trivial with most other GUI toolkits.
Have you tried PyQt4 which has this ability built-in? You can do what you're asking in about ten LOC.