Results 1 to 8 of 8
  1. #1
    Join Date
    Nov 2005
    Posts
    2,036

    Using SendKeys in a Console App

    Hey all!

    I'm writing a simple little app write now using a console, but for some reason Sendkeys doesn't want to work with it.

    SendKeys cannot run inside this application because the application is not handling Windows messages. Either change the application to handle messages, or use the SendKeys.SendWait method.
    Does anyone know how i can fix this?

    thx ahead of time,
    -Chris

  2. #2
    Join Date
    Dec 2004
    Location
    Norway
    Posts
    129
    I believe that SendKeys only work with windows applications. You can read about it in the MSDN Library

    What do you need the app to do with the input? Have you tried with Console.ReadKey() or Console.ReadLine()?

  3. #3
    Join Date
    May 2007
    Location
    Upstate, NY
    Posts
    505
    Probably a gamepad key mapper. I was looking into that a few weeks back for my 360 controller. I had been using a trial of Pinnacle, but it ran out. So I decided to see about just writing my own small, simple hardcoded one. Ran into trouble trying to do it through XNA, heheh. Then I found JoyToKey and Xpadder. Xpadder is really nice, but doesn't work with particular anti-cheat software. So I was forced to use the somewhat less polished JoyToKey. Meh, it works just as well though.
    The spice must flow.

  4. #4
    Join Date
    Nov 2005
    Posts
    2,036
    Hey thanks for the replies.

    @CurlyB: ok, thanks. SendKeys(from my understanding) is different from the console commands because it actually simulates the user pressing the button without them actually doing it.

    @Wren Akula: not exactly, thanks for the info though. I am actually making an app that will start itunes and make it play depending on some input, I just don't want to have to go through all the itunes sdk stuff.

  5. #5
    Join Date
    May 2007
    Location
    Upstate, NY
    Posts
    505
    Ah, cool. have you looked at PostMessage?
    http://msdn.microsoft.com/en-us/libr...44(VS.85).aspx

    Not sure if that will do you any good since "the application is not handling Windows messages", but it's worth checking out.

    Also, have you tried SendWait as suggested by the error message? I think the only difference is that it waits for the message to be processed.
    The spice must flow.

  6. #6
    Join Date
    Nov 2006
    Location
    UK
    Posts
    3,774
    Out of interest whats receiving send keys are you sending messages to yourself? or to another app..

    For me the SendWait worked to itself, or seemed to! If its another app, it could be you arent getting the window returned correctly
    Delphi !ROCKS!
    Got a question? Read this first!!!
    "You gotta help us, Doc. We've tried nothin' and we're all out of ideas"

  7. #7
    Join Date
    Nov 2005
    Posts
    2,036
    Wren Akula: Looks like this might be worth taking a look at, I'll see if I can use it! Thanks!

    LizRiley: I'm not entirely sure what you are asking, from my understanding the sendKey function just simulated someone pressing a key on the keyboard, I wasn't aware it took the window into account.

    I don't know, maybe this is down the wrong path for this situation, I just kinda threw it out there as a quick fix.

  8. #8
    Join Date
    Nov 2006
    Location
    UK
    Posts
    3,774
    Quote Originally Posted by gu1tarfreak View Post
    LizRiley: I'm not entirely sure what you are asking, from my understanding the sendKey function just simulated someone pressing a key on the keyboard, I wasn't aware it took the window into account.
    Sure it does. It sends to whatever it believes is the current window - if thats the console app it will whine, if the apps busy, it whines, because send expects a "I got it", where as the old win32 had a post which didnt care. If your app is pointing at the wrong window its sending random crap to the wrong app
    Delphi !ROCKS!
    Got a question? Read this first!!!
    "You gotta help us, Doc. We've tried nothin' and we're all out of ideas"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •