Convert string to int and use it on auto_click

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
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?

On Wed, Feb 19, 2014 at 9:11 AM, cynic limbu [email protected]
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
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.

Jesus.

Thank you, God :stuck_out_tongue:

Although I found an alternative solution I shall try yours.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs