Module: Mouse

Defined in:
ext/mouse/mouse.c,
lib/mouse/version.rb,
ext/mouse/mouse.c

Overview

A module with methods that "tap" into the system input methods. This is done by wrapping wrapping around the CoreGraphics event taps API provided by OS X.

The module provides a simple Ruby interface to performing mouse interactions such as moving and clicking.

This module can be used in a stand alone fashion or you can mix it into another class.

Reference

Constant Summary

VERSION =

Returns:

  • (String)
'4.0.3'

Instance Method Summary collapse

Instance Method Details

#arbitrary_click(button) ⇒ CGPoint #arbitrary_click(button, point) ⇒ CGPoint

Generate a click using an arbitrary mouse button (down and up events)

Numbers are used to map the mouse buttons. At the time of writing, the documented values are:

  • kCGMouseButtonLeft = 0
  • kCGMouseButtonRight = 1
  • kCGMouseButtonCenter = 2

And the rest are not documented! Though they should be easy enough to figure out. See the CGMouseButton enum in the reference documentation for the most up to date list.

You can optionally specify a point to click; the mouse cursor will instantly jump to the given point; otherwise the click event happens at the current cursor position.

Overloads:

  • #arbitrary_click(button) ⇒ CGPoint

    Parameters:

    • button (Number, #to_i)

    Returns:

  • #arbitrary_click(button, point) ⇒ CGPoint

    Parameters:

    • button (Number, #to_i)
    • point (CGPoint)

    Returns:



537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
# File 'ext/mouse/mouse.c', line 537

static
VALUE
rb_mouse_arbitrary_click(const int argc,
                         VALUE* const argv,
                         UNUSED const VALUE self)
{
    if (argc == 0) {
        rb_raise(rb_eArgError, "arbitrary_click requires at least one arg");
        return Qnil;
    }

    const uint_t button = NUM2UINT(argv[0]);

    switch (argc) {
    case 1:
        mouse_arbitrary_click(button);
        break;
    case 2:
    default:
        mouse_arbitrary_click2(button, rb_mouse_unwrap_point(argv[1]));
    }

    return CURRENT_POSITION;
}

#arbitrary_click_downCGPoint #arbitrary_click_down(point) ⇒ CGPoint

Generate the down click part of an arbitrary click event

This might be useful in concert with arbitrary_click_up if you want to inject some behaviour between the down and up click events.

You can optionally specify a point to click; the mouse cursor will instantly jump to the given point; otherwise the click event happens at the current cursor position.

Overloads:



447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
# File 'ext/mouse/mouse.c', line 447

static
VALUE
rb_mouse_arbitrary_click_down(const int argc,
                              VALUE* const argv,
                              UNUSED const VALUE self)
{
    if (argc == 0)
        rb_raise(rb_eArgError,
                 "arbitrary_click_down requires at least one arg");

    const uint_t button = NUM2UINT(argv[0]);

    switch (argc) {
    case 1:
        mouse_arbitrary_click_down(button);
        break;
    case 2:
    default:
        mouse_arbitrary_click_down2(button, rb_mouse_unwrap_point(argv[1]));
    }

    return CURRENT_POSITION;
}

#arbitrary_click_upCGPoint #arbitrary_click_up(point) ⇒ CGPoint

Generate the up click part of an arbitrary click event

This might be useful in concert with arbitrary_click_down if you want to inject some behaviour between the down and up click events.

You can optionally specify a point to click; the mouse cursor will instantly jump to the given point; otherwise the click event happens at the current cursor position.

Overloads:



487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
# File 'ext/mouse/mouse.c', line 487

static
VALUE
rb_mouse_arbitrary_click_up(const int argc,
                            VALUE* const argv,
                            UNUSED const VALUE self)
{
    if (argc == 0)
        rb_raise(rb_eArgError,
                 "arbitrary_click_up requires at least one arg");

    const uint_t button = NUM2UINT(argv[0]);

    switch (argc) {
    case 1:
        mouse_arbitrary_click_up(button);
        break;
    case 2:
    default:
        mouse_arbitrary_click_up2(button, rb_mouse_unwrap_point(argv[1]));
    }

    return CURRENT_POSITION;
}

#clickCGPoint #clickCGPoint

Generate a regular click event (both up and down events)

You can optionally specify a point to click; the mouse cursor will instantly jump to the given point; otherwise the click event happens at the current cursor position.

Overloads:



312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
# File 'ext/mouse/mouse.c', line 312

static
VALUE
rb_mouse_click(const int argc, VALUE* const argv, UNUSED const VALUE self)
{
    switch (argc) {
    case 0:
        mouse_click();
        break;
    case 1:
    default:
        mouse_click2(rb_mouse_unwrap_point(argv[0]));
    }

    return CURRENT_POSITION;
}

#click_downCGPoint #click_down(point) ⇒ CGPoint

Generate the down click part of a click event

This might be useful in concert with click_up if you want to inject some behaviour between the down and up click events.

You can optionally specify a point to click; the mouse cursor will instantly jump to the given point; otherwise the click event happens at the current cursor position.

Overloads:



249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
# File 'ext/mouse/mouse.c', line 249

static
VALUE
rb_mouse_click_down(const int argc,
                    VALUE* const argv,
                    UNUSED const VALUE self)
{
    switch (argc) {
    case 0:
        mouse_click_down();
        break;
    case 1:
    default:
        mouse_click_down2(rb_mouse_unwrap_point(argv[0]));
    }

    return CURRENT_POSITION;
}

#click_upCGPoint #click_up(point) ⇒ CGPoint

Generate the up click part of a click event

This might be useful in concert with click_down if you want to inject some behaviour between the down and up click events.

You can optionally specify a point to click; the mouse cursor will instantly jump to the given point; otherwise the click event happens at the current cursor position.

Overloads:



283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
# File 'ext/mouse/mouse.c', line 283

static
VALUE
rb_mouse_click_up(const int argc, VALUE* const argv, UNUSED const VALUE self)
{
    switch (argc) {
    case 0:
        mouse_click_up();
        break;
    case 1:
    default:
        mouse_click_up2(rb_mouse_unwrap_point(argv[0]));
    }

    return CURRENT_POSITION;
}

#current_positionCGPoint

Returns the current co-ordinates of the mouse cursor

Returns:



43
44
45
46
47
48
# File 'ext/mouse/mouse.c', line 43

static
VALUE
rb_mouse_current_position(UNUSED const VALUE self)
{
    return CURRENT_POSITION;
}

#double_clickCGPoint #double_click(point) ⇒ CGPoint

Perform a double click at the given mouse position

Implemented by first generating a single click, and then a double click., Apps seem to respond more consistently to this behaviour since that is how a human would have to generate a double click event.

You can optionally specify a point to click; the mouse cursor will instantly jump to the given point; otherwise the click event happens at the current cursor position.

Overloads:



657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
# File 'ext/mouse/mouse.c', line 657

static
VALUE
rb_mouse_double_click(const int argc,
                      VALUE* const argv,
                      UNUSED const VALUE self)
{
    switch (argc) {
    case 0:
        mouse_double_click();
        break;
    case 1:
    default:
        mouse_double_click2(rb_mouse_unwrap_point(argv[0]));
    }

    return CURRENT_POSITION;
}

#drag_toCGPoint

Drag the mouse cursor to the given co-ordinates

Returns:



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'ext/mouse/mouse.c', line 89

static
VALUE
rb_mouse_drag_to(const int argc,
                 VALUE* const argv,
                 UNUSED const VALUE self)
{
    switch (argc) {
    case 0:
        rb_raise(rb_eArgError, "drag_to requires at least a one arg");
    case 1:
        mouse_drag_to(rb_mouse_unwrap_point(argv[0]));
        break;
    case 2:
    default:
        mouse_drag_to2(rb_mouse_unwrap_point(argv[0]), NUM2DBL(argv[1]));
    }

    return CURRENT_POSITION;
}

#horizontal_scroll(amount) ⇒ Number #horizontal_scroll(amount, units) ⇒ Number #horizontal_scroll(amount, units, duration) ⇒ Number Also known as: hscroll

Note:

Scrolling by :pixel may not actually be by real pixels, but instead correspond to Cocoa co-ords (I don't have a retina display, so I haven't checked it out yet).

Generate amount of horizontal scroll events at the current cursor position

Returns number of lines/pixels scrolled, default units are by line. A positive amount will scroll up and a negative amount will scroll down.

An animation duration can also be specified, which defaults to 0.2 seconds.

Overloads:

  • #horizontal_scroll(amount) ⇒ Number

    Parameters:

    • amount (Number)

    Returns:

    • (Number)
  • #horizontal_scroll(amount, units) ⇒ Number

    Parameters:

    • amount (Number)
    • units (Symbol)

      :pixel or :line

    Returns:

    • (Number)
  • #horizontal_scroll(amount, units, duration) ⇒ Number

    Parameters:

    • amount (Number)
    • units (Symbol)

      :pixel or :line

    • duration (Number)

      animation time, in seconds

    Returns:

    • (Number)


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
# File 'ext/mouse/mouse.c', line 195

static
VALUE
rb_mouse_horizontal_scroll(const int argc,
                           VALUE* const argv,
                           UNUSED const VALUE self)
{
    if (argc == 0 || argc > 3)
        rb_raise(rb_eArgError,
                 "scroll requires 1..3 arguments, you gave %d",
                 argc);

    const int amt = NUM2INT(argv[0]);

    if (argc == 1) {
        mouse_horizontal_scroll(amt);

    } else {
        const VALUE input_units = argv[1];
        CGScrollEventUnit units = kCGScrollEventUnitLine;

        if (input_units == sym_pixel)
            units = kCGScrollEventUnitPixel;
        else if (input_units == sym_line)
            units = kCGScrollEventUnitLine;
        else
            rb_raise(rb_eArgError,
                     "unknown units `%s'",
                     rb_id2name(SYM2ID(input_units)));

        if (argc == 2)
            mouse_horizontal_scroll2(amt, units);
        else
            mouse_horizontal_scroll3(amt, units, NUM2DBL(argv[2]));
    }

    return argv[0];
}

#middle_clickCGPoint #middle_click(point) ⇒ CGPoint

Generate a click event for the middle mouse button (down and up events)

It doesn't matter if you don't have a middle mouse button.

You can optionally specify a point to click; the mouse cursor will instantly jump to the given point; otherwise the click event happens at the current cursor position.

Overloads:



577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
# File 'ext/mouse/mouse.c', line 577

static
VALUE
rb_mouse_middle_click(const int argc,
                      VALUE* const argv,
                      UNUSED const VALUE self)
{
    switch (argc) {
    case 0:
        mouse_middle_click();
        break;
    case 1:
    default:
        mouse_middle_click2(rb_mouse_unwrap_point(argv[0]));
    }

    return CURRENT_POSITION;
}

#move_to(point) ⇒ CGPoint #move_to(point, duration) ⇒ CGPoint

Move the mouse cursor to the given co-ordinates

The default duration is 0.2 seconds.

Overloads:

  • #move_to(point) ⇒ CGPoint

    Parameters:

    Returns:

  • #move_to(point, duration) ⇒ CGPoint

    Parameters:

    • point (CGPoint, Array(Number,Number), #to_point)
    • duration (Number)

      animation time, in seconds

    Returns:



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'ext/mouse/mouse.c', line 63

static
VALUE
rb_mouse_move_to(const int argc,
                 VALUE* const argv,
                 UNUSED const VALUE self)
{
    switch (argc) {
    case 0:
        rb_raise(rb_eArgError, "move_to requires at least a one arg");
    case 1:
        mouse_move_to(rb_mouse_unwrap_point(argv[0]));
        break;
    case 2:
    default:
        mouse_move_to2(rb_mouse_unwrap_point(argv[0]), NUM2DBL(argv[1]));
    }

    return CURRENT_POSITION;
}

#multi_click(num_clicks) ⇒ CGPoint #multi_click(num_clicks, point) ⇒ CGPoint

Generate a multi-click event at the current mouse position

Unlike double_click and triple_click this will generate a single event with the given number of clicks.

You can optionally specify a point to click; the mouse cursor will instantly jump to the given point; otherwise the click event happens at the current cursor position.

Overloads:

  • #multi_click(num_clicks) ⇒ CGPoint

    Parameters:

    • num_clicks (Number, #to_i)

    Returns:

  • #multi_click(num_clicks, point) ⇒ CGPoint

    Parameters:

    • num_clicks (Number, #to_i)
    • point (CGPoint)

    Returns:



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
# File 'ext/mouse/mouse.c', line 613

static
VALUE
rb_mouse_multi_click(const int argc,
                     VALUE* const argv,
                     UNUSED const VALUE self)
{

    if (argc == 0) {
        rb_raise(rb_eArgError, "multi_click requires at least one arg");
        return Qnil;
    }

    // TODO: there has got to be a more idiomatic way to do this coercion
    const size_t num_clicks = NUM2SIZET(argv[0]);

    switch (argc) {
    case 1:
        mouse_multi_click(num_clicks);
        break;
    case 2:
    default:
        mouse_multi_click2(num_clicks, rb_mouse_unwrap_point(argv[1]));
    }

    return CURRENT_POSITION;
}

#pinch(direction) ⇒ CGPoint #pinch(direction, magnification) ⇒ CGPoint #pinch(direction, magnification, point) ⇒ CGPoint #pinch(direction, magnification, point, duration) ⇒ CGPoint

Perform a pinch gesture in given direction

You can optionally specify the magnification factor and/or duration for the pinch event.

Available pinch directions are:

  • :zoom or :expand
  • :unzoom or :contract

Magnification is a relative magnification setting. A zoom value of 1.0 means 1.0 more than the current zoom level. 2.0 would be 2.0 levels higher than the current zoom. Default is 1.0.

You can also optionally specify a point on screen for the mouse pointer to be moved to before the gesture begins. The movement will be instantaneous. Default point is #current_position.

An animation duration can also be specified. The default is 0.2 seconds.

Overloads:

  • #pinch(direction) ⇒ CGPoint

    Parameters:

    • direction (Symbol)

    Returns:

  • #pinch(direction, magnification) ⇒ CGPoint

    Parameters:

    • direction (Symbol)
    • magnification (Float)

    Returns:

  • #pinch(direction, magnification, point) ⇒ CGPoint

    Parameters:

    • direction (Symbol)
    • magnification (Float)
    • point (CGPoint, #to_point)

    Returns:

  • #pinch(direction, magnification, point, duration) ⇒ CGPoint

    Parameters:

    • direction (Symbol)
    • magnification (Float)
    • point (CGPoint, #to_point)
    • duration (Float)

    Returns:



841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
# File 'ext/mouse/mouse.c', line 841

static
VALUE
rb_mouse_pinch(const int argc, VALUE* const argv, UNUSED const VALUE self)
{
    if (!argc)
        rb_raise(rb_eArgError, "wrong number of arguments (%d for 1+)", argc);

    const VALUE input_direction = argv[0];
    CGPinchDirection  direction = kCGPinchNone;

    if (input_direction == sym_expand || input_direction == sym_zoom)
        direction = kCGPinchExpand;
    else if (input_direction == sym_contract || input_direction == sym_unzoom)
        direction = kCGPinchContract;
    else
        rb_raise(rb_eArgError,
                 "invalid pinch direction `%s'",
                 rb_id2name(SYM2ID(input_direction)));

    if (argc == 1) {
        mouse_pinch(direction);
        return CURRENT_POSITION;
    }

    const double magnification = NUM2DBL(argv[1]);
    if (argc == 2) {
        mouse_pinch2(direction, magnification);
        return CURRENT_POSITION;
    }

    const CGPoint point = rb_mouse_unwrap_point(argv[2]);
    if (argc == 3) {
        mouse_pinch3(direction, magnification, point);
        return CURRENT_POSITION;
    }

    const double duration = NUM2DBL(argv[3]);
    mouse_pinch4(direction, magnification, point, duration);
    return CURRENT_POSITION;
}

#rotate(direction, angle) ⇒ CGPoint #rotate(direction, angle, point) ⇒ CGPoint #rotate(direction, angle, point, duration) ⇒ CGPoint

Perform a rotation gesture in the given direction the given angle degrees

Possible directions are:

  • :cw, ':clockwise, ':clock_wise to rotate in the clockwise direction
  • :ccw, ':counter_clockwise,:counter_clock_wise` to rotate in the the counter clockwise direction

The angle parameter is a number of degrees to rotate. There are 360 degrees in a full rotation, as you would expect in Euclidian geometry.

You can also optionally specify a point on screen for the mouse pointer to be moved to before the gesture begins. The movement will be instantaneous. Default point is #current_position.

An animation duration can also be specified. The default is 0.2 seconds.

Overloads:

  • #rotate(direction, angle) ⇒ CGPoint

    Parameters:

    • direction (Symbol)
    • angle (Float)

    Returns:

  • #rotate(direction, angle, point) ⇒ CGPoint

    Parameters:

    • direction (Symbol)
    • angle (Float)
    • point (CGPoint)

    Returns:

  • #rotate(direction, angle, point, duration) ⇒ CGPoint

    Parameters:

    • direction (Symbol)
    • angle (Float)
    • point (CGPoint)
    • duration (Float)

    Returns:



917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
# File 'ext/mouse/mouse.c', line 917

static
VALUE
rb_mouse_rotate(const int argc, VALUE* const argv, UNUSED const VALUE self)
{
    if (argc < 2)
        rb_raise(rb_eArgError, "wrong number of arguments (%d for 2+)", argc);


    const VALUE input_dir = argv[0];
    CGRotateDirection direction = kCGRotateNone;

    if      (input_dir == sym_cw ||
             input_dir == sym_clockwise ||
             input_dir == sym_clock_wise)
        direction = kCGRotateClockwise;

    else if (input_dir == sym_ccw ||
             input_dir == sym_counter_clockwise ||
             input_dir == sym_counter_clock_wise)
        direction = kCGRotateCounterClockwise;
    else
        rb_raise(rb_eArgError,
                 "invalid rotation direction `%s'",
                 rb_id2name(SYM2ID(input_dir)));

    const double angle = NUM2DBL(argv[1]);

    if (argc == 2) {
        mouse_rotate(direction, angle);
        return CURRENT_POSITION;
    }

    const CGPoint point = rb_mouse_unwrap_point(argv[2]);
    if (argc == 3) {
        mouse_rotate2(direction, angle, point);
        return CURRENT_POSITION;
    }

    mouse_rotate3(direction, angle, point, NUM2DBL(argv[3]));
    return CURRENT_POSITION;
}

#scroll(amount) ⇒ Number #scroll(amount, units) ⇒ Number #scroll(amount, units, duration) ⇒ Number

Note:

Scrolling by :pixel may not actually be by real pixels, but instead correspond to Cocoa co-ords (I don't have a retina display, so I haven't checked it out yet).

Generate amount scroll events at the current cursor position

Returns number of lines/pixels scrolled, default units are by line. A positive amount will scroll up and a negative amount will scroll down.

An animation duration can also be specified, which defaults to 0.2 seconds.

Overloads:

  • #scroll(amount) ⇒ Number

    Parameters:

    • amount (Number)

    Returns:

    • (Number)
  • #scroll(amount, units) ⇒ Number

    Parameters:

    • amount (Number)
    • units (Symbol)

      :pixel or :line

    Returns:

    • (Number)
  • #scroll(amount, units, duration) ⇒ Number

    Parameters:

    • amount (Number)
    • units (Symbol)

      :pixel or :line

    • duration (Number)

      animation time, in seconds

    Returns:

    • (Number)


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
# File 'ext/mouse/mouse.c', line 134

static
VALUE
rb_mouse_scroll(const int argc, VALUE* const argv, UNUSED const VALUE self)
{
    if (argc == 0 || argc > 3)
        rb_raise(rb_eArgError,
                 "scroll requires 1..3 arguments, you gave %d",
                 argc);

    const int amt = NUM2INT(argv[0]);

    if (argc == 1) {
        mouse_scroll(amt);

    } else {
        const VALUE input_units = argv[1];
        CGScrollEventUnit units = kCGScrollEventUnitLine;

        if (input_units == sym_pixel)
            units = kCGScrollEventUnitPixel;
        else if (input_units == sym_line)
            units = kCGScrollEventUnitLine;
        else
            rb_raise(rb_eArgError,
                     "unknown units `%s'",
                     rb_id2name(SYM2ID(input_units)));

        if (argc == 2)
            mouse_scroll2(amt, units);
        else
            mouse_scroll3(amt, units, NUM2DBL(argv[2]));
    }

    return argv[0];
}

#secondary_clickCGPoint #secondary_click(point) ⇒ CGPoint Also known as: right_click

Generate a secondary click (both down and up events)

Secondary click is often referred to as "right click".

You can optionally specify a point to click; the mouse cursor will instantly jump to the given point; otherwise the click event happens at the current cursor position.

Overloads:



412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
# File 'ext/mouse/mouse.c', line 412

static
VALUE
rb_mouse_secondary_click(const int argc,
                         VALUE* const argv,
                         UNUSED const VALUE self)
{
    switch (argc) {
    case 0:
        mouse_secondary_click();
        break;
    case 1:
    default:
        mouse_secondary_click2(rb_mouse_unwrap_point(argv[0]));
    }

    return CURRENT_POSITION;
}

#secondary_click_downCGPoint #secondary_click_down(point) ⇒ CGPoint Also known as: right_click_down

Generate the down click part of a secondary/right click event

This might be useful in concert with secondary_click_up if you want to inject some behaviour between the down and up click events.

You can optionally specify a point to click; the mouse cursor will instantly jump to the given point; otherwise the click event happens at the current cursor position.

Overloads:



345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
# File 'ext/mouse/mouse.c', line 345

static
VALUE
rb_mouse_secondary_click_down(const int argc,
                              VALUE* const argv,
                              UNUSED const VALUE self)
{
    switch (argc) {
    case 0:
        mouse_secondary_click_down();
        break;
    case 1:
    default:
        mouse_secondary_click_down2(rb_mouse_unwrap_point(argv[0]));
    }

    return CURRENT_POSITION;
}

#secondary_click_upCGPoint #secondary_click_up(point) ⇒ CGPoint Also known as: right_click_up

Generate the up click part of a secondary/right click event

This might be useful in concert with secondary_click_down if you want to inject some behaviour between the down and up click events.

You can optionally specify a point to click; the mouse cursor will instantly jump to the given point; otherwise the click event happens at the current cursor position.

Overloads:



379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
# File 'ext/mouse/mouse.c', line 379

static
VALUE
rb_mouse_secondary_click_up(const int argc,
                            VALUE* const argv,
                            UNUSED const VALUE self)
{
    switch (argc) {
    case 0:
        mouse_secondary_click_up();
        break;
    case 1:
    default:
        mouse_secondary_click_up2(rb_mouse_unwrap_point(argv[0]));
    }

    return CURRENT_POSITION;
}

#smart_magnifyCGPoint #smart_magnify(point) ⇒ CGPoint Also known as: two_finger_double_tap

Perform a smart magnify (double tap on trackpad)

You can optionally specify a point to click; the mouse cursor will instantly jump to the given point; otherwise the click event happens at the current cursor position.

Overloads:



727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
# File 'ext/mouse/mouse.c', line 727

static
VALUE
rb_mouse_smart_magnify(const int argc,
                       VALUE* const argv,
                       UNUSED const VALUE self)
{
    switch (argc) {
    case 0:
        mouse_smart_magnify();
        break;
    case 1:
    default:
        mouse_smart_magnify2(rb_mouse_unwrap_point(argv[0]));
    }

    return CURRENT_POSITION;
}

#swipe(direction) ⇒ CGPoint #swipe(direction, point) ⇒ CGPoint #swipe(direction, point, duration) ⇒ CGPoint

Perform a swipe gesture in the given direction

You can optionally specify a point on screen for the mouse pointer to be moved to before the gesture begins. The movement will be instantaneous; otherwise the click event happens at the current cursor position.

You can also optionally specify the duration of the swipe event; the default duration is 0.2 seconds.

Overloads:

  • #swipe(direction) ⇒ CGPoint

    Parameters:

    • direction (Symbol)

    Returns:

  • #swipe(direction, point) ⇒ CGPoint

    Parameters:

    • direction (Symbol)
    • point (CGPoint)

    Returns:

  • #swipe(direction, point, duration) ⇒ CGPoint

    Parameters:

    • direction (Symbol)
    • point (CGPoint)
    • duration (Float)

    Returns:



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
796
797
798
799
# File 'ext/mouse/mouse.c', line 769

static
VALUE
rb_mouse_swipe(const int argc, VALUE* const argv, UNUSED const VALUE self)
{
    if (!argc)
        rb_raise(rb_eArgError, "wrong number of arguments (0 for 1+)");

    const VALUE direction_input = argv[0];
    CGSwipeDirection direction = kCGSwipeDirectionNone;
    if (direction_input == sym_up)
        direction = kCGSwipeDirectionUp;
    else if (direction_input == sym_down)
        direction = kCGSwipeDirectionDown;
    else if (direction_input == sym_left)
        direction = kCGSwipeDirectionLeft;
    else if (direction_input == sym_right)
        direction = kCGSwipeDirectionRight;
    else
        rb_raise(rb_eArgError,
                 "invalid swipe direction `%s'",
                 rb_id2name(SYM2ID(direction_input)));

    if (argc == 1) {
      mouse_swipe(direction);
      return CURRENT_POSITION;
    }

    const CGPoint point = rb_mouse_unwrap_point(argv[1]);
    mouse_swipe2(direction, point);
    return CURRENT_POSITION;
}

#triple_clickCGPoint #triple_click(point) ⇒ CGPoint

Perform a triple click at the given mouse position

Implemented by first generating a single click, then a double click, and finally a triple click. Apps seem to respond more consistently to this behaviour since that is how a human would have to generate a triple click event.

You can optionally specify a point to click; the mouse cursor will instantly jump to the given point; otherwise the click event happens at the current cursor position.

Overloads:



693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
# File 'ext/mouse/mouse.c', line 693

static
VALUE
rb_mouse_triple_click(const int argc,
                      VALUE* const argv,
                      UNUSED const VALUE self)
{
    switch (argc) {
    case 0:
        mouse_triple_click();
        break;
    case 1:
    default:
        mouse_triple_click2(rb_mouse_unwrap_point(argv[0]));
    }

    return CURRENT_POSITION;
}