Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Design Time Macro(simulation of keypresses) For executables

Status
Not open for further replies.

KALP1

Programmer
Aug 26, 2016
102
0
0
IN
Is there any source code or utility to implement macros which are available for programmers in Exe(executable file) for Users.

Can we get VFP's source code written for Macros.

 
I assume you are referring to keyboard macros: the kind that you get from the Tools / Macros menu (as distinct from macro substitution). If so, this is a design-time facility; it is not available from within a VFP EXE.

However, you can create your own macro facility fairly easily. One way to do that is with the ON KEY LABEL command. You can assign any series of keystroke to a variable, and then when the user hits the specified key, use the KEYBOARD command to simulate that string being typed.

You will also need a way of letting the user specify the characters that they want to assign to the key in question. To do that, you will need a simple form in which the user can type the relevant string, and also specify the relevant key.,

If would be a little more difficult if you want allow the character string to also contain control characters, such as ALT and CTRL combinations, or cursor movement keys. In that case, you will probably need to use the Keypress event to trap the required keys in the form mentioned above, but the basic principle will be the same.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
There is PLAY MACRO.

That said, it's rather an outdated part of the language, it's mentioned in conjunction with @GET, BROWSE, CHANGE, and EDIT (yuck). Maybe it also works in conjunction with todays winform controls. If you want to automate yoiur application, eg for testing, there once was foxrunner. Since VFP has deprecated almost all third party vendors are gone. You will find this, but I'm not sure you can order and use it, if your goal is in that direction.

Since VFP7 intellisense was introduced and has much more to offer for the kind of support you need writing code. Some of the features of intellisense like offering a dropdown combo to choose options could also be helpful for writing texts. Doug Hennig has written several papers on using Intellisense at runtime. You may have a read on this:
Bye, Olaf.
 
Yes, Play Macro would work with a predefined set of macros (in a foxuser resource file) that is shipped with an application. But most people who want "macros" want their users to create them, and Play Macro won't help at all with that. (Although the OP's wording was vague enough, this might actually cover the need.)
 
Thanks Mike,olaf and danfreeman

PLAY MACRO worked for exe but as danfreeman already stated,my users want to create macros on the fly,assign key and use them so I think Mike's Suggestion would work.

Now I have to just record a macro as Mike suggested and assign it a key. How will I implement Pause feature of macro in that.







 
Utmost apologies ... if this is off topic:

