Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Send key sequence to window until specific value in child field
#1
I need to run a loop sending a keys sequence and testing certain field for value and if the value is not meeting condition, reloop:

Code:
Copy      Help
int wMain=win("" "*.Window.*" "KeePass")
if(!wMain) ret;
int w=child("" "*.Window.*" wMain 0x0 "wfName=m_pbQuality")
if(!w) ret;
WindowText wt.Init(w)
 g1
'VDDY           ;; Space (40) (40) Enter
wait 50
str s=wt.CaptureToString
x = ????? ;; <===== extract the integer part from s
if(x < 52) goto g1
ret

1. How do I extract the integer part from 's' when it contains text like "57 bits" ?
2. Is it better to use WindowText wt.Init(w), wt.CaptureToString or s.getwintext(w) ?
#2
I am not sure about my advice, but it might get you started.

I think (repeat: think) s.getwintext(w) works faster and therefore is better IF it works on the object/interface you are interacting with.
If getwintext does not work then try "CaptureToString". I think "CaptureToString" is more complex (might contain advanced text-recognition code? or advanced text extraction code?). While "getwintext" extracts texts directly assuming the object contains textual data (window title,....etc...)

Below some examples regarding extracting the integer part.

Macro Macro41
Code:
Copy      Help
;; The below code finds/extracts numeric value from string
;; but after finding/extracting the numeric value it is still stored in an string variable
;; in order to do arithmetic and bitwise based actions (x*y , x<y,...) you must convert it to an integer or double
;; in your case integer. That's why you need i1, i2 , i3, i4 or i5 (see below code)


;; If you are 100% sure:
;;  - string BEGINS with numeric value
;;  - and everything after that can be ignored
;; example: "56 bits"

int i1
str s1="111 bits,...some other bla bla"
str s1_rgx="^[0-9]+"
str s1_result
findrx(s1 s1_rgx 0 0 s1_result) ;;"s1_result" now contains "111" but it is string
i1=val(s1_result) ;; convert contents of "s1_result" to integer value
out i1

;;---------------------------------------------------------------

;; If you are 100% sure:
;;  - string ENDS with numeric value
;;  - and everything before that can be ignored
;; example: "bits 56"

int i2
str s2="text text and more text bits 222"
str s2_rgx="[0-9]+$"
str s2_result
findrx(s2 s2_rgx 0 0 s2_result) ;;"s2_result" now contains "222" but it is string
i2=val(s2_result) ;; convert contents of "s2_result" to integer value
out i2

;;---------------------------------------------------------------

;; If you are 100% sure:
;;  - string contains ONE set of numeric value(s)
;;  - and everything before AND after that can be ignored
;; example: "there are 56 bits" , this example does not work correctly when you work with a string like this "123 there are 4 bits", result would be: "1234"
;; In other words extract numeric value from string

int i3
str s3="there are 333 bits followed by some text"
str s3_rgx="[^0-9]+"
s3.replacerx(s3_rgx "") ;; All NONE numeric characters have been removed, "333" only remains but it is string
i3=val(s3) ;; convert contents of "s3" to integer value, you can now use 'i3' for
out i3

;;---------------------------------------------------------------

;; Below 2 other examples you might have some use for


;; If we want to extract the numeric value from string '444 bits'
;; It also works if there are more then one spaces between '444' and 'bits'
;; or if there are no spaces between '444' and 'bits'
;; 'bits' can be upper or lowercase
str s4="123 there are 444 Bits test 123"
str s4_rgx="[0-9]+\s*bits" ;; The regex contains 'bits' in lowercase but below 'findrx' and 'findreplace' have the '1' flag set, meaning 'Case insensitive'
str s4_result
findrx(s4 s4_rgx 0 1 s4_result)
s4_result.findreplace("bits" "" 1) ;; remove 'bits' (case insensitive) from string "s4_result"
s4_result.trim ;; s4_result still contains an empty space, 'trim' removes empty space from beginning AND end of string
int i4=val(s4_result) ;; put contents of 's4_result' in integer 'i4'
out i4


;; If we want to extract the numeric value from string 'bits 555'
;; It also works if there are more then one spaces between '555' and 'bits'
;; or if there are no spaces between '555' and 'bits'
;; 'bits' can be upper or lowercase
str s5="123 there are Bits 555 test 123" ;; Not a normal situation, but wanted to show the reversed way
str s5_rgx="bits\s*[0-9]+" ;; The regex contains 'bits' in lowercase but below 'findrx' and 'findreplace' have the '1' flag set, meaning 'Case insensitive'
str s5_result
findrx(s5 s5_rgx 0 1 s5_result)
s5_result.findreplace("bits" "" 1) ;; remove 'bits' (case insensitive) from string "s5_result"
s5_result.trim ;; s5_result still contains an empty space, 'trim' removes empty space from beginning AND end of string
int i5=val(s5_result) ;; put contents of 's5_result' in integer 'i5'
out i5
#3
in your case you will have to keep using WindowText wt.Init(w), wt.CaptureToString because its a custom progress bar in .net so get wintext wont work
try this

Code:
Copy      Help
int wMain=win("" "*.Window.*" "KeePass")
if(!wMain) ret;
int w=child("" "*.Window.*" wMain 0x0 "wfName=m_pbQuality")
if(!w) ret;
WindowText wt.Init(w)
;g1
'VDDY           ;; Space (40) (40) Enter
wait 50
str s=wt.CaptureToString
str pattern= "\d+"
str ss
findrx(s pattern 0 1 ss)
int x = val(ss)
if(x < 52) goto g1
ret
#4
Thanks! val(...) worked for me fine


Forum Jump:


Users browsing this thread: 1 Guest(s)