Page 1 of 2

global hotkeys

Posted: 20 Jul 2012 12:47
by ludieter
Is there a way to define global hotkeys, i.e. that work when other programs are in focus?
Thx
Dieter

Posted: 20 Jul 2012 17:04
by Tonton Luc
Hi,

One way => you can use an accelerator (F1, F2, ...F12) in your TaskMenu.

global hotekeys

Posted: 20 Jul 2012 17:48
by ludieter
Accelerators are only local to the program, no? They do not work if I am in another program, for instance a browser, as far as I can tell?

Posted: 20 Jul 2012 19:30
by Tonton Luc
Sorry, I did not read your first post correctly.

So you want to press F5 from a browser like IE (or from Excel or Word) to start an action in your VP7 application : is it what you want to do ?

Maybe look at gui_Native::registerHotKey + http://discuss.visual-prolog.com/viewto ... sterhotkey

global hotkeys

Posted: 20 Jul 2012 19:50
by ludieter
yes, that would be the idea. I will have a look at the linked info. Thx for your help.

global hotkeys

Posted: 2 Feb 2015 18:55
by ludieter
Some time ago I asked about defining global hotkeys and received the hint to look at
gui_Native::registerHotKey + http://discuss.visual-prolog.com/viewto ... sterhotkey (this link seems to be erased)

Although I tried over time to do something with this, I got no further. I assumed that registering the hotkey correctly would call a menu entry in my program or perhaps do other things not requiring a menu entry?

What I am trying to do now is copy something from outside my program and paste into an edit control.

the first step seemed clear:
_=gui_native::registerHotKey(vpi::winGetActiveWindow(),id_file_open,0x0001,0x31)
Alt-1 should be the hotkey:
0x0001=mod_alt
0x31=K_1

Am I correct so far? how to continue?

Any help is much appreciated!

Posted: 3 Feb 2015 11:33
by Thomas Linder Puls
The API function is described here RegisterHotKey function.

The window that is given as argument will receive a WM_HOTKEY event once the key is pressed.

So the window you supply should not be some "random (happens to be active)" window, it should be the one that handles the hotkey. I assume the task window will be most appropriate, as it is the one that that is available all the time.

To react on the WM_HOTKEY message, you will have to attach a native handler to the window.


This seems to work (update in taskWindow.pro):

Code: Select all

constants     hotKeyId = 17.   predicates     onShow : window::showListener. clauses     onShow(_, _CreationData) :-         _MessageForm = messageForm::display(This),         R = gui_native::registerHotKey(getVpiWindow(), hotKeyId, gui_native::mod_alt, gui_native::vk_1key),         if 0 = R then             E = exception::getLastError(),             exception::raise_nativeCallException("registerHotKey", E, [])         end if,         addNativeMessageHandler(hotKeyHandler).   predicates     hotKeyHandler : window::nativeMessageHandler. clauses     hotKeyHandler(_, gui_native::wm_hotkey, WParam, LParam) = defaultNativeHandling :-         !,         stdio::writef("Hotkey pressed WParam = % LParam = %\n", WParam, LParam).       hotKeyHandler(_, _, _, _) = defaultNativeHandling.   predicates     onDestroy : window::destroyListener. clauses     onDestroy(_) :-         _ = gui_native::unregisterHotKey(getVpiWindow(), hotKeyId).

global hotkeys

Posted: 3 Feb 2015 21:01
by ludieter
Great, thanks for your help, Thomas. I had looked at the registerhotkey function, but did not really get it.

Copying marked data from outside my prolog program to clipboard then uses gui_api::setClipboardData?I couldn't find anything else that looks promising.(but admittedly have not yet had time to try it).

Posted: 3 Feb 2015 21:10
by Thomas Linder Puls
There is a clipboard package in gui/clipboard.

global hotkeys

Posted: 3 Feb 2015 21:24
by ludieter
Quick response! Thx.

But in order to put a string on the clipboard, I have to capture it first?

Posted: 4 Feb 2015 9:09
by Thomas Linder Puls
Are you trying to make another program put its selection on the clipboard?

I believe that is in general impossible, you could try to simulate a Ctrl-C to the application and hope that it handles it as "copy". I don't know how to simulate key strokes to other applications.

global hotkeys

Posted: 4 Feb 2015 12:56
by ludieter
yes, that's the idea. On using the hotkey, grab some text (which is already marked) from another program screen and insert it into my program. I was hoping that that is what gui_api::setClipboardData does somehow, or that there is another command somewhere in the vast number of MSDN commands in gui_api or gui_native.

Simulating Ctl-C is an interesting idea, maybe with outputStream_console?

Posted: 5 Feb 2015 9:24
by Thomas Linder Puls
An application can place data on the clipboard, but it can only place data it have access to. So you cannot place another applications data on the clipboard (unless you somehow get access to the data and in that case you don't really need to put it on the clipboard).

outputStream_console deals with your applications console (if it has one). Dealing with other application is significantly more complicated.

I know that the UI Automation framework can do such things. But that is rather complex, and there are no bindings to it in Visual Prolog.

There may be other ways, but I am not aware of them.

global hotkeys

Posted: 5 Feb 2015 13:13
by ludieter
Thanks for your comments. It seems the (quick and dirty) solution would be to write a small program with Autokey or similar which I then call from Prolog. This would copy marked text and send to clipboard, where my program can pick up the string again..

Posted: 5 Feb 2015 13:34
by Thomas Linder Puls
The function SendInput is mapped to gui_api::sendInput.