If macros become hazardous (non-bulletproof) for you, possibly consider the hazardous (Window's) sendkeys() method instead (i.e, (per Mike and Olaf and others)).

Code:
oWSH = CREATEOBJECT("wscript.shell")
oWSH.AppActivate("Some Application")
oWSH.SendKeys("Hello World")

In the last 2 weeks I've 'exploited' these 'sendkey-macros' extensively for (1) expediting VFP calls and faxes (RingCentral), (2) writing VFP data within web-forms (BCBS), and (3) exporting VFP data to Google Calendar.

Again, please disregard or rebuke me if this is off-topic. Utmost blessings!
Philip
 
Philip,

Your post is not off-topic. SendKeys() could be a plausible way of simulating keyboard input. But it is really intended for sending keystrokes to other running applications, not to the application itself.

I'm glad you are finding some good uses for it.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
my users want to create macros on the fly,assign key and use them

In theory, it might be possible to do that with PLAY MACRO. If you could programmatically save your user's keystrokes in an FKY file, you could use RESTORE MACROS to get them into memory, then use PLAY MACRO to execute them. However, the FKY is a binary file, and its format is not documented (as far as I know), so you would have to do some hacking to make it work.

How will I implement Pause feature of macro

If you mean something like the TIME clause in PLAY MACRO, then you would have to break the playback string into individual characters, and KEYBOARD each one separately, with a pause between them. Use INKEY() to actually implement the pause.

Or do you mean something like the "insert pause" option in the macro recorder? That would be more difficult, but still do-able. You would need some way to let the user specify the position of the pause, and the keystroke to resume playback. Again, it would probably involve splitting the macro string into multiple sections, KEYBOARDing each section in turn, while listening for the "resume" key after each one. Probably too complicated for me to attempt to offer you some code, so try and do it yourself, and come back if you get stuck.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Well,

SET MACKEY TO F10 and you can record macros also at runtime.
You can also have the menu item with its icon at runtime, simply create a menu, choose "Quick Menu" from the menu menu and you get the VFP menu with Tools->Macros, which has the _mst_macro menu item inlcuding its _mst_macro picture as Resource (icon in the runtime DLL). If you set the shortcut key of that menu item to the MACKEY you trigger the macro recording this way (eg also apply F10 as with SET MACKEY TO F10).

So you don't get the full dialog, but the capability to record a macro, now you can also offer saving and restoring macros, as there also is SAVE MACROS TO and RESTORE MACROS FROM.

Bye, Olaf.

 
Of course, there are also dozens of third-party macro utilities around, including some which are free. They are not VFP-specific, but there's no reason for them not to work in your VFP application.

A quick Google search should turn up some suitable candidates. Some examples: AutoHotKey, SlickRun, QLiner Hotkeys, WinMacro, and the delightfully named Do It Again.

NOTE: The above examples are not recommendations. I have no personal experience of any of the above products.

Although you won't be able to integrate these utilities in your application, they should provide the facilities you are looking for, without you having to write any code yourself.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Yes, I mean the same as you guessed Mike.

Great suggestion Olaf . I will definitely try this and let u know.

if any third party tools are suffice to cater my needs, then will go for that. Thanks Mike


 
Olaf,
How to assign this shortcut key of menu item to MACKEY.
I got system's tools menu with Macro as submenu item. Even macro are recorded with F10 Key.
Now how to proceed further,as I have never used Menu's before so don't know how to do that.
Sorry for asking such small things..

Hearty thanks Olaf as I will not have to move to third party s/w .
 
As I said, the same key as SET MACKEY TO, so if you SET MACKEY TO F10 you also set the menu items hotkey to F10.

MACKEY is not the name of a key, but the name of the setting (MAC is in MACROS, not as in MAC OSX).

If you use the menu designer every item has an options checkbox, click on that and you get a dialog to define menu item hotkeys.

Essentially this just causes the menu item to press the same key you press to directly record a macro, it's optional, you don't need a menu item for macro recording, it's just convenient to offer multiple ways o do the same thing to users and it makes it obvious, that F10 is the hotkey for macro recording, as the menu item hotkey is displayed next to the menu item prompt text.

Bye, Olaf.
 
It's worth stressing that F10 is just an example here. You can set the MACKEY to any suitable key or key combination. For example, SET MACKEY TO ALT+M would work just as well.

Also, if you don't feel confident using the menu designer, you can just ignore it. As Olaf has pointed out, you can use a MACKEY setting, or you can use a menu, or you can use both. But one does not depend on the other.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
>But one does not depend on the other.

Almost right, Mike, the menu item itself does not do anything, it depends on SET MACKEY, so it's SET MACKEY, that you need in any case. Defining a menu item is optional, but it's a simple way to show the necessary key to users.

Bye, Olaf.

 

Ok then, I need not to worry about menu. I have tested using F10 and it is working fine. F10 was just to record macro. How will I Save Macro or save as default or restore buttons.
Macro I made in executable was applicable for that session only. How to permanently save it.
 
SAVE MACROS TO and RESTORE MACROS FROM are the commands you need, as said already. You may provide these via ON KEY LABEL or menu items or a self made Macros dialog or, or, or. What's blocking you to use them as you want?

Bye, Olaf.
 
Oh, "Save Macro to" was the command to save macro. Now I got it.
Thats a lot Mike and olaf. Cleared a long pending work with your help.
 
KEYBOARD("{F10}") for recording (or whatever key you set via SET MACKEY)
SAVE MACROS TO somefile for saving
RESTORE MACROS FROM somefile for loading

And if you use a Procedure for menu items the code can be as verbose as you like, also save and load to a MEMO, eg a per user record of his own macros.
If you do a dialog, a Form, you can do whatever you want in it. You are a developer, aren't you? If you're free to do anything you like and need, what is the hurdle of that? You know the core commands you need, you can look at the help reference about then, you can use them in a click event, form method, whatever you like. However you program anything else.

And if it's not yet has become obvious: The full Macro dialog is NOT available at runtime, you only have the three things you need as commands (read again from begin), so you can either make your own dialog or simply only set some keys or menu items doing the three things.

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top