Command to run a HotKey

I'm looking for a command that I can assign to a button that will run a HotKey.

All HotKey commands that I have looked at do the opposite, that is, the HotKey runs a command.

What I want is a button, that when pressed, will execute ALT+F4 to close the current open window.

The Opus Close command does not do that, it closes only open Listers. I need to do Alt+F4 to close any open window.

Thanks;
Doc

What are you actually trying to do?

When would you run the command, via what, to close which window?

As stated above I want to add a button to my tool bar that will do Alt+F4 when clicked.

The BIG red X in the JPEG is where I want to assign this command.

Doc

Alt-F4 on which window?

On the toolbar? There are commands to close toolbars so you don't need to go to such lengths just for that.

Or on another window? Which one?

I don't want to close the toolbar; I want to close other windows such as Outlook, Excel, Word, Listers or any other open window. This would be the same as clicking on the small red x in the upper left corner of any open window.

There are several reasons why I want to do this with the big red X that I have installed on the floating toolbar.

Doc

The problem is that once you click a button on an Opus toolbar (I seem to recall you crafting a floating Opus toolbar as a Start Menu replacement or something) you're making that toolbar 'active' and giving it input focus. So guess what will happen if you run <Alt+F4> against a floating toolbar...?

That said, it's trivial to compile an autohotkey script to run something like:

; Alt+F4
Send !{Tab}
Sleep, 25
Send !{F4}

...which you can then call from an Opus button. It's doing an <Alt+Tab> first to switch back to the previously active window, waiting for a small bit of time for the window change to complete, then sending <Alt+F4>.

But I'm wary of suggesting you really rely on this. Depending on system load, it could still end up closing the current window, or doing nothing at all if the window switch takes some fractional bit of time that causes the Alt+F4 keystroke to go to the desktop or something. It could also have other unexpected results - like closing some ~other window you didn't intend to close (like it did to me when it closed Opera midway through drafting my original version of this reply :wink: even though it was several windows 'behind' the last active window that Alt+Tab should have switched to).

Ahhh... I'm beginning to see the heart of the problem; as soon as I click on the big red X on my toolbar IT than has focus and Alt+F4 will close down the toolbar... not what I want.

It is not exactly the same as manually pressing the Alt+F4 keys on the keyboard with Outlook selected as focus.

It may be that the standard Close Lister command is all that I can have.

But, I'm also thinking that the big red X toolbar button can still work IF...
1: I can somehow make the command first select the previously active window (such as the Outlook example) before doing Alt+F4.
2: Adding some code that would ignore the toolbar as a top focused window (when the big red X is clicked) then run Alt+F4.
3: De-focus the toolbar then run Alt-F4.

Items 2 & 3 may be related.

Any ideas?

This gives me a lot to thinks about.

Thabks;
Doc

:thumbsup:

I know this doesn't really help you to make the big X button close the current program. But you could close it via a 3button.

LMB opens the program (example ImgBurn.exe)
RMB runs a MS-DOS Batch Function that closes the program.

taskkill /im ImgBurn.exe

To find the name of the program, just open Task Manager -> Processes tab after the program has been started.

Thanks, not exactly what I need.

Doc

I manually tried

and you are right, the results can be erratic.

Doc

Trust me, you will not be able to make that work reliably.

If you want to close a window, click the close button in that window, not in some other window. :slight_smile:

(And/or do what I do and bind a spare mouse button to Alt+F4 for a quick way to close the active window.)

I've used that before and it does work very well. Problem is, even with 13 fully programmable mouse keys, I'm out of keys.

Same for the keyboard... out of keys.

Clicking on the little x in the top right corner of each window is what I want to get away from. I often have many windows of different sizes open and sometimes want to quickly close a few of the top-most ones & have always found Alt-F4 to work well EXCEPT when the windows are of different sizes then it is a pain as I have to move the mouse all over the place to click on the x's in different locations. It's actually quicker to manually press the Alt+F4 keys to close different size windows. Just thought having a single BIG red X in one consistent location would be much nicer.

Oh, well; maybe something will come up. I'll sleep on it.

Thanks again;
Doc

Think I have come up with an answer. I was looking at my Universal Key Commands Excel database I put together a year or so ago which has every key for many common programs including Windows. I recalled seeing several ways to back track or recall previous focused windows.

The answer is the Win+Tab key. No matter what window was last opened before selecting an Opus toolbar, Win+Tab ALWAYS returns to the last focused window. It seems that it also completely ignores the Opus toolbar as not even being there.

Sooo... all we need is something like....
1: Win+Tab.
2: Alt+F4.

And we're done.

Is there a way to enter simple commands like that directly into an opus toolbar button or do we need to run something like AutoHotKey?

Doc

I don't think there's a DOpus-Command to send keystrokes. You can use nircmd.exe to do this but it will probably also close the floating toolbar at some point when executed from the toolbar.
What you can do to get around this is to pin a shortcut which executes your command to the taskbar. To do that write the following command to a textfile and rename it to e.g. "test.ncl":

sendkey alt down
sendkey tab down
wait 25
sendkey tab up
sendkey alt up
sendkeypress alt+F4

Now create a shortcut to nircmd.exe, pin it to your taskbar and edit it to do [path]\nircmd.exe script [path]\test.ncl

VERY interesting, Kundal.

I will take a long, hard look at the nircmd.exe option as I have never used it before.

I'm also looking into simply entering the Win+Tab and the Alt+F4 into a simple BAT file and calling that up with my big red X.

Either way, thanks again;
Doc

The following nircmd script is fully working (with a little flicker) from a button in a floating toolbar. If your toolbar is not docked to the left side of your screen you'll have to change the values for the "movecursor"-commands accordingly.
It moves the cursor out of the toolbar (adjust the value in the first line to fit the width of your toolbar to make it work even if you click the button near the edge of the screen), applies the hotkeys and moves the cursor to the edge of the screen first and some pixels to the right afterwards to bring the toolbar up again with cursor placed above the button.

movecursor 100 0
sendkey alt down
sendkey tab down
wait 25
sendkey alt up
sendkey tab up
sendkeypress alt+F4
movecursor -500 0
wait 25
movecursor 30 0

Is all this really quicker, easier and more reliable than simply clicking on the close buttons of the windows you want to close? :slight_smile:

As I said...

It's just nicer, like Opus is nicer than Explorer.

Besides, it's the little things that makes life "nicer".

Doc

To throw more confusion into the picture, you are looking for a subset of the whole automation process.

I use Macro Express. The Pro version.

It has a reasonably capable scripting language that can work with Windows titles, processes and the like.

I don't know if it could do what you want, and I haven't tried to make it play ball with DOpus, but I use it to take some of the cues for actions that you describe.