Jump to content
Sign in to follow this  
Meerecat

_IsPressed and Send problem

Recommended Posts

Meerecat

Hello

I am trying to write a script where certain text is entered into a document using a hotkey. It works, ie the text is entered when the hotkey is pressed. But it seems to continue to hold down the SHIFT + CTRL keys until I toggle sticky keys on and off, even if I quit the script.

Here is my example:

#Include <Misc.au3>

$dll = DllOpen("user32.dll")

While Sleep(100) ;Loop the program
    If  _IsPressed("11", $dll) AND _IsPressed("31", $dll) AND _IsPressed("10", $dll) Then _Send()
    If _IsPressed("7B", $dll) Then
        DllClose($dll)
        Exit
    EndIf

WEnd


Func _Send()
    Send ('Please find attached pro forma for your order as requested.  Also attached are our bank details should you wish to make payment directly into our account.  On receipt of cleared funds we will despatch your order.  Please note, this could take up to 4 working days.'& @LF & @LF & 'If you have any queries or need further information, please do not hesitate to contact me.')
    ;Send('test')
EndFunc

It only occurs when sending long strings of text. If I

Send('test')
the problem doesn't occur.

Incidentally is the a better way of doing this, ie rather than 'Sending' the text, perhaps copy the text straight from a separate text file? I guess I would start with FileOpen but am lost after that.

Any advice greatfully received.

Kind Regards

Lee

Edited by Meerecat

Lack of planning on your part does not constitute an emergency on my part.-The biggest idiot can ask questions the smartest man cannot answer.

Share this post


Link to post
Share on other sites
Tvern

If you can get a handle to the control you're using, try using ControlSetText. If you can't get the handle, or the control does not respond to ControlSetText, then you could try the following:

Not sure this will solve the problem completely, but at least it'll be faster

Func _Send()
    ;store old clupboard contents. (I think this only works for strings)
    $sClip = ClipGet()
    ;put the string in the clipboard.
    ClipPut('Please find attached pro forma for your order as requested.  Also attached are our bank details should you wish to make payment directly into our account.  On receipt of cleared funds we will despatch your order.  Please note, this could take up to 4 working days.'& @LF & @LF & 'If you have any queries or need further information, please do not hesitate to contact me.')
    ;paste string
    Send('^v')
    ;restore old clipboard
    ClipPut($sClip)
EndFunc

If you still have the problem with this, try adding

Send("{SHIFTUP}")
Send("{CTRLUP}")
before the function returns.

Share this post


Link to post
Share on other sites
Meerecat

If you can get a handle to the control you're using, try using ControlSetText. If you can't get the handle, or the control does not respond to ControlSetText, then you could try the following:

Not sure this will solve the problem completely, but at least it'll be faster

Func _Send()
    ;store old clupboard contents. (I think this only works for strings)
    $sClip = ClipGet()
    ;put the string in the clipboard.
    ClipPut('Please find attached pro forma for your order as requested.  Also attached are our bank details should you wish to make payment directly into our account.  On receipt of cleared funds we will despatch your order.  Please note, this could take up to 4 working days.'& @LF & @LF & 'If you have any queries or need further information, please do not hesitate to contact me.')
    ;paste string
    Send('^v')
    ;restore old clipboard
    ClipPut($sClip)
EndFunc

If you still have the problem with this, try adding

Send("{SHIFTUP}")
Send("{CTRLUP}")
before the function returns.

Works like a charm, thank you.

Rather than inserting the text into the script directly, could I store it in a separate text or ini file and read it from that, without actually opening the file? I guess I would use FileOpen, but can I put the contents of a file into the clipboard, given I'm not really opening the file?

Many Thanks

Lee


Lack of planning on your part does not constitute an emergency on my part.-The biggest idiot can ask questions the smartest man cannot answer.

Share this post


Link to post
Share on other sites
Meerecat

Func _Send($s_msg)
    $a_msg = StringSplit($s_msg," ")
    For $i = 1 To $a_msg[0]
        Send($a_msg[$i])
    Next
EndFunc

:)

I'm obviously being thick, so please feel free to tell me so. But do I somehow use that with FileOpen? I have looked at the help file, just don't get it.

Thanks, and feel free to tell me to go away if this is so simple I should just get it ;)


Lack of planning on your part does not constitute an emergency on my part.-The biggest idiot can ask questions the smartest man cannot answer.

Share this post


Link to post
Share on other sites
JohnOne

But do I somehow use that with FileOpen?

No. You'd want to use FileOpen("file.ext",$iFlag) for that.

Or Just $sFileRead = FileRead("File.ext")

$sFileRead will hold the contents of whatever is in the file, and you can Send that if you wish.

Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites
Meerecat

No. You'd want to use FileOpen("file.ext",$iFlag) for that.

Or Just $sFileRead = FileRead("File.ext")

$sFileRead will hold the contents of whatever is in the file, and you can Send that if you wish.

Thank you both very much, that's perfect. Now to have a play around with this :)

Lack of planning on your part does not constitute an emergency on my part.-The biggest idiot can ask questions the smartest man cannot answer.

Share this post


Link to post
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
Sign in to follow this  

×