Notice: This forum has been recovered from an old backup, so some content, links, and dates may be outdated. The forum is currently read-only while we restore sign-in and registration functionality. Details

If you find this forum valuable and would like to help keep it online, donations to help cover hosting and domain costs are greatly appreciated, but never expected. You can support the forum through Buy Me a Coffee or Ko-fi. Thank you for helping preserve the EventGhost community.

VNC Keyboard Events

If you have a question or need help, this is the place to be.
stottle
Plugin Developer
Posts: 636
Joined: Sun Apr 26, 2009 10:59 pm

Re: VNC Keyboard Events

Post by stottle »

Ok, I can see where in the keyboard hook you can see if the keypress is simulated or not. The problem is that EG uses simulated keypresses for a lot of its communication with other programs. So I'm wondering if by having AHK send simulated keys to EG, then having EG create a simulated key in response caused an infinite loop that pegged your CPU?

One trick is that you can set a dwExtraInfo field when you simulate keystrokes. I'm thinking maybe you can have EG use one value and HippoRemote use another? Then you could potentially filter on HippoRemote's value within the EG keyboard hook. Any idea if HippoRemote sets dwExtraInfo to a particular value?

Brett
dustobub
Posts: 24
Joined: Wed Nov 05, 2008 10:57 pm

Re: VNC Keyboard Events

Post by dustobub »

stottle wrote:Ok, I can see where in the keyboard hook you can see if the keypress is simulated or not.
Could you point me to this?

The problem I was having with CPU usage was related to the number of EventGhost processes that would get spawned when using EventGhost.exe -e MyEvent. When you held a keypress down, it would launch many processes, spawning some before others finished, causing a huge CPU load. Using the VBscript doesn't launch a new EventGhost process, so it is much more CPU efficient.

I don't think there should be any problems with receiving and then sending emulated keystrokes, AutoHotKey does this with no issues. The dwExtraInfo flag that you mentioned, is this the method that VNC uses to send Ctrl-Alt-Delete? I'll have to take a look at UltraVNC as HippoVNC is built off of that.

Thanks,
Dustin
stottle
Plugin Developer
Posts: 636
Joined: Sun Apr 26, 2009 10:59 pm

Re: VNC Keyboard Events

Post by stottle »

The code is in [EG directory]\extensions\cFunctions, in the keyhook.c file. There's a line:

Code: Select all

isInjected = kbd->flags & LLKHF_INJECTED;
If isInjected is true, EG won't try to handle the key.
dustobub wrote:I don't think there should be any problems with receiving and then sending emulated keystrokes, AutoHotKey does this with no issues. The dwExtraInfo flag that you mentioned, is this the method that VNC uses to send Ctrl-Alt-Delete? I'll have to take a look at UltraVNC as HippoVNC is built off of that.
Yes, but AutoHotKey may use customized code to do so (I have no idea, just saying that because it works that way for AHK, doesn't mean it works the same for EG). As for the dwExtraInfo, it looks like when you create a simulated key, you can choose to set this value to an app specific value. I think it defaults to zero if not actively set. My thought was that if HippoVNC actively set it, then the value could be used to filter Hippo specific events and ignore any other simulated keys. No idea on Ctrl-Alt-Delete.

Brett
dustobub
Posts: 24
Joined: Wed Nov 05, 2008 10:57 pm

Re: VNC Keyboard Events

Post by dustobub »

Do you know when that C code gets compiled? Is it at runtime?

Update - I don't seem to have that directory. I guess you are looking at the source code. Maybe I'll make a build with statically setting that to False. Probably a bad idea...
stottle
Plugin Developer
Posts: 636
Joined: Sun Apr 26, 2009 10:59 pm

Re: VNC Keyboard Events

Post by stottle »

No, it is compiled into cFunctions.pyd, which is also part of the EG distro ([EG Dir]\lib26\site-packages). You can recompile and replace cFunctions.pyd.

Brett
stottle
Plugin Developer
Posts: 636
Joined: Sun Apr 26, 2009 10:59 pm

Re: VNC Keyboard Events

Post by stottle »

Well, I learned a lot about keyboard handling today.

Here's a modified cFunctions.pyd that includes a handler to pass only simulated keypresses to EventGhost. For it to work, you need to use the SimKeys plugin (the attached __init__.py file). Enabling the plugin should have SimKey events start showing up. Other that the fact that it only applies to simulated keys, it should work just like the keyboard plugin.

To use:
1) Replace cFunctions.pyd (in [EG directory]\lib26\site-packages) with the version attached to this post.
1b) I couldn't attach a .pyd file, so rename cFunctions.pyd.txt to cFunctions.pyd
2) Create a SimKey directory (in [EG directory]\plugins) and save the attached __init__.py file in that directory.
3) Restart EG and load the SimKey plugin.
4) Add SimKey.[key] to macros to trigger from the new events.

I successfully tested using keybd_event calls (what UltraVNC uses internally), but I'm not running HippoRemote or VNC, so there could be something that I missed. Please let me know how it works.

