Fake Key Press
Im trying to make a program that turn off my laptop screen when windows has started, becasue the screen is going to an external moniter instead. There is a special Function key on my laptop (Fn) and the key press Fn + F4 turns off the screen.
Is this possible? is there a key code for an Fn key because it isnt standard on all keyboards. And if it is possible how can i imitate this key press from my program.
Thanks for any pointers
You could try this:
This will give you the keycode for the desired key to "press".
//In your Message Handling Function
MessageBox(NULL,cKey,"The keycode is:",NULL);
Then in your app wherever you want to "press" the key:
Of course, you'd replace iKey in the SendMessage call with
whatever keycode you need to simulate pressing.
Hey thanks alot i hadnt thought of doing it that way, but for some odd reason my program dosnt recieve a msg from the Fn key. I am guessing that the fn key is only sending a message to windows or somthing?? and maybe i would need to set up some sort of hook to catch it? Im not sure if this is the right path can someone enlighten me please
its probably a system key use the message WM_SYSKEYDOWN
wParam = virtual-key code
lParam = key data
I wasn't sure about the FN key returning a keycode. That was just a thought. I'll look into a couple of other methods.
Hey thanks alot but the WM_SYSKEYDOWN msg didnt catch it either :( i have tested all my code on the other keys and that works fine... Any other ideas? Is there a function around to turn off the screen.
Does this key do anything else? It could just be an old boring hardwired on off key that doesn't care about any key codes.
Hmm, all the function keys along the top do different things when pressed in conjunction with the fn key like turn off the screen, turn sound on off, volume up and down just general short keys.
My bet is you'll need assembly to catch the key press, try asking on the flashdaddee.com Assembly forum about it.
Although it would be a bit of work, you could write a program to hook the messages sent on the system..this would then save the info to a readable place (send accross network, save to file...)..then run the prog and shut down.......I guess this might work....but it would be a pile of work