AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Copy command not working in web form

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
ryanbarrier
Guest





PostPosted: Thu Jun 12, 2008 3:10 pm    Post subject: Copy command not working in web form Reply with quote

I use a web form at work that has full name, first name, and last name fields (among others). I have to copy/paste the name from a mainframe window, usually copying the full name and pasting it to the full name field and the first name field, then cutting the last name out of the first name field and pasting it to the last name field.

Obviously this is very tedious, and I have to do it dozens of times throughout the day. So I created a macro to do the cut/copy/paste for me. I have several other macros that cut/copy/paste between windows and they work just fine, but with this one the cut/copy commands are not updating the information on the clipboard. I can't figure out why... If I send a cut command the text will be removed, but the clipboard is not storing the cut text. So when I go to paste, it pastes whatever was already on the clipboard.

Here's what I'm working with (note that this assumes I've already copied the full name manually, and that information is already stored in the clipboard):

Code:
;-------------------------------------------------
#a::  ; For some reason "cut" is not working in this macro.
      ; It cuts the text away, but does not save it
      ; to the clipboard properly. 

  Send {Ctrl Down}      ;
  Click 450,355         ; Highlight "Full Name" Name box
  Send v                ; Paste Name
  Send {Ctrl up}        ;

  Send {Ctrl Down}      ;
  Click 160,175         ; Highlight "First Name" box
  Send v                ; Paste Name
  Send {Ctrl up}        ;

  Send {Shift Down}             ;
  Send {Left}{Left}{Left}       ; Highlight suffix (jr, sr, iii, etc)
  Send {Ctrl Down}              ;
  Send {Left}                   ; Highlight Last Name
  Send x                        ; Cut last name + suffix
  Send {Ctrl up} {Shift up}     ;

  Send {Ctrl Down}      ;
  Click 420,175         ; Highlight Last Name box
  Send v                ; Paste
  Send {Ctrl up}        ;

  ; Here is where I have to manually delete the first/middle names
  ; since the macro has pasted the full name instead of just the last
  ; name + suffix
  Send {Left}{Left}{Left}        ; Jump past suffix (jr, sr, etc)
  Send {Ctrl Down}      ;
  Send {Left}           ; Jump left past Last Name
  Send {Ctrl Up}        ;
  Send {Shift Down}     ;
  Send {Home}           ; Highlight everything else (first/middle names)
  Send {Delete}         ; Delete it
  Send {Shift Up}       ;

  Send {tab}    ;
  Send {tab}    ; Tab to "ID Type"

return
;-------------------------------------------------


Am I going crazy, or is there some strange behavior when you type text into a form field and cut/copy before leaving that field? Might it be some strange coding on the form itself? I other macros that copy information from the form and send it to other windows and vice versa, but this one doesn't work at all.

I have tried using the "send {ctrl}c" method as well as "send !c", and they both seem to work the same (neither works).

Thanks for the help.
Back to top
TheIrishThug



Joined: 19 Mar 2006
Posts: 379

PostPosted: Thu Jun 12, 2008 3:20 pm    Post subject: Reply with quote

If you have already have the full name on the clipboard before this starts, why not do all the string manipulation within ahk and then just send two variables. The less work done by sending key strokes the better.
Back to top
View user's profile Send private message Visit poster's website AIM Address
tank



Joined: 21 Dec 2007
Posts: 807

PostPosted: Thu Jun 12, 2008 3:26 pm    Post subject: Reply with quote

see the IE7_Get_Dom function in the link in my sig
_________________
Read this
Com
Automate IE7 with Tabs
Back to top
View user's profile Send private message
ryanbarrier



Joined: 12 Jun 2008
Posts: 9

PostPosted: Thu Jun 12, 2008 4:50 pm    Post subject: Reply with quote

TheIrishThug you're a genious. I'm not sure why I didn't think of that. I'm new to AHK, but not coding. I guess I still think of this thing as a macro tool more than a general coding kit.

I'd still like to know why the cut/copy/paste is not behaving, but string manipulation in AHK should work.

tank, I reviewed your IE7_Get_Dom function and I'm very impressed. Now... what does it do and why am I looking at it? I think it gets all Dom accessible objects from the current window and shows them in a GUI. I have to admit though, I don't know what any of that means or what is a Dom and I'm not sure how it will help me.
Back to top
View user's profile Send private message
tank



Joined: 21 Dec 2007
Posts: 807

PostPosted: Thu Jun 12, 2008 5:52 pm    Post subject: Reply with quote

its more for those of us who automate thigns with IE
if you grab a value from a form it can be loaded into the clipboard
you can automate sometimes complex tasks in an explorer window in seconds
Im glad you got your issue answered even if i didnt do it
probably should start with w3schools.com before messing to much with DOM whcih is document object model
_________________
Read this
Com
Automate IE7 with Tabs
Back to top
View user's profile Send private message
ryanbarrier



Joined: 12 Jun 2008
Posts: 9

PostPosted: Thu Jun 12, 2008 7:08 pm    Post subject: Reply with quote

Ok now I'm confused about how to manipulate the string in the clipboard. I've copied a name and I need to paste the full name to the full name field, the last name and suffix (if any) to the last name field, and everything else (first name and any middle names) to the first name field.

If I split the string, I don't know how many elements I have and which ones correspond to which field.

If all the names were just 2 elements it would be easy. But I have some names with first, middle, last... some with first, last, suffix... some with first, 2 middle names, last, and suffix.

I can figure out if a particular element is "III" or "Jr", but I don't know how to reference the LAST element in the string array since I don't know how many elements it has. Is there a way to reference the last element in an array? Like %nameArray_last% or something like that?
Back to top
View user's profile Send private message
ryanbarrier



Joined: 12 Jun 2008
Posts: 9

PostPosted: Thu Jun 12, 2008 7:16 pm    Post subject: Reply with quote

Ok I'm a nub. %nameArray0% contains the number of elements in the array...
Back to top
View user's profile Send private message
ryanbarrier



Joined: 12 Jun 2008
Posts: 9

PostPosted: Fri Jun 13, 2008 3:11 pm    Post subject: Reply with quote

For anyone reading this that wants to see my final resolution, here's the code I came up with to parse the text and split it as needed. I never figured out why the cut/copy commands weren't updating the clipboard information.

Code:
;-------------------------------------------------
; This hotkey analyzes the contents of the clipboard
; which should contain a name.  The name is split into
; individual names, and the last name is checked to see
; if it is a suffix.  Then the names are pasted into
; the appropriate fields in the form.
#a::
  fullName = %clipboard%
  StringSplit, nameArray, fullName, %A_Space%
  numElements := nameArray0
  firstName = %nameArray1%
  lastName := nameArray%numElements%
  suffix := nameArray%numElements%

  validSuffixes := "JR SR II III IV"

; If there is a suffix, set the last name to the name before it
; and update the number of middle names. Otherwise, empty
; the suffix variable and update number of middle names.
  IfInString, validSuffixes, %suffix%
  {
    secondLast := numElements - 1
    lastName := nameArray%secondLast%
    midElements := numElements - 3   ; exclude first, last, suffix
  }
  else
  {
    suffix =
    midElements := numElements - 2   ; exclude first, last names
  }

  Send {Ctrl Down}   ;
  Click 450,355      ; Highlight "Full Name" box
  Send {Ctrl up}   ;
  Send %fullName%   ; Paste Full Name

  Send {Ctrl Down}   ;
  Click 160,175      ; Highlight "First Name" box
  Send {Ctrl up}   ;
  Send %firstName%   ; Paste First Name

  i := 2   ; Counter variable.  Always start with 2nd name.
  Loop %midElements%   ; Note: there may be zero midElements
  {
    midName := nameArray%i%   ; get current middle name
    Send %A_Space%   ; type a space
    Send %midName%   ; type the name
    i += 1   ; increment counter, rinse, and repeat
  }

  Send {Ctrl Down}   ;
  Click 420,175      ; Highlight Last Name box
  Send {Ctrl up}   ;
  Send %lastName%   ; Paste Last Name
  If suffix   ; If suffix is empty (false) skip it
  {
    Send %A_Space%   ; Space
    Send %suffix%   ; Suffix
  }

return
;-------------------------------------------------
Back to top
View user's profile Send private message
Razlin



Joined: 05 Nov 2007
Posts: 417
Location: canada

PostPosted: Fri Jun 13, 2008 4:01 pm    Post subject: Reply with quote

Just a tip.
instead of ctrl down v ctrl up.
you can use

send %clipboard%

Which does the same for text output.

For your future scripts.
_________________
-=Raz=-
Back to top
View user's profile Send private message
engunneer



Joined: 30 Aug 2005
Posts: 6804
Location: Pacific Northwest, US

PostPosted: Fri Jun 13, 2008 6:31 pm    Post subject: Reply with quote

Sending %clipboard% may be slower than sending ^v, since the send command will type out each letter. The paste command is instant.

Changing the Sendmode can help.
_________________
Unless otherwise noted, all code is untested.
Common Answers: 1.(Loops, Viruses, etc.) 2. Search 3.RTFM
Back to top
View user's profile Send private message Visit poster's website
Razlin



Joined: 05 Nov 2007
Posts: 417
Location: canada

PostPosted: Fri Jun 13, 2008 6:45 pm    Post subject: Reply with quote

oh I do realize send and sendinput are slower then ^v I was only pointing it out as if ^v did not work..

My bad.. I guess I should have pointed that out.

If you cant use the control key then its another option..

my bad
_________________
-=Raz=-
Back to top
View user's profile Send private message
argneo



Joined: 14 Sep 2007
Posts: 133

PostPosted: Fri Jun 13, 2008 11:30 pm    Post subject: Reply with quote

I know why cut didn't work Razz... Shift was down ^^
_________________
WoW
Back to top
View user's profile Send private message
ryanbarrier



Joined: 12 Jun 2008
Posts: 9

PostPosted: Sat Jun 14, 2008 3:21 pm    Post subject: Reply with quote

Argneo I love you. I like my new code better, because it takes into account short last names (mostly Asian, like Yi and Ko), but I'm really glad you pointed out the error in the original code. Hopefully I'll remember that in the future Very Happy .

Thanks to Razlin and engunneer for the tips on sending clipboard too. I'm new to this language and I'm still learning (thus the baby scripts).
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group