Jump to content


Photo

Trouble creating script to copy form text


  • Please log in to reply
6 replies to this topic

#1 OM2

OM2
  • Members
  • 54 posts

Posted 16 July 2012 - 01:36 PM

I have AutoHotkey_L version v1.1.04.01

I'm trying to use a script to record my keyboard actions to copy text

I've tried running a recorder script called Recorder.ahk, but this seems not to record by Ctrl A and CTRL C presses

The script it gives me seems to vary as well each time I run it!

This is what I want (only want keyboard actions recorded)

CTRL A
CTRL C
Shift Tab
CTRL A
CTRL C
Shift Tab
CTRL A
CTRL C
Shift Tab
CTRL A
CTRL C

I then also want to run a script where I do the following:

CTRL A
CTRL V
Tab
CTRL A
CTRL + Windows Key + Left Alt
Enter
Tab
CTRL A
CTRL + Windows Key + Left Alt
Down Arrow
Enter
Tab
CTRL A
CTRL + Windows Key + Left Alt
Down Arrow twice
Enter
Tab
CTRL A
CTRL + Windows Key + Left Alt
Down Arrow three times
Enter

Explanation: I use PhraseE*press
I have CTRL + Windows Key + Left Alt programmed so that it pulls up whatever I have copied in cache (for the last 10 entries)

The first set of actions copies fields from one form
The second set of actions copies those fields copied and pastes them into a second form

Can someone help me get started?

With the recorder I have this script:

Send, {LCtrl 21}{LCtrl}{LControl up}{LShift}{Tab}{	}{LShift up}{Tab up}{LCtrl}{LControl up}{LShift}{Tab}{	}{Tab up}{LShift up}{LCtrl}{LControl up}{LShift}{

I've tried something like this just to test:

RAlt & 0::
Send {CTRL a}
Return
So if the right hand side alt is pressed with 0 *zero) then it should CTRL A and select all
Nothing happens

So... I haven't even got round to trying to do CTRL C yet :(

Where am I going wrong?

Thanks


OM

#2 Guests

  • Guests

Posted 16 July 2012 - 01:51 PM

It is quite easy ^ = ctrl + = shift ! = alt # = winkey so
Send ^a ; this will work most of the time, if not you could try
Send {CTRL down}a{CTRL up}


#3 OM2

OM2
  • Members
  • 54 posts

Posted 16 July 2012 - 04:57 PM

ok... that works :)

so now i have:

RAlt & 0::  ;Right Alt + 0 (that's a zero)
Send ^a^c+{tab}^c+{tab}^c+{tab}^c+{tab}^c+{tab}^c
Return

problem: only the last field gets copied

i don't have to use phr*seexpress
it's ok for me to put a copy of the copied text into cache memory that autohotkey can access
i'm not sure how to do this - i definitely read up about
can u give pointers to this?

also, if i did want to use phr*seexpress how would i make it work?

thanks

#4 Leef_me

Leef_me
  • Moderators
  • 7704 posts

Posted 16 July 2012 - 05:22 PM

The following assumes you are not using phr*seexpress

This AHk command Send ^c copies the selected data to the clipboard.
The clipboard is the same windows clipboard that programs use.

If the data you copy to the clipboard can be represented as text,
then the command msgbox %clipboard% would show that text in a pop-up message.

:arrow: On this doc page is a link to the detailed docs of the clipboard <!-- m -->http://www.autohotke...ds/ClipWait.htm<!-- m -->
Please read both those pages.

If you need to retain text from multiple copying operations
you can copy the clipboard text to another variable using keep1 := clipboard
The name of the variable is up to you. I used keep1 to suggest using keep1, keep2 ... etc.

In case it isn't clear, this following will put the text data back on the clipboard for pasting with ^v clipboard := keep1

:arrow: Alternately you can use the send command with the stored variables <!-- m -->http://www.autohotke...mmands/Send.htm<!-- m -->

:arrow: Another alternative allows copying the text from the fields directly,
but requires that the target program have controls that AHk can "see" <!-- m -->http://www.autohotke... ... etText.htm<!-- m -->
This would not work on fields of a webpage, but might be good for other programs.

#5 OM2

OM2
  • Members
  • 54 posts

Posted 18 July 2012 - 12:36 AM

@leef_me, that is awesome :)
ok, i've made a lot of progress!

