How can Perl fill out fields on a GUI made in Visual Basic? - perl

I have a script that runs several little programs I don't have the source code to, one of which requires filling out some fields in a GUI. I've been doing this by hand, but I'd like to have the Perl script focus the GUI window, then enter some hardcoded text into each field and close the window.

In the past I've used the Win32::GuiTest module for tasks like this. Have a look at the example scripts and documentation.

Unless there's a specific reason you're using Perl, Autoit is a Basic-like scripting language pretty much specifically designed for automating GUI tasks. It's very easy to pick up.
You can have it wait for a window to become active, send any sequence of keystrokes or tell it to specifically focus on a GUI element with a given handle, and much more. You can also package the scripts as standalone executables, which can be a nice benefit when you need it.

You might want to look into Win32::OLE. There's also a book on this topic.

Related

"Save as" an open file from Command Line

I have a large folder of DWG files and want to convert them to DXF files, using Solid Edge. After opening the documents, is it possible to "Save As" from the command line or powershell?
Is this a program by program line of code or is it universal for all programs?
So if I wanted to save a .docx document open in Microsoft Word as a .pdf (for want of a better example) can I use that same line of code?
Any help appreciated...
Well since you want to convert from one Autocad format to another, you could do it using Autocad's command line.
https://knowledge.autodesk.com/support/autocad/downloads/caas/downloads/content/autodesk-customization-conversion-tools.html?_ga=2.88877275.1703552679.1574826072-7420195.1574826072
This does require you writing all of the scripting of course.
Alternatively, there is this handy scripted mass converter someone wrote using lisp and they wrote a custom script executor wrapper thingy but their scripting supposedly requires the full version of autocat (at least version 2010 to accomplish this.)
https://www.cadtutor.net/forum/topic/51941-autocad-mass-convert-dwg-to-dxf-batch-convert-dwg-to-dxf-mas-dwg-convert/
That said the official AutocCAD conversion command-line utilities are also going to use LISP scripting, so you might want to just take the second script, and work through it manually testing against the normal AutoCAD utilities until you can get it working for your needs to sort of jump start you.
If you do that I would suggest re-posting with tags for LISP and AutoCAD and give them a sample of what you have got if you end up going the official tools and your own or jump-started script route.
Hope that will be helpful to you and others in the future! :)
As commented beneath my question,
No, it would not be universal
So, no, there is no way of using a single command "save as" on every single program, and as Solid Edge doesn't have a command line API, that I know of, I would have to write a program for it.

Changing Code At Runtime While Debugging

I am using Eclipse Kepler Service Release 2 , EPIC 0.5.46 and Strawberry Perl 5 version 18 for perl programming. For debugging I am using Eclipse debugger and PadWalker .
I have an interactive perl program that writes to files based on answers provided by the users to multiple prompts. While debugging , every time i change a single line of code I have to rerun the whole program again and provide inputs to every prompt , which is really time consuming.
Is there a way to make changes to the code in a sub routine , in the middle of debugging session such that the instruction pointer resets itself to the first line of that sub routine. This way i do not have to restart the session to recompile the new code.
Appreciate your inputs and suggestions. Thank You!!!
What you want to do can be done, and I've done it many times in Perl myself. For example, see this.
However although what you describe may work (and is a bit dangerous), the way it is generally done a bit different and safer.
First one has to assume a regular kind of command structure like a command processor, or say a web server.
In a command processor or web server, you read a command (or get a web request), perform an action, then read another command, perform another action and so on. From your description, it sounds like you have such a structure.
In my case, I have each debugger command stored as in Perl file. This is helpful not only for facilitating this task, but also for understanding, testing and changing the code.
Given this kind of program structure, instead of trying to change the program counter, you complete the command and at the level where you are about to read a new command, you make the change and then reload the file which changes the code.
The specific Perl construct to do this is called do. Don't use require or use which will load in a Perl file only if that file or module hasn't been previously loaded. In your situation, you want to reload even if it has been loaded before.
So now how do you get to be able to issue a do command? As you suggest, you could do it through a debugger. Assuming you have this overall program stucture as described above, you put the breakpoint somewhere a common point in the caller which loops over things to process, rather than try to change things in indvidual commands.
And you don't even need a debugger to do this! Many web frameworks like Ruby on Rails, have a "development" mode where they save timestamps on files that implement functionality. If the file has changed they issue the "do" command before running the request.

How to create a Notepad++ macro to run multiple plugins automatically?

