SendCustomKey and Windows Key


http://www.s-code.com/forum/Topic2487.aspx
Print Topic | Close Window

By mrowley - Friday, April 24, 2009
How can I use SendCustomKey to send the Windows Key down to the client?

Specifically I am trying to do a WindowsKey + R to get a run dialog and be able to run commands automatically through my application.

I also believe that SendCustomKeyEx is what I need to be able to hold the WindowsKey and get key combinations.  Is this true?  I believe SendCustomKeyEx is not available in the trial version, is there another way I can test this before purchasing the control?

Thanks

M

By Yury Averkiev (s-code) - Saturday, April 25, 2009
You are correct SendCustomKeyEx is the way to go. The ServerX build available for download from the main site doesn't have this method implemented.

Here is the download link for the upcoming ServerX build with SendCustomKeyEx:
http://www.s-code.com/download/beta/scvncctrl_sendcustomkeyex.zip

By mrowley - Sunday, April 26, 2009
Sorry, I should have specified, I am using the viewer control not the server control.

Is there a viewer build that has the SendCustomKeyEx in it?

thanks

M

By mrowley - Sunday, April 26, 2009
Also what is the KeyCode for the Windows Key?

Thanks

M

By Yury Averkiev (s-code) - Monday, April 27, 2009
Sorry, I should have specified, I am using the viewer control not the server control.

Is there a viewer build that has the SendCustomKeyEx in it?


Actually it was my mistake, when I wrote ServerX I actually meant ViewerX. So the download URL points to a ViewerX build with SendCustomKeyEx in it.

With regards of the Windows key. I'm trying to find out its scan code but so far I haven't found it. You see, for ViewerX it doesn't matter what code you are sending via SendCustomKeyEx, it simply sends it to a VNC server. So its up to VNC server to interpret this code and process it.

Attached is a source code file from UltraVNC distribution with the list of scan codes supported by UVNC server.
It might be a good idea to ask UVNC developers via forum.ultravnc.com about what's the Windows key scan code is.

By mrowley - Tuesday, April 28, 2009
This is great info, I have added the updated DLL and have SendCustomKeyEx but cannot get the windows key (65515) to work.

What I am looking for is the WinKey+R combination to get me a run dialog.  But the Windows Key doesnt seem to work properly.  ALT+F4 works as expected, it seems to be a Windows Key Issue, which I beleive is called XK_Super_L in the doc you provided, at least according to the research I did.

Here is the code I am using:

Me.vwr_Main.SendCustomKeyEx(KeySym_Windows_L, True)

Me.vwr_Main.SendCustomKeyEx(Keys.R, True)

Is there something I am missing?  I seem to get the R to go through but not the combination.

Thanks

M

By Yury Averkiev (s-code) - Tuesday, April 28, 2009
A key press event consists of two event: key down and key up event. So you should call SendCustomKeyEx twice, one time for key down and another for key up. You code should look like this:

Me.vwr_Main.SendCustomKeyEx(KeySym_Windows_L, True)
Me.vwr_Main.SendCustomKeyEx(Keys.R, True)
Me.vwr_Main.SendCustomKeyEx(Keys.R, False)
Me.vwr_Main.SendCustomKeyEx(KeySym_Windows_L, False)

By mrowley - Wednesday, April 29, 2009
I understand how it works now, but I still cant get a windows key combination to work.

This works, it brings up the windows menu like it should.

Me.vwr_Main.SendCustomKeyEx(KeySym_Windows_L, True)

Me.vwr_Main.SendCustomKeyEx(KeySym_Windows_L, False)

 

This doesnt work however:

Me.vwr_Main.SendCustomKeyEx(KeySym_Windows_L, True)

Me.vwr_Main.SendCustomKeyEx(Keys.R, True)

Me.vwr_Main.SendCustomKeyEx(Keys.R, False)

Me.vwr_Main.SendCustomKeyEx(KeySym_Windows_L, False)

 

Neither does this:

Me.vwr_Main.SendCustomKeyEx(KeySym_Windows_L, True)

Me.vwr_Main.SendCustomKeyEx(Keys.R, True)

Me.vwr_Main.SendCustomKeyEx(KeySym_Windows_L, False)

Me.vwr_Main.SendCustomKeyEx(Keys.R, False)

 

Or this:

Me.vwr_Main.SendCustomKeyEx(KeySym_Windows_L, True)

Me.vwr_Main.SendCustomKey(Keys.R)

Me.vwr_Main.SendCustomKeyEx(KeySym_Windows_L, False)

 

I've tried everything I can think of, either I am missing something or maybe we have a bug?

Thanks

M

By Yury Averkiev (s-code) - Thursday, April 30, 2009
Could you please send me which scan code do you use for the Windows key and where did you find one? I'll try to reproduce the problem locally. But with 100% certainty I can guaranty that this is not an issue with ViewerX, since it merely sends scan codes to a VNC server.
By mrowley - Thursday, April 30, 2009
If you google KeySym and "Windows Key" you will find dozens of descriptions of the Super L (65515) and Super R keys being the windows Key.

