Forum: Ruby Convert string to int and use it on auto_click

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
B108916be03f8a27b45bb94ca26648d2?d=identicon&s=25 cynic limbu (cyniclimbu)
on 2014-02-19 09:11
auto_click is a gem pretty much used for manipulating keyboard/mouse via
ruby script.

The command below will take the mouse's cursor to the given co-ordinates
mouse_move(100,100) #100,100 is the x and y coordinates (maybe?)

if you do
mouse_move(0,0) the cursor will go to the top-left corner of the screen

Now I want to pass the co-ordinates via a variable
So far, I haven't found any smart way to do it.
Let's look what irb thinks of it below.

DL is deprecated, please use Fiddle
irb(main):001:0> require 'auto_click'
=> true
irb(main):002:0> coordinate = "100,100"
=> "100,100"
irb(main):003:0> mouse_move("#{coordinate}")
ArgumentError: wrong number of arguments (1 for 2)
        from
C:/Ruby200/lib/ruby/gems/2.0.0/gems/auto_click-0.2.0/lib/auto_click
.rb:21:in `mouse_move'
        from (irb):3
        from C:/Ruby200/bin/irb:12:in `<main>'
irb(main):004:0>


UPDATE:

DL is deprecated, please use Fiddle
irb(main):001:0> require 'auto_click'
=> true
irb(main):002:0> x = 0
=> 0
irb(main):003:0> y = 0
=> 0
irb(main):004:0> mouse_move(x,y)
=> 1
irb(main):005:0>

I tried the above way and it worked, Only question now is shall I delete
this topic?
E088bb5c80fd3c4fd02c2020cdacbaf0?d=identicon&s=25 Jesús Gabriel y Galán (Guest)
on 2014-02-19 09:54
(Received via mailing list)
On Wed, Feb 19, 2014 at 9:11 AM, cynic limbu <lists@ruby-forum.com>
wrote:
> So far, I haven't found any smart way to do it.
> C:/Ruby200/lib/ruby/gems/2.0.0/gems/auto_click-0.2.0/lib/auto_click
> .rb:21:in `mouse_move'
>         from (irb):3
>         from C:/Ruby200/bin/irb:12:in `<main>'
> irb(main):004:0>

If I understand correctly, you need to convert the string "100,100" to
two ints to be passed to a method?
If that's the case, then:

coordinate = "100,100"
numbers = coordinate.split(",").map{|x| x.to_i}
mouse_move(*numbers)

should work.

Jesus.
B108916be03f8a27b45bb94ca26648d2?d=identicon&s=25 cynic limbu (cyniclimbu)
on 2014-02-19 09:59
> Jesus.

Thank you, God :P

Although I found an alternative solution I shall try yours.
This topic is locked and can not be replied to.