CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 12 of 12
  1. #1
    Join Date
    Apr 2009
    Posts
    6

    keyboard input problems

    I amtrying to send ALT + 1 Key to the active application but the problem i am having is when i use SendKeys.SendWait("%1") the program ignores the alt key and jsut enters the 1. is there a way i can get this done?

    Thanks

  2. #2
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: keyboard input problems

    Search for posts by TT(n). He has a few links in his signature that will help.
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Apr 2009
    Posts
    6

    Re: keyboard input problems

    I have tried his Send Keys method and it does not work either. I am using VB 2008 and the problem is with it's SendKeys.SendWait("%1") it sends the keys too fast and unfortunately the program ignores the alt key

  4. #4
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: keyboard input problems

    Try using a SLEEP command
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  5. #5
    Join Date
    Apr 2009
    Posts
    6

    Re: keyboard input problems

    yea that doesnt work all that will do is slow down the time in between each keypress. which works fine for sending sentences and stuff but for this particular key combination that does not work.

  6. #6
    Join Date
    Jun 2004
    Location
    NH
    Posts
    678

    Re: keyboard input problems

    The SendWait method doesn't always wait as long as you might want it to.
    It only waits for the key messages to be processed, not the processes that might be initialized by the key combo.
    That's why my module also includes a function called WaitForWindow,
    which will wait for any new window that may be initialized by a keyboard stroke.
    There may be other reasons to wait, but this is probably the most common.
    Automation usually continues, with keyboard focus on the new window.

    I think you should be able to use the module for what you need, but if not then try MS Sendkeys inside parenthesis.
    Code:
    Windows.Forms.SendKeys.SendWait("%(1)")
    What exactly are you waiting for, before moving onto what?

  7. #7
    Join Date
    Apr 2009
    Posts
    6

    Re: keyboard input problems

    it doesnt need to wait on anything SendKeys is just simply sending the keystrokes too fast so the program does not recognize them all. I have gotten around this issue for everything else i need to send by doing as below:

    SendKeys.SendWait("H")
    Sleep(1)
    SendKeys.SendWait("e")
    Sleep(1)
    SendKeys.SendWait("l")
    Sleep(1)
    SendKeys.SendWait("l")
    Sleep(1)
    SendKeys.SendWait("o")


    But for the ALT, CTRL, and Another Key Combo that method does not work since it has to be in the form

    SendKeys.SendWait("%1")

    So when it does that it ignores the alt and just inputs a one into the program. so this method

    SendKeys.SendWait("%")
    Sleep(1)
    SendKeys.SendWait("1")

    does not work because it needs to Hold the ALT Key While Pressing the 1 Key

    I am stumped at this point.

  8. #8
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: keyboard input problems

    One site didn't let you use send keys at all, nor would it let you paste in words.

    It did let us send keystrokes 15ms apart, though. There should be some validation keys that are valid that you are using...
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  9. #9
    Join Date
    Jun 2004
    Location
    NH
    Posts
    678

    Re: keyboard input problems

    Is it a common program?

    EDIT: What does the key combo(Alt + 1) do?

    If you use my module, you can open it up, and change the KeyEvent function from Private to Public,
    so that you can press the menu key down separately, then lift it.
    Here is your key combo:
    Code:
            SendKeys.KeyEvent(Keys.Menu, True, False)
            SendKeys.KeyEvent(Keys.D1)
            SendKeys.KeyEvent(Keys.Menu, False, True)
    I don't think you'll need any Sleeps, in here but you could try SendKeys.Sleep(), if that doesn't work.
    Last edited by TT(n); April 8th, 2009 at 12:29 AM.

  10. #10
    Join Date
    Apr 2009
    Posts
    6

    Re: keyboard input problems

    Thanks so much that worked perfectly.

    I had to do it as so

    SendKeys.KeyEvent(Keys.Menu, True, False)
    SendKeys.Sleep(50)
    SendKeys.KeyEvent(Keys.D1)
    SendKeys.Sleep(50)
    SendKeys.KeyEvent(Keys.Menu, False, True)


    Except there are a couple keys i noticed are not working for example. Subtract I assumed would do the - key but it did not and i cant find a key for =

    Thanks

  11. #11
    Join Date
    Jun 2004
    Location
    NH
    Posts
    678

    Re: keyboard input problems

    Thanks so much that worked perfectly.
    Except there are a couple keys i noticed are not working for example.
    Subtract I assumed would do the - key but it did not and i cant find a key for =
    The keys that don't work, are the ones that do not have a value 0-255.
    For example Keys.Alt = 262144, and so the keyboard API will not recognize it.
    However, just about all keys are represented by some value 0-255.
    Use the function called Sendkeys.GetCommands, for all values.

    Keys.OemMinus is the subtract key next to zero.
    Keys.Oemplus is the add key next to zero, and OemMinus.
    You have to press/hold shift down, while the OemPlus key is pressed, just like normal.

    EDIT:
    To get the = key, just press Keys.Oemplus
    Last edited by TT(n); April 8th, 2009 at 12:50 PM.

  12. #12
    Join Date
    Apr 2009
    Posts
    6

    Re: keyboard input problems

    ok Thanks. I have sent you a PM.

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured