Python uses Win32API system hooks
Blog Category:
Python
There is a requirement: The customer's test program scans the barcode of a product, but it does not and the system verifies the function (that is, from inside the system to check whether it can be tested in this test bit). For example, there are 10 test bits, this is the 4th one, then the first 3 test bits must be all pass, the 4th test bit can be tested, this is said validation. Of course there are other situations, such as each product the same test bit can only be measured 2 times, and then the 3rd system should be prompted to repair.
The problem we encountered is that the client gave the program did not verify this piece, so that customers change the program is not very good to do. Alas, who makes the current customer so bull.
So let's see if we can handle it ourselves. The idea is: we add a program to receive the product's bar code, and after the system verification if you can continue to test, the bar code is then written to the customer Program bar code text box, if the process error, prompt error, let the operator fix.
The difficulty is how we find the barcode text box for the client program. So from the online search (we use Python, we need to install the Pywin32 module) WIN32API usage, fortunately found a little, here is an example (in the Python shell):
First, import Win32gui, Win32con
Second, use Win32gui. FindWindow Find the target program:
Win = Win32gui. FindWindow (None, ' User Login ')
Third, use Win32gui. FindWindowEx Find the target text box:
Tid = Win32gui. FindWindowEx (Win, none, ' Edit ', none)
Four, use Win32gui. SendMessage send text to the target text box:
Win32gui. SendMessage (Tid, Win32con. Wm_settext, None, ' hello ')
Of course, you can continue to find the next text box:
Username = Win32gui. FindWindowEx (Win, Tid, ' Edit ', None)
Just haven't found the function to add a return to the string, in Notepad can be implemented, do not know why not here. If the heroes have the hope of knowing, please enlighten me.
This is the first time we have studied here. In case you forget, keep it here for later use.
Update: You have found a way to send a carriage return:
Win32gui. SendMessage (Tid, Win32con. Wm_settext, None, ' hello ')
Win32gui. PostMessage (Tid, Win32con. Wm_keydown, Win32con. Vk_return, 0)
Win32gui. PostMessage (Tid, Win32con. Wm_keyup, Win32con. Vk_return, 0)
Go python using Win32API system hooks