Jump to content

ControlSend and SHIFTDOWN/UP


Recommended Posts

When I use the ControlSend in the scipt below the SHIFTDOWN/UP don't work.

Does anyone know why?

$title = WinGetTitle("", "")
$Versie = "v.2.0"
AutoItSetOption ( "SendKeyDelay", 5 )
;
;Position cursor
;
Sleep (1000)
for $__n1_ = 1 to 9
ControlSend($title, "", "", "{LEFT}")
next
ControlSend($title, "", "", "{DOWN}{DOWN}")
;
;Copy the data
;
ControlSend($title, "", "", "{SHIFTDOWN}")
for $__n1_ = 1 to 7
ControlSend($title, "", "", "{RIGHT}")
next
for $__n1_ = 1 to 4
ControlSend($title, "", "", "{DOWN}")
next
ControlSend($title, "", "", "{SHIFTUP}")
Send ( '!ec' )
Link to comment
Share on other sites

ControlSend often has problems with the shift state (as well as the control and alt state sometimes.) A solution is to use the global shift state. I would also recomend that you look at my ControlSendPlus function, since it has all the handeling built in to use the global shift state, as well as options to use the global alt and/or control states when needed. You may download this from my Projects page from the link in my signature. Just check out the readme included and you'll be set.

[font="Optima"]"Standing in the rain, twisted and insane, we are holding onto nothing.Feeling every breath, holding no regrets, we're still looking out for something."[/font]Note: my projects are off-line until I can spend more time to make them compatable with syntax changes.

Link to comment
Share on other sites

Hi Pekster,

I downloaded youre code as well as the HELP-file, but I'm probably a bit retarded because I dont understand one bit.

I don't even know how to send a SHIFTDOWN with this.

What do I have to change / alter and what not.

Can you please help me !!! :iamstupid:

Link to comment
Share on other sites

I downloaded youre code as well as the HELP-file, but ... I dont understand one bit.

I don't even know how to send a SHIFTDOWN with this.

What do I have to change / alter and what not.

My ControlSendPlus function works very similar to ControlSend, so knowing how to use that is important. All the paramaters are technically the same, except the last one (the "flag" paramater.) I will explain the paramaters first, and then explain why my function is often a useful replacement for ControlSend.

Paramaters: ControlSendPlus("title", "text", "classnameNN", "string", flag)

  • "title": Title of the window
  • "text": The text of the window (can be "", see ControlSend for more info.)
  • "classnameNN": Control to send to. See ControlSend for more info.
  • "string": The string to send. They are sent using ControlSend, but with important differences listed below.
  • flag: This is a slightly different paramater from the default. First, it is a required paramater, so you must enter 0 for the "default" behavior. Please note that for all flag modes, the shift key is modified globally. Consult the information below for an explination of the various flags for my UDF:
  • 0 - "default" mode, where special keys such as {UP} and {ENTER} are sent as the special keys, and the +, !, and ^ modifiers all work as expected.
  • 1 - This is "raw" mode, where any text is sent excatally as it appears. If you entered "!{ENTER}" for the string, it would type "!{ENTER}" in a notepad window (and not alt plus the enter key.)
  • 2 - This mode is the same as mode 0, but the alt and control keys are sent globally. Sometimes controls have a problem with local control and/ or alt keys, so this flag will set the control and alt state using Send and not ControlSend.
  • 3 - Same as mode 2, but only the control key is sent globally. The alt key is still sent locally.
  • 4 - Same as mode 2, but only the alt key is sent globally. The control key is still sent locally.
Usefullness

My UDF aims to overcome the problem where keys sent with ControlSend are not always interperted correctally. This occurs when you open a command window, and try to control send something such as email@domain.com > out.txt . It will appear as email2domain.com . out.txt. You will notice that this is sent as if the shift key were not properly used. Furthermore, this problem can't be solved with the {SHIFTDOWN} and {SHIFTUP} keys if they are sent via ControlSend.

