-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathlibcvautomation_funcs
795 lines (657 loc) · 21 KB
/
libcvautomation_funcs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
#!/bin/sh
#===============================================================================
# FILE: libcvautomation_funcs
#
# USAGE: . mosaic_testing_funcs
#
# DESCRIPTION:
#
# OPTIONS: ---
# REQUIREMENTS: ---
# BUGS: ---
# NOTES: ---
# AUTHOR: Bradlee Speice, [email protected]
# ORGANIZATION:
# CREATED: 06/19/2012 11:35:20 AM EDT
# REVISION: ---
#===============================================================================
#-------------------------------------------------------------------------------
# This script file is meant to be sourced and then used for driving libcvautomation.
# It provides access to a lot of common macros, like clicking
# an area of the screen based on an image.
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
# NOTE: Due to the way loops work in this script, you may NOT use spaces
# in file names.
#-------------------------------------------------------------------------------
#Make sure all the programs we will need are in the right place
CVAMATCH=`which cva-match` || echo "Could not find the cva-match program..." &>2 #Needed for image recognition
CVAINPUT=`which cva-input` || echo "Could not find the cva-input program..." &>2 #Needed to manipulate mouse and keyboard
INT_MAX=2147483647
#Some program-wide configs
SEARCH_METHOD=0 #CV_TM_SQDIFF
TOLERANCE=2250000
USE_SANE_TOLERANCE=""
#Set to non-null to enable sane tolerance matching
#ex: USE_SANE_TOLERANCE="yes"
USE_CENTER="yes"
#Set to null to disable center-of-image matching
#ex: USE_CENTER=""
USE_WAIT="yes"
#Set to null to disable waiting before an action
#ex: USE_WAIT=""
TIMEOUT=5
#Quick trick to allow for easy redirection of output
#OUTFILE=`mktemp`; echo "Logfile: " $OUTFILE
OUTFILE=/dev/null
#ERRFILE=`mktemp`; echo "Error file: " $ERRFILE
ERRFILE=/dev/null
out ()
{
echo "`date`: $@" >> $OUTFILE
}
err ()
{
echo "`date`: $@" >> $ERRFILE
}
#-------------------------------------------------------------------------------
# Begin testing macros
#-------------------------------------------------------------------------------
#--- FUNCTION ----------------------------------------------------------------
# NAME: mouse_down
# DESCRIPTION: Push the mouse button down, and leave it there.
# PARAMETERS:
# RETURNS:
#-------------------------------------------------------------------------------
mouse_down ()
{
if [ -n "$1" ]; then
eval $CVAINPUT -s 'mousedown "$1"' >> $OUTFILE
else
eval $CVAINPUT -s 'mousedown 1' >> $OUTFILE
fi
return $?
} # ---------- end of function mouse_down ----------
#--- FUNCTION ----------------------------------------------------------------
# NAME: mouse_up
# DESCRIPTION: Release a mouse button
# PARAMETERS:
# RETURNS:
#-------------------------------------------------------------------------------
mouse_up ()
{
if [ -n "$1" ]; then
eval $CVAINPUT -s 'mouseup "$1"' >> $OUTFILE
else
eval $CVAINPUT -s 'mouseup 1' >> $OUTFILE
fi
return $?
} # ---------- end of function mouse_up ----------
#--- FUNCTION ----------------------------------------------------------------
# NAME: mouse_click
# DESCRIPTION: Click the mouse where it is currently located
# PARAMETERS:
# RETURNS:
#-------------------------------------------------------------------------------
mouse_click ()
{
if [ -n "$1" ]; then
eval '$CVAINPUT -s "mouseclick \"$1\"" >> $OUTFILE'
else
eval '$CVAINPUT -s "mouseclick 1" >> $OUTFILE'
fi
return $?
} # ---------- end of function mouse_click ----------
#--- FUNCTION ----------------------------------------------------------------
# NAME: mouse_click_xy
# DESCRIPTION: Click a specific point on the screen
# PARAMETERS: x-location, y-location
# RETURNS:
#-------------------------------------------------------------------------------
mouse_click_xy ()
{
if [ -z "$1" ]; then
out "Did not specify an X location, assuming (0, 0)"
X_LOC=0
Y_LOC=0
else
X_LOC=$1
fi
if [ -z "$2" ]; then
out "Did not specify a Y location, assuming ($1, 0)"
else
Y_LOC=$2
fi
out "mouse_click_xy: " $X_LOC $Y_LOC
if [ -n "$3" ]; then
eval '$CVAINPUT -s "mousexy $X_LOC $Y_LOC" -s "mouseclick $3" >> $OUTFILE'
else
eval '$CVAINPUT -s "mousexy $X_LOC $Y_LOC" -s "mouseclick 1" >> $OUTFILE'
fi
return $?
} # ---------- end of function mouse_click_xy ----------
#--- FUNCTION ----------------------------------------------------------------
# NAME: mouse_click_rxy
# DESCRIPTION: Click a point on the screen relative to where the mouse is at
# PARAMETERS: X increment, Y increment
# RETURNS:
#-------------------------------------------------------------------------------
mouse_click_rxy ()
{
if [ -z "$1" ]; then
out "Did not specify an X increment, assuming (0, 0)"
X_INC=0
Y_INC=0
else
X_INC=$1
fi
if [ -z "$2" ]; then
out "Did not specify a Y increment, assuming ($X_INC, 0)"
else
Y_INC=$2
fi
out "mouse_click_rxy: " $1 $2
if [ -n "$3" ]; then
eval '$CVAINPUT -s "mouserxy $1 $2" -s "mouseclick 1" >> $OUTFILE'
else
eval '$CVAINPUT -s "mouserxy $1 $2" -s "mouseclick 1" >> $OUTFILE'
fi
return $?
} # ---------- end of function mouse_click_rxy ----------
#--- FUNCTION ----------------------------------------------------------------
# NAME: mouse_click_image
# DESCRIPTION: Click a point based on a screenshot
# PARAMETERS: Location of screenshot, optional index to use if multiple
# matches are found
# RETURNS:
#-------------------------------------------------------------------------------
mouse_click_image ()
{
RETURN_CODE=255
COMMAND_LINE=""
if [ -z "$1" ]; then
err "Did not give a base image..."
return 255
fi
out "mouse_click_image: matching $@"
if [ -n "$USE_CENTER" ]; then
center="c"
else
center=""
fi
if [ -n "$USE_SANE_TOLERANCE" ]; then
TOLERANCE_OPTION="-o"
else
TOLERANCE_OPTION="-t"
fi
if [ -z "$TOLERANCE" ]; then
TOLERANCE=$INT_MAX
fi
if [ -n "$USE_WAIT" ]; then
#Alternate between each image until a match is found, or we loop $TIMEOUT times
#This is a bit weird, since we need to lower the TIMEOUT value for the "waitfor"
#function, and then restore it at the end.
OLD_TIMEOUT=$TIMEOUT
TIMEOUT=1
#I don't like this syntax, but 'for loop in {1..$OLD_TIMEOUT}' doesn't work
for loop in `seq 1 $OLD_TIMEOUT`
do
for x in "$@"
do
CVA_RETURN=`waitfor "$x"`
if [ $CVA_RETURN -lt $RETURN_CODE ]; then
RETURN_CODE=$CVA_RETURN
fi
if [ $CVA_RETURN -eq 0 ]; then
#We found the image, click it
TIMEOUT=$OLD_TIMEOUT
eval "$CVAINPUT $TOLERANCE_OPTION $TOLERANCE --search-method $SEARCH_METHOD -s 'i${center}mouseclick \"$x\"' >> $OUTFILE"
return $?
fi
done
done
#We'll get here if we don't find a match
TIMEOUT=$OLD_TIMEOUT
else
eval "$CVAINPUT $TOLERANCE_OPTION $TOLERANCE --search-method $SEARCH_METHOD -s 'i${center}mouseclick \"$x\"' >> $OUTFILE"
CVA_RETURN=$?
if [ $CVA_RETURN -lt $RETURN_CODE ]; then
RETURN_CODE=$CVA_RETURN
fi
fi
return $RETURN_CODE
} # ---------- end of function mouse_click_image ----------
#--- FUNCTION ----------------------------------------------------------------
# NAME: mouse_rightclick_image
# DESCRIPTION: Exactly like click_i, but click the right mouse button
# PARAMETERS:
# RETURNS:
#-------------------------------------------------------------------------------
mouse_rightclick_image ()
{
out "mouse_rightclick_image: $@"
mouse_hover_image "$@" && click 3
} # ---------- end of function mouse_rightclick_image ----------
#--- FUNCTION ----------------------------------------------------------------
# NAME: mouse_doubleclick
# DESCRIPTION: Click the mouse twice
# PARAMETERS:
# RETURNS:
#-------------------------------------------------------------------------------
mouse_doubleclick ()
{
out "mouse_doubleclick: $1"
if [ -n "$1" ]; then
mouse_click "$1" && mouse_click "$1"
else
mouse_click && mouse_click
fi
} # ---------- end of function mouse_doubleclick ----------
#--- FUNCTION ----------------------------------------------------------------
# NAME: mouse_doubleclick_xy
# DESCRIPTION: Click the mouse twice on a specific location
# PARAMETERS:
# RETURNS:
#-------------------------------------------------------------------------------
mouse_doubleclick_xy ()
{
if [ -z "$1" ]; then
err "Did not specify an X location, assuming (0, 0)"
X_LOC=0
Y_LOC=0
else
X_LOC=$1
fi
if [ -z "$2" ]; then
err "Did not specify a Y location, assuming ($1, 0)"
else
Y_LOC=$2
fi
out "mouse_doubleclick_xy $X_LOC $Y_LOC"
if [ -n "$3" ]; then
mouse_click_xy "$X_LOC" "$Y_LOC" "$3" && mouse_click "$3"
else
mouse_click_xy "$X_LOC" "$Y_LOC" && mouse_click
fi
return $?
} # ---------- end of function mouse_doubleclick_xy ----------
#--- FUNCTION ----------------------------------------------------------------
# NAME: mouse_doubleclick_rxy
# DESCRIPTION: Click the mouse twice on a relative location
# PARAMETERS:
# RETURNS:
#-------------------------------------------------------------------------------
mouse_doubleclick_rxy ()
{
if [ -z "$1" ]; then
err "Did not specify an X increment, assuming (0, 0)"
X_INC=0
Y_INC=0
else
X_INC="$1"
fi
if [ -z "$2" ]; then
err "Did not specify a Y increment, assuming ($X_INC, 0)"
else
Y_INC="$2"
fi
out "doubleclickr_xy: $X_INC $Y_INC"
if [ -n "$3" ]; then
mouse_clickr_xy "$X_INC" "$Y_INC" "$3" && mouse_click "$3"
else
mouse_clickr_xy "$1" "$2" && mouse_click
fi
return $?
} # ---------- end of function mouse_doubleclick_rxy ----------
#--- FUNCTION ----------------------------------------------------------------
# NAME: mouse_doubleclick_image
# DESCRIPTION: Double-click an image - moves to image first and then
# executes a double-click to make sure that it is
# compatible with multiple image arguments
# PARAMETERS:
# RETURNS:
#-------------------------------------------------------------------------------
mouse_doubleclick_image ()
{
out "mouse_doubleclick_image: $@"
mouse_hover_image "$@" && mouse_click && mouse_click
} # ---------- end of function mouse_doubleclick_image ----------
#--- FUNCTION ----------------------------------------------------------------
# NAME: image_location
# DESCRIPTION: Get the location of a subimage in root
# PARAMETERS: PNG Filename of sub-image
# RETURNS: "X_LOC,Y_LOC"
#-------------------------------------------------------------------------------
image_location ()
{
COMMAND_LINE=""
if [ -z "$1" ]; then
err "Did not give a base image..."
return 255
fi
#Build the command line arguments
for x in "$@"
do
COMMAND_LINE+="-s \"$x\" "
done
#Find our sub-image
if [ -n "$USE_SANE_TOLERANCE" ]; then
TOLERANCE_OPTION="-o"
else
TOLERANCE_OPTION="-t"
fi
if [ -z "$TOLERANCE" ]; then
TOLERANCE=$INT_MAX
fi
if [ -n "$USE_CENTER" ]; then
CENTER="--center"
else
CENTER=""
fi
MATCH=`$CVAMATCH $TOLERANCE_OPTION $TOLERANCE $CENTER --x-root $COMMAND_LINE`
RETURN_CODE=$?
out "$MATCH"
MATCH=`echo $MATCH | head -n1`
if [ x"$MATCH" == "x" ]; then
err "Could not find a match between \"$@\" and the root window."
return 255
fi
IMAGE_NAME=`echo "$MATCH" | cut -d',' -f1`
X_LOC=`echo "$MATCH" | cut -d',' -f2`
Y_LOC=`echo "$MATCH" | cut -d',' -f3`
out "image_location: \"$MATCH\" " "$X_LOC,$Y_LOC,$IMAGE_NAME"
echo "$X_LOC,$Y_LOC"
return $RETURN_CODE
} # ---------- end of function image_location ----------
#--- FUNCTION ----------------------------------------------------------------
# NAME: mouse_hover_xy
# DESCRIPTION: Move the mouse to location X Y
# PARAMETERS: X_LOC, Y_LOC
# RETURNS:
#-------------------------------------------------------------------------------
mouse_hover_xy ()
{
if [ -z "$1" ]; then
err "Did not provide an X location, assuming 0..."
X_LOC=0
else
X_LOC=$1
fi
if [ -z "$2" ]; then
err "Did not provide a Y location, assuming 0..."
Y_LOC=0
else
Y_LOC=$2
fi
out "mouse_hover_xy: $X_LOC $Y_LOC"
eval '$CVAINPUT -s "mousexy $X_LOC $Y_LOC" >> $OUTFILE'
return $?
} # ---------- end of function mouse_hover_xy ----------
#--- FUNCTION ----------------------------------------------------------------
# NAME: mouse_hover_rxy
# DESCRIPTION: Move the mouse over X and up Y
# PARAMETERS:
# RETURNS:
#-------------------------------------------------------------------------------
mouse_hover_rxy ()
{
if [ -z "$1" ]; then
err "Did not provide an X increment, assuming 0..."
X_INC=0
else
X_INC=$1
fi
if [ -z "$2" ]; then
err "Did not provide a Y increment, assuming 0..."
Y_INC=0
else
Y_INC=$1
fi
out "mouse_hover_rxy: $X_INC $Y_INC"
eval '$CVAINPUT -s "mouserxy $X_INC $Y_INC" >> $OUTFILE'
return $?
} # ---------- end of function mouse_hover_rxy ----------
#--- FUNCTION ----------------------------------------------------------------
# NAME: mouse_hover_image
# DESCRIPTION: Move the mouse to the center of image on root window
# PARAMETERS: PNG File name
# RETURNS:
#-------------------------------------------------------------------------------
mouse_hover_image ()
{
RETURN_CODE=255
COMMAND_LINE=""
if [ -z "$1" ]; then
err "Did not give a base image."
return 255
fi
out "hover_i: $@"
if [ -n "$USE_CENTER" ]; then
center="c"
else
center=""
fi
if [ -n "$USE_SANE_TOLERANCE" ]; then
TOLERANCE_OPTION="-o"
else
TOLERANCE_OPTION="-t"
fi
if [ -z "$TOLERANCE" ]; then
TOLERANCE=$INT_MAX
fi
if [ -n "$USE_WAIT" ]; then
#Alternate between each image until a match is found, or we loop $TIMEOUT times
#This is a bit weird, since we need to lower the TIMEOUT value for the "waitfor"
#function, and then restore it at the end.
OLD_TIMEOUT=$TIMEOUT
TIMEOUT=1
#I don't like this syntax, but 'for loop in {1..$OLD_TIMEOUT}' doesn't work
for loop in `seq 1 $OLD_TIMEOUT`
do
for x in "$@"
do
CVA_RETURN=`waitfor "$x"`
if [ $CVA_RETURN -lt $RETURN_CODE ]; then
RETURN_CODE=$CVA_RETURN
fi
if [ $CVA_RETURN -eq 0 ]; then
#We found the image, click it
eval "$CVAINPUT $TOLERANCE_OPTION $TOLERANCE --search-method $SEARCH_METHOD -s '${center}mouseimage \"$x\"' >> $OUTFILE"
TIMEOUT=$OLD_TIMEOUT
return $?
fi
done
done
#We'll get here if we didn't find a match
TIMEOUT=$OLD_TIMEOUT
else
eval "$CVAINPUT $TOLERANCE_OPTION $TOLERANCE --search-method $SEARCH_METHOD -s '${center}mouseimage \"$x\"' >> $OUTFILE"
CVA_RETURN=$?
if [ $CVA_RETURN -lt $RETURN_CODE ]; then
RETURN_CODE=$CVA_RETURN
fi
fi
return $RETURN_CODE
} # ---------- end of function mouse_hover_image ----------
#--- FUNCTION ----------------------------------------------------------------
# NAME: mouse_jiggle
# DESCRIPTION: Moves the mouse down-right 1 pixel, and then back - necessary
# for activation some widgets
# PARAMETERS:
# RETURNS:
#-------------------------------------------------------------------------------
mouse_jiggle ()
{
out "mouse_jiggle"
eval '$CVAINPUT -s "mousejiggle" >> $OUTFILE'
return $?
} # ---------- end of function mouse_jiggle ----------
#--- FUNCTION ----------------------------------------------------------------
# NAME: mouse_scroll_up
# DESCRIPTION: Scroll the mouse wheel up one
# PARAMETERS:
# RETURNS:
#-------------------------------------------------------------------------------
mouse_scroll_up ()
{
out "mouse_scrollu"
eval '$CVAINPUT -s "mousescrollu" >> $OUTFILE'
return $?
} # ---------- end of function mouse_scroll_up ----------
#--- FUNCTION ----------------------------------------------------------------
# NAME: mouse_scroll_down
# DESCRIPTION: Scroll the mouse wheel down one
# PARAMETERS:
# RETURNS:
#-------------------------------------------------------------------------------
mouse_scroll_down ()
{
out "mouse_scroll_down"
eval '$CVAINPUT -s "mousescrolld" >> $OUTFILE'
return $?
} # ---------- end of function mouse_scroll_down ----------
#--- FUNCTION ----------------------------------------------------------------
# NAME: mouse_drag_n_drop
# DESCRIPTION: Drag one image to another image
# PARAMETERS:
# RETURNS:
#-------------------------------------------------------------------------------
mouse_drag_n_drop ()
{
if [ -z "$1" ]; then
err "mouse_drag_n_drop: Did not give me an image to drag!"
return 255
elif [ -z "$2" ]; then
err "mouse_drag_n_drop: Did not give me an image to drag to!"
return 255
fi
#We have our images to find, hover over the first, mousedown, and then
#hover over the other one, and mouseup.
mouse_hover_image "$1"
if [ $? -ne 0 ]; then
err "mouse_drag_n_drop: Could not find image to drag!"
else
mouse_down 1
mouse_hover_image "$2" || err "mouse_drag_n_drop: Could not find image to drag to!"
mouse_up
fi
} # ---------- end of function mouse_drag_n_drop ----------
#--- FUNCTION ----------------------------------------------------------------
# NAME: key_string
# DESCRIPTION: Simulate pressing keys according to $1
# PARAMETERS: String of text as $1
# RETURNS:
#-------------------------------------------------------------------------------
key_string ()
{
COMMAND_LINE=""
if [ -z "$1" ]; then
err "Did not give me a string to enter..."
return 255
fi
#We use $* instead of $@ because they expand a bit differently -
# "$*" -> "$1 $2 $3"
# "$@" -> "$1" "$2" "$3"
COMMAND_LINE="-s 'keystring $*'"
out "key_str: \"$*\""
eval "$CVAINPUT $COMMAND_LINE >> $OUTFILE"
return $?
} # ---------- end of function key_string ----------
#--- FUNCTION ----------------------------------------------------------------
# NAME: key_down
# DESCRIPTION: Presses down a key - necessary for stuff like Alt-shortcuts
# PARAMETERS:
# RETURNS:
#-------------------------------------------------------------------------------
key_down ()
{
if [ -z "$1" ]; then
err "Did not give me a key to press down..."
return 255
fi
out "key_down: $1"
eval '$CVAINPUT -s "keydown $1" >> $OUTFILE'
return $?
} # ---------- end of function key_down ----------
#--- FUNCTION ----------------------------------------------------------------
# NAME: key_up
# DESCRIPTION: Lifts a key up - every key_down should have a key_up
# PARAMETERS:
# RETURNS:
#-------------------------------------------------------------------------------
key_up ()
{
if [ -z "$1" ]; then
err "Did not give me a key to release..."
fi
out "key_up: $1"
eval "$CVAINPUT -s 'keyup $1' >> $OUTFILE"
return $?
} # ---------- end of function key_up ----------
#--- FUNCTION ----------------------------------------------------------------
# NAME: key_click
# DESCRIPTION: Clicks a single key
# PARAMETERS:
# RETURNS:
#-------------------------------------------------------------------------------
key_click ()
{
if [ -z "$1" ]; then
err "Did not give me a key to press..."
fi
out "key_click: $1"
eval "$CVAINPUT -s 'keyclick $1' >> $OUTFILE"
return $?
} # ---------- end of function key_press ----------
#--- FUNCTION ----------------------------------------------------------------
# NAME: wait_for
# DESCRIPTION: Wait for an image to be displayed
# PARAMETERS:
# RETURNS:
#-------------------------------------------------------------------------------
wait_for ()
{
if [ -z "$1" ]; then
err "Did not give me an image to find..."
fi
out "wait_for: $1"
if [ -n "$USE_SANE_TOLERANCE" ]; then
if [ -z "$TOLERANCE" ]; then
TOLERANCE=$INT_MAX
fi
eval '$CVAINPUT -o $TOLERANCE --search-method $SEARCH_METHOD --timeout $TIMEOUT -s "waitfor \"$1\"" >> $OUTFILE'
else
if [ -z "$TOLERANCE" ]; then
TOLERANCE=$INT_MAX
fi
eval '$CVAINPUT -t $TOLERANCE --search-method $SEARCH_METHOD --timeout $TIMEOUT -s "waitfor \"$1\"" >> $OUTFILE'
fi
RETURN_CODE=$?
echo $RETURN_CODE
#We don't return here, but rather just pass the return code up -
#This makes sure that if the user sets errexit, we don't abort because
#multiple images were used, while still keeping the return code.
} # ---------- end of function waitfor ----------
#--- FUNCTION ----------------------------------------------------------------
# NAME: notify
# DESCRIPTION: Notify the user and pause
# PARAMETERS:
# RETURNS:
#-------------------------------------------------------------------------------
notify ()
{
if [ -z "$1" ]; then
#Not given any text to display, return an error
return 255
fi
if [ -n "$DISPLAY" ]; then
which zenity &> /dev/null
#If zenity isn't found, we don't want to go to a read prompt -
#the user may not be running this from a terminal.
if [ $? -eq 0 ]; then
zenity --info --text="$@"
fi
else
read -p "$@"
fi
} # ---------- end of function notify ----------