Click to See Complete Forum and Search --> : keyboard input problems


adambennett
April 5th, 2009, 05:07 PM
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

dglienna
April 5th, 2009, 10:37 PM
Search for posts by TT(n). He has a few links in his signature that will help.

adambennett
April 7th, 2009, 11:42 AM
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

dglienna
April 7th, 2009, 04:21 PM
Try using a SLEEP command

adambennett
April 7th, 2009, 06:21 PM
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.

TT(n)
April 7th, 2009, 07:06 PM
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.
Windows.Forms.SendKeys.SendWait("%(1)")

What exactly are you waiting for, before moving onto what?

adambennett
April 7th, 2009, 09:01 PM
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.

dglienna
April 7th, 2009, 11:45 PM
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...

TT(n)
April 8th, 2009, 12:19 AM
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:

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.

adambennett
April 8th, 2009, 10:42 AM
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

TT(n)
April 8th, 2009, 12:45 PM
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

adambennett
April 8th, 2009, 01:45 PM
ok Thanks. I have sent you a PM.