global hotkeys

Discussions related to Visual Prolog
ludieter
Active Member
Posts: 29
Joined: 21 Dec 2010 19:40

global hotkeys

Unread post by ludieter » 20 Jul 2012 12:47

Is there a way to define global hotkeys, i.e. that work when other programs are in focus?
Thx
Dieter

User avatar
Tonton Luc
VIP Member
Posts: 502
Joined: 16 Oct 2001 23:01

Unread post by Tonton Luc » 20 Jul 2012 17:04

Hi,

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

ludieter
Active Member
Posts: 29
Joined: 21 Dec 2010 19:40

global hotekeys

Unread post by ludieter » 20 Jul 2012 17:48

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?

User avatar
Tonton Luc
VIP Member
Posts: 502
Joined: 16 Oct 2001 23:01

Unread post by Tonton Luc » 20 Jul 2012 19:30

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

ludieter
Active Member
Posts: 29
Joined: 21 Dec 2010 19:40

global hotkeys

Unread post by ludieter » 20 Jul 2012 19:50

yes, that would be the idea. I will have a look at the linked info. Thx for your help.

ludieter
Active Member
Posts: 29
Joined: 21 Dec 2010 19:40

global hotkeys

Unread post by ludieter » 2 Feb 2015 18:55

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!

User avatar
Thomas Linder Puls
VIP Member
Posts: 1668
Joined: 28 Feb 2000 0:01

Unread post by Thomas Linder Puls » 3 Feb 2015 11:33

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).
Regards Thomas Linder Puls
PDC

ludieter
Active Member
Posts: 29
Joined: 21 Dec 2010 19:40

global hotkeys

Unread post by ludieter » 3 Feb 2015 21:01

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).

User avatar
Thomas Linder Puls
VIP Member
Posts: 1668
Joined: 28 Feb 2000 0:01

Unread post by Thomas Linder Puls » 3 Feb 2015 21:10

There is a clipboard package in gui/clipboard.
Regards Thomas Linder Puls
PDC

ludieter
Active Member
Posts: 29
Joined: 21 Dec 2010 19:40

global hotkeys

Unread post by ludieter » 3 Feb 2015 21:24

Quick response! Thx.

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

User avatar
Thomas Linder Puls
VIP Member
Posts: 1668
Joined: 28 Feb 2000 0:01

Unread post by Thomas Linder Puls » 4 Feb 2015 9:09

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.
Regards Thomas Linder Puls
PDC

ludieter
Active Member
Posts: 29
Joined: 21 Dec 2010 19:40

global hotkeys

Unread post by ludieter » 4 Feb 2015 12:56

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?

User avatar
Thomas Linder Puls
VIP Member
Posts: 1668
Joined: 28 Feb 2000 0:01

Unread post by Thomas Linder Puls » 5 Feb 2015 9:24

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.
Regards Thomas Linder Puls
PDC

ludieter
Active Member
Posts: 29
Joined: 21 Dec 2010 19:40

global hotkeys

Unread post by ludieter » 5 Feb 2015 13:13

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..

User avatar
Thomas Linder Puls
VIP Member
Posts: 1668
Joined: 28 Feb 2000 0:01

Unread post by Thomas Linder Puls » 5 Feb 2015 13:34

The function SendInput is mapped to gui_api::sendInput.
Regards Thomas Linder Puls
PDC

Post Reply