http://www.google.ca/search?hl=en&q=keysym+%22Windows+Key%22&meta=&aq=f&oq=

If you use a

Me.vwr_Main.SendCustomKeyEx(65515, True)

Me.vwr_Main.SendCustomKeyEx(65515, False)

you will get the windows start menu just like the windows key should do.  And we know the R works so its an issue with the combination of keys for sure.

Although ALT + F4 works:

Me.vwr_Main.SendCustomKeyEx(KeySym_Alt_L, True)

Me.vwr_Main.SendCustomKeyEx(KeySym_F4, True)

Me.vwr_Main.SendCustomKeyEx(KeySym_F4, False)

Me.vwr_Main.SendCustomKeyEx(KeySym_Alt_L, False)

 

Rather unfortunate that the windows key combinations dont work as that was the point to why I wanted to replace a precompiled VNC viewer with my own.

Please let me know what you find out.

Thanks

M

By Yury Averkiev (s-code) - Thursday, April 30, 2009
I'll give it a try in the morning (10.20PM in Singapore now) and post my test results. I'll run UltraVNC Server under a debuger and check if it processes the Windows key correctly.
By mrowley - Thursday, April 30, 2009
I have tested this viewer issue with RealVNC server and UltraVNC server, it displays the same problem on both. 

Hope this info helps.

M

By mrowley - Thursday, April 30, 2009
I also figured a work around to my problem, which was to create short cuts on the desktop and assign them Shortcut keys such as CTRL+ALT_Num2, if I press the keys on the keyboard it works perfectly, if I used SendCustomKeyEx as below, nothing happens.

Its definitely seems to be a problem with the function.

     Me.vwr_Main.SendCustomKeyEx(KeySym_Control_L, True)
     Me.vwr_Main.SendCustomKeyEx(KeySym_Alt_L, True)
     Me.vwr_Main.SendCustomKeyEx(Keys.NumPad2, True)
     Me.vwr_Main.SendCustomKeyEx(Keys.NumPad2, False)
     Me.vwr_Main.SendCustomKeyEx(KeySym_Alt_L, False)
     Me.vwr_Main.SendCustomKeyEx(KeySym_Control_L, False)

Thanks

M

By Yury Averkiev (s-code) - Friday, May 01, 2009
Bad news....it looks like a VNC server doesn't process Windows key events. Look at the file attached. If you familiar with C++ you will see that their key map processing class works only with scan codes defined in the static keymap_t keymap[] array plus ordinary Latin-1 characters. The Windows key is not defined in the array. 

Look at the method void keyEvent(CARD32 keysym, bool down, vncServer *server)  Line:254, the main processing logic is implemented by this method.

Probably if you add scan code for the Windows key to the keymap array and recompile  VNC server sources you will get it working.

Unfortunately there is noting can be done about the problem on the ViewerX side, since this is a missing VNC server feature we are dealing here.

By mrowley - Friday, May 01, 2009
My browser failed, so I am not sure if you got this post or not.

If the server doesnt process the windows key, why does the following code cause the windows start menu to open?

Me.vwr_Main.SendCustomKeyEx(KeySym_Windows_L, True)

Me.vwr_Main.SendCustomKeyEx(KeySym_Windows_L, false)

 

Also why doesnt CTRL+ALT+Key work?

Me.vwr_Main.SendCustomKeyEx(KeySym_Control_L, True)

Me.vwr_Main.SendCustomKeyEx(KeySym_Alt_L, True)

Me.vwr_Main.SendCustomKeyEx(Keys.NumPad3, True)

Me.vwr_Main.SendCustomKeyEx(Keys.NumPad3, False)

Me.vwr_Main.SendCustomKeyEx(KeySym_Alt_L, False)

Me.vwr_Main.SendCustomKeyEx(KeySym_Control_L, False)

 

This code doesnt launch the shortcut with this keyboard shortcut setup, but if I physically press the keys it does.

 

Thanks

M

By Yury Averkiev (s-code) - Friday, May 01, 2009
I got it working! Apparently TightVNC server (which I was using for testing) doesn't support Windows key, but UltraVNC server does.
The trick is order in which scan codes are sent. The following works for me and opens the Run window:

vx.SendCustomKeyEx(65515, true);
System.Threading.Thread.Sleep(100);
vx.SendCustomKeyEx(65515, false);
System.Threading.Thread.Sleep(100);
vx.SendCustomKeyEx(0x052, false);
System.Threading.Thread.Sleep(100);
vx.SendCustomKeyEx(0x052, true);

Now you might be wondering what those Sleep(100) are doing the code. At least in my case, without them I was getting some random results; in some case the start menu would open and in some cases the Run window. Adding the Sleep call seems to fix the issue.