this is what i now have:

#IfWinActive ahk_class Chrome_WidgetWin_1
RAlt & 0::  ;Right Alt + 0 (that's a zero)
clipboard = ; Empty the clipboard
Send, ^a^c
ClipWait, 2
if ErrorLevel
{
    keep1 := "Empty"
}
keep1 := clipboard
clipboard = ; Empty the clipboard
Send, {tab}^c
ClipWait, 2
if ErrorLevel
{
    keep2 := "Empty 2"
}
keep2 := clipboard
clipboard = ; Empty the clipboard
Send, {tab}^c
ClipWait, 2
if ErrorLevel
{
    keep3 := "Empty 3"
}
keep3 := clipboard
clipboard = ; Empty the clipboard
Send, {tab}^c
ClipWait, 2
if ErrorLevel
{
    keep4 := "Empty 4"
}
keep4 := clipboard
clipboard = ; Empty the clipboard
Send, {tab}^c
ClipWait, 2
if ErrorLevel
{
    keep5 := "Empty 5"
}
keep5 := clipboard
clipboard = ; Empty the clipboard
Send, {tab}^c
ClipWait, 2
if ErrorLevel
{
    keep6 := "Empty 6"
}
keep6 := clipboard
MsgBox Control-C copied the following contents to the clipboard:`n`n keep1: %keep1% `n`n keep2: %keep2% `n`n keep3: %keep3% `n`n keep4: %keep4% `n`n keep5: %keep5% `n`n keep6: %keep6%
Return

a few questions:

1. Why doesn't it work without: #IfWinActive ahk_class Chrome_WidgetWin_1
If I leave this out, then it doesn't work
How do I make it so that it works ANYWHERE! (I need to use on different browsers)

ahk_class Chrome_WidgetWin_1 is a problem. I started Autolt Window Spy and got from the ahk_class Chrome_WidgetWin_0 as being the window. This worked for a while, but then stopped working, When I ran Window Spy again, this time I got ahk_class Chrome_WidgetWin_1
What am I missing?

2. How long should I clipwait?
I used 2 - the amount they used in the example code

3. When do I use comma? I tried googling but can't find an explanation

4. What does a newline mean? If I have this in my code, does it mean anything?
Is it ok to space my code out? What happens if I have empty lines - does this effect the code?

For example, what if I had:

MsgBox Control-C 
copied the following contents to
 the clipboard:

`n`n keep1: %keep1% `n`n 

keep2: %keep2% `n`n keep3: 
%keep3% `n`n keep4: %keep4% `n`n keep5: %keep5% `n`n keep6: 


%keep6%

5 .If i have an empty field, I get a 'PING' sound (loud annoying ping sound!)
Is there anyway round this?

i.e. I have this code:

clipboard = ; Empty the clipboard
Send, {tab}^c
ClipWait, 2
if ErrorLevel
{
    keep6 := "Empty 6"
}
If there is text to copy, then is OK
If not, I get the annoying PING sound!

6. I have keep6 := "Empty 6" - this doesn't work. Instead, I just get keep6 to be nothing when I send to the messagebox
What am I doing wrong?

7. Is there a different way to paste stored text?
Instead of:

clipboard := keep1
Send, ^v

Isn't there a paste command that pastes your variables?

8. I've now tried to do the other part of the code I need - pasting into another form in another browser

I have:


#IfWinActive ahk_class MozillaWindowClass
RAlt & 9::  ;Right Alt + 9
Send, ^a
clipboard := keep1
Send, ^v
Send, {tab}
clipboard := keep2
Send, ^v
Send, {tab}
clipboard := keep3
Send, ^v
Send, {tab}
clipboard := keep4
Send, ^v
Send, {tab}
clipboard := keep6
Send, ^v
Send, {tab}
Erm... this just doesn't work!
It manages to do a few Ctrl+Tab keys for some reason
Where am I going wrong?

Thanks!!


OM

#6 OM2

OM2
  • Members
  • 54 posts

Posted 18 July 2012 - 11:25 PM

anyone? have i been tooooo detailed in my reply?

#7 Leef_me

Leef_me
  • Moderators
  • 7704 posts

Posted 19 July 2012 - 07:10 AM

anyone? have i been tooooo detailed in my reply?

Read all of this post, especially the last sentence of step #3 <!-- l --><a class="postlink-local" href="http://www.autohotkey.com/community/viewtopic.php?f=1&t=4986">viewtopic.php?f=1&t=4986</a><!-- l -->


a few questions:

1. Why doesn't it work without: #IfWinActive ahk_class Chrome_WidgetWin_1
If I leave this out, then it doesn't work
How do I make it so that it works ANYWHERE! (I need to use on different browsers)

Your statement seems backwards, hotkeys are supposed to work >everywhere<
the "#ifwin..." statement is to make hotkeys context-sensitive <!-- m -->http://www.autohotke...eys.htm#Context<!-- m -->

got from the ahk_class Chrome_WidgetWin_0
got ahk_class Chrome_WidgetWin_1


You need a different "match" than just a fixed name, please read
<!-- m -->http://www.autohotke... ... chMode.htm<!-- m -->
<!-- m -->http://www.autohotke...Ex-QuickRef.htm<!-- m -->

settitlematchmode, regex ; <--- at top of script

#IfWinActiveahk_class Chrome_WidgetWin_[0-9]+ ; <--- I don't know regex, but this kinda seems right


2. How long should I clipwait?

It depends, copying "war and peace" from MSWord to the clipboard might take a while :wink:
Consider how long whatever copy might really take,

Or build yourself a little stopwatch using the variable A_TickCount, and instead of "sleep,1000" insert "send ^c" and "clipwait"
<!-- m -->http://www.autohotke...iables.htm#date<!-- m -->

3. When do I use comma? I tried googling but can't find an explanation

Commas are typically used to separate parameters. For some backwards compatibility with previous version,the first comma shown in the docs is typically optional. I >try< to put them in to build a habit but I forget sometimes.

4. What does a newline mean? If I have this in my code, does it mean anything?
Is it ok to space my code out? What happens if I have empty lines - does this effect the code?


<!-- m -->http://www.autohotke...ocs/Scripts.htm<!-- m -->
<!-- m -->http://www.autohotke...cs/Tutorial.htm<!-- m -->
<!-- l --><a class="postlink-local" href="http://www.autohotkey.com/community/viewtopic.php?f=16&t=47791">viewtopic.php?f=16&t=47791</a><!-- l -->

5 .If i have an empty field, I get a 'PING' sound (loud annoying ping sound!)
Is there anyway round this?

I turn systems sounds off. I hate clicks, dings, swish, pop, donk ....

6. I have keep6 := "Empty 6" - this doesn't work. Instead, I just get keep6 to be nothing when I send to the messagebox
What am I doing wrong?

I don't have a clue what you mean. In the script at the top of the post I'm responding to,
you have 5 other instances of almost the same exact line

7. Is there a different way to paste stored text?
Isn't there a paste command that pastes your variables?

See my previous post,


8. I've now tried to do the other part of the code I need - pasting into another form in another browser
Erm... this just doesn't work!
It manages to do a few Ctrl+Tab keys for some reason
Where am I going wrong?


AHk can send ^v and {tab} at blinding speed :shock:
I suggest adding Sleep, 1000 between every pair of "sends", to slow AHk down.