I am using Notepad++ for different languages i.e: JAVA, C, C++. For each of these languages I have installed plugins to make coding easier in Notepad++.
The problem is that every time I start Notepad++ I have to go and run all those plugins manually. I tried recording a macro so that it will perform all these actions by one click but it didn't record anything I did with the plugins. The macro will record any changes I bring to the code or if I save the code to some other location but it won't record the actions performed by the plugins.
Can anyone guide me to a solutions.
Thank you in advance.
Have a look at AutoHotKey tool. It can send keystrokes/mouseclicks to Notepad++ so you can easily combine invoking many menu items into one command. (And much more like work with clipboard, ask for values in input boxes, run apps or DLL's.) Please see AutoHotKey usage with Notepad++ in this answer.

How to fill textboxes on a website with MATLAB

I'm trying to use MATLAB to fill in textboxes on a webpage in Internet Explorer without typing directly into the URL. Can anyone explain to me how to do this? I'm pretty lost. I really appreciate any help you can give me.
Thanks!
While I have seen this done before (i.e. running a MATLAB script that automatically fills in fields in Internet Explorer), to the best of my knowledge, I do not believe that there is an actual MATLAB command to directly interface with IE.
Instead, you can make use of the MATLAB command system to call an external program that actually does the interfacing with IE.
For example, you might be able to make a Visual Basic program that interfaces with IE through the InternetExplorer object. I'm not too familiar with VB, but this doc might help. Once you've created this program, use MATLAB's system command to execute it (passing command-line arguments to define what/how to fill in the textboxes).
Take a look at the doc for system for more info.
I've done it many times with a small program called Autohotkey.
With this program you can write a script, that will move the mouse / click the keyboard. you can pass string arguments and use it inside the script. once done, you can call this script from matlab.

How can I intercept and correct keypresses at a low level?

I keep typing "t eh" instead of " the" which is, of course, annoying in the amount of time it takes me to correct myself.
The obvious answer is "Learn to type, noob!" or at least to type more slowly and/or more correctly. This error is frighteningly consistent so it appears I've trained my muscle memory for that pattern already.
But I'm wondering if it's possible to write a small, windows portable script or application that, when it detects the incorrect sequence, backspaces and corrects it automatically at a layer where it would apply to any keyboard input.
Does C# have access to that layer of the OS that intercepts keypresses systemwide?
Will I run into UAC issues with Vista?
Am I re-inventing the wheel (ie, are there open source tools I can modify or use out of the box)?
In DOS this sort of thing was quite easy and one could make TSRs (Terminate and Stay Resident) programs that would, for instance, give you a calculator onscreen with a special keypress. Not to mention the many, many practical joke programs based on this concept (dial "M" for monster!)...
I would, of course, never suggest such a utility could be used that way for co-workers...
-Adam
On windows you could use AutoHotKey. That allows you to create little scripts or macros to automate and correct things like mistypes.
One use was posted on lifehacker which took the common mistyped words and corrected them. It is at http://lifehacker.com/192506/download-of-the-day-universal-autocorrect
UPDATE Per Comment: This is Free software and windows only as far as I know.
The above script is just an example of what it can do. There are a slew of scripts available at AutoHotkeys Site
I suggest AutoHotKey. If you've never used it before, have a quick read of the tutorial: http://www.autohotkey.com/docs/Tutorial.htm
The feature you are looking for is called "hotstrings." http://www.autohotkey.com/docs/Hotstrings.htm
In your case, your script would look something like:
::teh::the
That's it! Add other things you want corrected on additional lines. AutoHotkey scripts can be compiled so you don't have to install AutoHotKey on all of your machines.
It's a very cool program. It's primary use (for making custom hotkeys) rocks! These scripts are system wide so you'll also probably want to make a hotkey to be able to turn them off too!
EDIT: In a comment, it was mentioned that he actually types "t eh" (with a space in it) and I wondered if something additional would be needed for it to work. I just tested it and it works fine. Just install autohotkey, and create a file with the .AHK extension. In that file put in the following line
::t eh::the
and save the file. Then double-click on the AHK file to load AutoHotKey with your script (you'll see a green square in your system tray to let you know it is running). It should work fine!
Yes, you can use pinvoke commands from C# to intercept the low-level os commands. I recommend you take a look at http://www.pinvoke.net. The coding isn't easy but it does work.
I suggest learning to type more slowly. I also suffer from "teh" and "ahve" in part due to autocorrect giving me the leniency. If you forced yourself to retrain then you would not be at a disadvantage when using someone else's machine.
Not to mention the unfortunate event when you need to write "t eh" and are being prevented by an overzealous 'corrector'.