Shoutbox

Virtual Key Code - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Skype & Technology (/forumdisplay.php?fid=9)
+---- Forum: Tech Talk (/forumdisplay.php?fid=17)
+----- Thread: Virtual Key Code (/showthread.php?tid=66592)

Virtual Key Code by Dan0208 on 09-24-2006 at 08:01 AM

I am trying to write a simple script for salling clicker.
what I am trying to do is send a virtual keystroke of "fn + f4" which is a shortcut set by my laptop to change primary monitors.

I need to work out what the virtual key stroke codes for fn and f4 are.
this microsoft site is very helpful http://msdn.microsoft.com/library/default.asp?url...irtualKeyCodes.asp

as far as a know this 'fn' is not very common on keyboards and as such is a special key which is not documented on that site. so my question is does anyone know of what the keystroke resembling fn is or how I could go about finding it?

I have been googling and came up with FF but i have tried this line and its not working so maybe that key code was specific to the persons keyboard that posted it. by the way, as far as i can tell f4 is 73??

code:
SendVirtualKeystroke( 0xFF|0x73, true, false, false, false );


RE: Virtual Key Code by Mike on 09-24-2006 at 08:30 AM

quote:
Originally posted by http://en.wikipedia.org/wiki/Fn_key
Unlike other modifier keys such as Shift or AltGr, the control processor inside the keyboard typically sends out a different keycode depending on whether the Fn key is depressed. This allows the keyboard to emulate a full sized keyboard and means that specialised keymaps do not need to be created; the operating system can use standard keymaps designed for a full sized keyboard.
That means that you will actually have to find which keystroke is sent when the Fn key is pushed... ;)
I have a laptop, so I might be able to help you...
I will research for it some more there, but right now I can't since the laptop is not here... :(

Also, check this for more information regarding the Fn key :)
RE: Virtual Key Code by Dan0208 on 09-24-2006 at 08:52 AM

Thanks for the reply,

yep I need to work out which keystroke is sent when its pushed but how do i do that? Is there an application that can do so?

haha funnily enough thats the site i have been reading and where i got the information about FF being the keystroke (though i cant seem to get it to work)

can anyone that knows Jscript actually confirm its the right code. i assume it is though cos it was taken from documentation from the salling clicker developer. im just not sure what all the true, falses are for...


RE: Virtual Key Code by CookieRevised on 09-24-2006 at 10:26 AM

For extra background info, read this::
CookieRevised's reply to # key and = key

And:
http://msdn.microsoft.com/library/default.asp?url=/library/.../VirtualKeyCodes.asp
http://msdn.microsoft.com/library/default.asp?url=/library/.../wm_appcommand.asp
http://www.microsoft.com/mspress/books/sampchap/6232.asp#120
http://www.microsoft.com/whdc/device/input/w2kbd.mspx#EATAE


Finally, what you need depends on what your programming language returns or can detect, or what your destination app may detect. You have ascii codes, scan codes, key codes and virtual key codes.

This said, when you need to send something like that you do not send a keystroke (eg: <CTRL> <K>; thus 2 codes) but you send the code which makes up that keystroke (eg: <CTRL+K>; thus 1 code). The same goes for that Fn Key. You don't send the code for that, but you send the code of the F4 when Fn is pressed.

So sending 0xFF|0x73 doesn't make much sense (also '255 OR 115' will be 255 anyways). You need to send the keycode of the key F4 when the Fn key is on.

I attached a very crude virtual keycode scanner which I just slammed together. Launch it, toggle your Fn and press F4 and see what the keycode is (requires VB6 runtimes).

---------------