This is where my function is useful. If you were to put my ControlSendPlus.au3 file in your ~\AutoIt3\Include folder, you could do an #include <ControlSendPlus.au3> at the top of your script, and then use the ControlSendPlus call to send. If you sent that same line as I used above to demonstrate the problem that ControlSend has with my function, it will properly set the shift state before each key.

I accomplish this by changing the global shift state with a standard Send over a ControlSend. However, this does have 2 limitations. First, if you press the shift key if will mess up the ControlSend, but this is no different than the ControlSend function (as pressing the shift key will screw it up too.) Second, if you are typing in another window while my UDF is changing the shift (and alt/ control too depending on your flag) it will apply to what you are typing.

For the last 3 flag modes listed above, you can use the same logic for alt and control characters. Using that command prompt window, you can't properly send any control keystrokes. To illustrate this, type a control-C in a normal command prompt and see what it does (it will cancel the current command and give you a fresh prompt.) However, if you try to send the "^c" key with ControlSendPlus, it will just send c. This is identical to the shift state problem, so you need to send it globally.

This is where some experimenting is required. You might say "well, since it needed to send the control keystroke globally, we should use flag 2 to send the alt globally as well." This is not always correct. Back to the command prompt, if you try to use flag 2, it will fail to use the alt keystroke correctally. So, when dealing with the command prompt, flag 3 is a good choice to properly send all keys properly.

Coded examples

Here are some exmples, using a command prompt window, that explain what I have talked about above. For these to work, you must put my ControlSendPlus function in your AutoIt Include folder. If you don't want to do that, just place the au3 in the same directory, and change the include to quotes instead of < > symbols.

example 1: failure of ControlSend to work

Run(@ComSpec)
WinWaitActive(@ComSpec)
ControlSend(@ComSpec, "", "", "user@domain.com > out.txt")

example 2: ControlSendPlus using the same code

#include <ControlSendPlus.au3>

Run(@ComSpec)
WinWaitActive(@ComSpec)
ControlSendPlus(@ComSpec, "", "", "user@domain.com > out.txt", 0)

example 3: ControlSendPlus failing to handle the control-c combination

#include <ControlSendPlus.au3>

Run(@ComSpec)
WinWaitActive(@ComSpec)
ControlSendPlus(@ComSpec, "", "", "let's cancel this command^c", 0)

example 4: ControlSendPlus properly using a global state for control-c, but failing to use alt-enter because it too is being sent globally

#include <ControlSendPlus.au3>

Run(@ComSpec)
WinWaitActive(@ComSpec)
ControlSendPlus(@ComSpec, "", "", "let's cancel this command^c!{ENTER}", 2)

example 5: Proper flag to use with ControlSendPlus and the command prompt

#include <ControlSendPlus.au3>

Run(@ComSpec)
WinWaitActive(@ComSpec)
ControlSendPlus(@ComSpec, "", "", "let's cancel this command^c!{ENTER}", 3)

LONG STORY SHORT

Don't use {SHIFTDOWN} with my UDF since it will be useless. Instead, just send the keys you want to be used with shift like you normally would. To do a capital s, use "S", and to do a shift-down, use "+{DOWN}". Play with the flag modes to see the proper combination of alt and control keystrokes to be sent globally, if that is required for your application. Each program responds to my different methods a little bit differently.

Had to change a "local" to "global"... whopsie :D

2 typos corrected so far

Edited by pekster

[font="Optima"]"Standing in the rain, twisted and insane, we are holding onto nothing.Feeling every breath, holding no regrets, we're still looking out for something."[/font]Note: my projects are off-line until I can spend more time to make them compatable with syntax changes.

Link to comment
Share on other sites

Oh sure, take the fun out of my function :D (although it does do control/ alt too :huh2: )

You'll just have to write 12 lines of code for my command prompt example compared to the 1 required for my function. I guess it depends on how often you'll be using this in your code. Use it 2 or 3 times, and my UDF has just saved you valuable space.

Typo edit

Edited by pekster

[font="Optima"]"Standing in the rain, twisted and insane, we are holding onto nothing.Feeling every breath, holding no regrets, we're still looking out for something."[/font]Note: my projects are off-line until I can spend more time to make them compatable with syntax changes.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...