Thread: Fake Key Press

  1. #1
    Registered User (TNT)'s Avatar
    Join Date
    Aug 2001
    Location
    UK
    Posts
    339

    Fake Key Press

    Hi,

    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
    TNT
    TNT
    You Can Stop Me, But You Cant Stop Us All

  2. #2
    Used Registerer jdinger's Avatar
    Join Date
    Feb 2002
    Posts
    1,065
    You could try this:

    Code:
    //In your Message Handling Function
    case WM_KEYDOWN:
    {
       int iKey=(int)wParam;
       char cKey[20];
       _itoa(iKey,cKey,10);
       MessageBox(NULL,cKey,"The keycode is:",NULL);
    }
    This will give you the keycode for the desired key to "press".

    Then in your app wherever you want to "press" the key:
    Code:
    SendMessage(hwnd,WM_KEYDOWN,iKey,0);
    Of course, you'd replace iKey in the SendMessage call with
    whatever keycode you need to simulate pressing.

  3. #3
    Registered User (TNT)'s Avatar
    Join Date
    Aug 2001
    Location
    UK
    Posts
    339
    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

    Cheers,
    TNT
    TNT
    You Can Stop Me, But You Cant Stop Us All

  4. #4
    Has a Masters in B.S.
    Join Date
    Aug 2001
    Posts
    2,263
    its probably a system key use the message WM_SYSKEYDOWN

    wParam = virtual-key code
    lParam = key data
    ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.

  5. #5
    Used Registerer jdinger's Avatar
    Join Date
    Feb 2002
    Posts
    1,065
    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.

  6. #6
    Registered User (TNT)'s Avatar
    Join Date
    Aug 2001
    Location
    UK
    Posts
    339
    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.

    Thanks
    TNT
    TNT
    You Can Stop Me, But You Cant Stop Us All

  7. #7
    Registered User
    Join Date
    Feb 2002
    Posts
    589
    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.

  8. #8
    Registered User (TNT)'s Avatar
    Join Date
    Aug 2001
    Location
    UK
    Posts
    339
    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.
    TNT

  9. #9
    Registered User Dual-Catfish's Avatar
    Join Date
    Sep 2001
    Posts
    802
    My bet is you'll need assembly to catch the key press, try asking on the flashdaddee.com Assembly forum about it.

  10. #10
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 11-23-2007, 01:48 PM
  2. Virtual keys
    By Arkanos in forum Windows Programming
    Replies: 4
    Last Post: 12-12-2005, 10:00 AM
  3. Directional Keys - Useing in Console
    By RoD in forum C++ Programming
    Replies: 38
    Last Post: 10-06-2002, 04:42 PM
  4. FAQ: Directional Keys - Useing in Console
    By RoD in forum FAQ Board
    Replies: 38
    Last Post: 10-06-2002, 04:42 PM