quote:
Originally posted by Dan0208
code:
SendVirtualKeystroke( 0xFF|0x73, true, false, false, false );
can anyone that knows Jscript actually confirm its the right code.
No, as that code is not part of JScript, but it is part of the scripting engine of salling clicker (just as the Interop stuff is part of Plus!'s addition to the JScript engine in Plus!Live).

quote:
Originally posted by Dan0208
....im just not sure what all the true, falses are for.
Isn't that also in the documentation?

Either way, there is the forum for that, search and you'll find (in fact their forum is full of threads with questions like yours) ;)

eg:
http://www.salling.com/forums/viewtopic.php?t=404...ndvirtualkeystroke
http://www.salling.com/forums/viewtopic.php?t=304...ndvirtualkeystroke

quote:
SendVirtualKeystroke(
        virtual keycode value,
        shiftState,
        ctrlState,
        altState,
        winState
);


PS: in the SVKS app the 'shift state' indicates the state of the shift keys. these are Shift, Ctrl and ALT. So don't confuse 'shift state' with the 'shiftState' of the SendVirtualKeystroke function where they actually mean the SHIFT button itself.
RE: Virtual Key Code by Dan0208 on 09-24-2006 at 11:44 AM

Thanks cookie for your very detailed reply. I understand much more now.
I only have very basic knowledge of this but I thought i could at least try and modify another persons function for doing the alt+esc command to make mine do fn+f4.
how would i check the value of the virtual key code when those buttons are pressed at the same time? is it the information you provided in link 2? the appcommand?
if so how would i implement it? I only need to know once off what the code value is, its only a 5 line program lol.
Thanks


RE: Virtual Key Code by CookieRevised on 09-24-2006 at 11:45 AM

reread my post, it's edited while you were posting ;)

And to add to it: Fn is not a shift state key like CTRL, ALT or SHIFT. Fn is a toggle key which maps other keycodes to the keys.

You first press Fn to toggle some keys on your keyboard (just like CAPS LOCK, or NUM LOCK does on a normal keyboard). In other words Fn is not part of the final keycode.


RE: Virtual Key Code by Dan0208 on 09-24-2006 at 01:17 PM

that keycode scanner you provided works great. but one problem. It gives me info on every key i press on the keyboard EXCEPT when using the fn key in conjunction with its functions of f1 to delete key across the top.

i can get f4, or any letters etc but if i press fn by itself nothing happens. I know this is not what im meant to be getting but if i also press both at the same time to see what keycode is generated from this choice it changes my monitor to my tv like its sposed to but does not record anything on your keycode scanner :(
the same thing happens if i press fn + f7 (screen brightness down).

hmm when i first decided to do this i never though it would be such a hassle.
any other ideas?
thanks so much for all your help so far by the way

EDIT: added some more to my post to make it a bit more informative.
EDIT 2: we seem to have a habit of posting at the same time...


RE: Virtual Key Code by CookieRevised on 09-24-2006 at 02:00 PM

If you don't get any virtual keycodes then there are no virtual keycodes and the chances are high the key combination is probably hard coded in the laptops hardware (and thus never send to the operating system at all).

You could try keyboard scan codes in that case, but it is not only hard to catch them, I highly doubt that scripting engine of that program can even simulate scan codes.


RE: Virtual Key Code by Dan0208 on 09-24-2006 at 02:19 PM

hmm ok, i think I just read that somewhere but wasnt sure what it meant or if it applied to my situation.

I think it has now gone beyond my ability. I thought it would be easier to mimmick the shortcut key to change my monitor to my tv then it seems to be. so I think I will have to leave it at that. unless there is any other methods? could I assign another shortcut that does the same thing yet doesnt use fn?

either way thanks cookie for all your help I really appreciate it.


RE: Virtual Key Code by CookieRevised on 09-24-2006 at 09:40 PM

quote:
Originally posted by Dan0208
. unless there is any other methods? could I assign another shortcut that does the same thing yet doesnt use fn?
dunno. If it truely is a hardware combination (it's still not sure; it isn't because VB doesn't detect the virtual key, that you couldn't grab it somehow (eg: scan codes)), you have little chance in assigning another shortcut.

Unless, it can be set in the BIOS or something...
RE: Virtual Key Code by rav0 on 09-25-2006 at 02:42 AM

My (non-laptop) keyboard has a full-hardware self-contained F Lock button. No program can know when I press it or what the F Lock state is. When t's on, the function keys work like normal. When it's off, it just sends a different scancode for the function keys (they do things like Undo, Redo, Save, Print etc).

You mentioned that the keycode scanner won't detect what keycode is recieved when you use the graphics hotkeys. Try disabling the hotkeys (or changing them) temporarily, and the to find the keycode. I don't think that thge problem is that the shortcut includes FN, it's that it's being used by the graphics driver right now. If you decided to change the shortcut to something that doesn't use Fn, you would have to find out the keycode(s) for the new shortcut before you actually change the shortcut to that.


RE: Virtual Key Code by Adeptus on 09-25-2006 at 04:32 AM

Fn key is a pain in the posterior.  There is no standard and different vendors implement it differently.

In some cases, Fn key itself will have a keycode and when pressed in combination with certain other keys, cause them to produce different keycodes.  In other cases, it may not have a keycode of its own, but the combinations still do.  In yet other implementations, Fn key combinations trigger ACPI events and thus have no keycodes at all. 

It sounds like that may be the case with yours.  It is possible to programmatically hook (or trigger) ACPI events, but keyboard mapping software wouldn't be of much help there.

Although you are using Windows, this is a hardware question and you should be a able to Google up a lot of discussion of this (possibly including information specific to your laptop brand and model) in the context of running Linux on laptops.  Linux laptop user community has invested a lot of time trying to make use of the the Fn key combinations and discovering how different vendor implementations work.