BTW, it looks like keypresses sent to specific windows (like EG's SendKeys functionality) will not go thru the EG keyboard hooks. So they don't show up as SimKey events.

Brett
Attachments
__init__.py
SimKey plugin file
(3.25 KiB) Downloaded 325 times
cFunctions.pyd.txt
New python dll for simulated keyboard hooks.
(69.5 KiB) Downloaded 324 times
Last edited by stottle on Fri Nov 27, 2009 11:43 pm, edited 1 time in total.
dustobub
Posts: 24
Joined: Wed Nov 05, 2008 10:57 pm

Re: VNC Keyboard Events

Post by dustobub »

Brett,

Thanks a lot for working on this. I don't have a EventGhost\Extensions folder, so I put that pyd file in EventGhost\lib26\site-packages. This got the SimKey plugin to load, and recognize keys, but it does have some issues. I see lots of "Simkey info = 0" when I press simulated keys, and it also doesn't seem to be trapping the simulated keypresses. Did you intentionally not trap keys? I also got EventGhost to hang once, but I haven't reproduced it yet. It looks like Simkey info = 0 is a debug statement, what does it mean? Once again, thank you very much for working on this.

Dustin
dustobub
Posts: 24
Joined: Wed Nov 05, 2008 10:57 pm

Re: VNC Keyboard Events

Post by dustobub »

Also, multiple button presses aren't picked up ideally. For example,

Pressing LShift+LCtrl+LAlt+E looks like

SimKey.LCtrl
SimKey.LShift+LCtrl
SimKey.LShift+LCtrl+LAlt
SimKey.LShift+LCtrl+LAlt+E
SimKey.LShift+LCtrl+LAlt
SimKey.LShift+LCtrl
SimKey.LCtrl
stottle
Plugin Developer
Posts: 636
Joined: Sun Apr 26, 2009 10:59 pm

Re: VNC Keyboard Events

Post by stottle »

Sorry, your right about \lib26\site-packages. I pasted the wrong location. I fixed that in my post above. Also, I had a debug print in the __init__.py file to show the dwExtraInfo which I forgot to delete. That gave a bunch of extra messages. I uploaded a new __init__.py file above, which doesn't have that print statement.

As for the trapping, I just copied the handling from the Keyboard plugin. It should post the messages to the screen, but only trap if you have a macro that responds to the keystroke. Is that not what you are seeing?

Finally, I will have to take at the multiple button handling.

Brett
dustobub
Posts: 24
Joined: Wed Nov 05, 2008 10:57 pm

Re: VNC Keyboard Events

Post by dustobub »

Got it, yeah I was wrong about the trapping, I forgot you had to have a macro associated. I'll test the new plugin and get back to you. Thanks!
dustobub
Posts: 24
Joined: Wed Nov 05, 2008 10:57 pm

Re: VNC Keyboard Events

Post by dustobub »

Things are looking better. No debug statements and I can correctly trigger macros. The same cascading multiple key thing happens though. Only the longest key combo actually gets sent to the system, but SimKey reports the others. Also, it doesn't look like repeated keys sent from VNC are captured through SimKey, only the first one gets reported even though the system responds to the repeated key. Is there any debug I can get you?

Thanks again,
Dustin
User avatar
jinxdone
Plugin Developer
Posts: 443
Joined: Tue Jan 02, 2007 4:08 pm

Re: VNC Keyboard Events

Post by jinxdone »

dustobub wrote:Also, multiple button presses aren't picked up ideally. For example,

Pressing LShift+LCtrl+LAlt+E looks like

SimKey.LCtrl
SimKey.LShift+LCtrl
SimKey.LShift+LCtrl+LAlt
SimKey.LShift+LCtrl+LAlt+E
SimKey.LShift+LCtrl+LAlt
SimKey.LShift+LCtrl
SimKey.LCtrl
If you stop to think about it it is never possible to press or release any buttons at the exact same time. They will always be registered in some order, even if the events are only milliseconds apart. You don't have to mind the other key combinations only use LShift+LCtrl+LAtl+E if that's what you were looking for.

If this behaviour is no-good for you then other ways I can think of how it could possibly work are all not good also:
1. you pre-define the possible key-combinations the plugin can trigger (might be good or bad, depending on the intended use)
2. only trigger single events on keydown, always one event for each key (would be hard to use in practice)
3. the plugin has a time-delay after first button is pressed, after which it triggers whatever key combination is pressed at the time (bad idea)
dustobub wrote:only the first one gets reported even though the system responds to the repeated key.
I didn't look yet, but if it's triggering enduring events like the keyboard plugin, you should only see one event in the log view. You can test it for example with the move mouse in direction action, it should keep moving the cursor while you press and hold the buttons.

----

I spent a little time tinkering with a non-blocking standalone keyboard hook plugin using pyHook. It works otherwise ok, but for some reason if you have the EG window focused and press keys in rapid succession the EG window will hang.. I didn't get to the bottom of why this is happening, in my (rather simple)test application it worked without any issues.

Use the EG's own keyboard hook with the method stottle presented instead of this plugin.

I'm posting this version only incase somebody wants to take a look at the code. Please don't expect it to work properly, because it doesn't.

-jinxdone
Attachments
KeyboardHook_plugin_test.zip
KeyboardHook plugin test (buggy). EG window may hang if it is focused while buttons are pressed.
(36.21 KiB) Downloaded 232 times
Last edited by jinxdone on Sat Nov 28, 2009 1:34 am, edited 2 times in total.
dustobub
Posts: 24
Joined: Wed Nov 05, 2008 10:57 pm

Re: VNC Keyboard Events

Post by dustobub »

Cool, I'll play around with that plugin too. As for the cascading keypress, I understand why they would happen on a real keyboard, I just would expect VNC to directly send only the final command, it must artificially insert delays.

For repeating keys, it does behave like the standard plugin. Is there any way to detect how long a key is being pressed in EventGhost using the standard keyboard plugin?

Thanks,
Dustin
User avatar
jinxdone
Plugin Developer
Posts: 443
Joined: Tue Jan 02, 2007 4:08 pm

Re: VNC Keyboard Events

Post by jinxdone »

Well, the cascading keypresses could also be due to a queued handing of the buttons. (again, didn't look in the EG source, but this is how my test plugin works)

Usually it's not a problem though.
skreien
Posts: 14
Joined: Fri Nov 27, 2009 4:32 am

Re: VNC Keyboard Events

Post by skreien »

From the testing I've done so far it seems to be working great! Thanks Brett!
Post Reply