Skip to content

Instantly share code, notes, and snippets.

@smison
Last active August 29, 2015 14:17
Show Gist options
  • Save smison/240026c8d578e7b16ea1 to your computer and use it in GitHub Desktop.
Save smison/240026c8d578e7b16ea1 to your computer and use it in GitHub Desktop.
自動カケアミスクリプト(http://qiita.com/smison/items/3a7bcf7a31ebd8876b06)
require 'auto_click'
### parameter
line_length = 90 # カケアミ一本あたりの長さ
interval_x = 5 # カケアミ間の幅(x軸)
interval_y = 3 # カケアミ間の幅(y軸)
times_x = 125 # x軸方向に何本線を引くか
times_y = 5 # y軸方向に何本線を引くか
start_point_x = 50 # 始点(x軸)
start_point_y = 300 # 始点(y軸)
### module_ext
module AutoClick
def draw_vertical_line(start_point_x, start_point_y, line_length)
tmp_x = start_point_x
tmp_y = start_point_y
(0..(line_length - 1)).each do |i|
send_input( [@@leftdown] )
mouse_move tmp_x, tmp_y
tmp_y += 1
send_input( [@@leftup] )
end
sleep 0.3 # tegaki_dtでカケアミを綺麗に描画するのに必要
end
def draw_vertical_kakeami(start_point_x, start_point_y,
line_length, interval_x, interval_y,
times_x, times_y)
start_point_x_init = start_point_x
start_point_y_init = start_point_y
# 始点でウィンドウをアクティブにして少し待つ
mouse_move start_point_x, start_point_y
send_input( [@@leftdown] )
send_input( [@@leftup] )
sleep 0.3
(0..(times_y - 1)).each do |i|
(0..(times_x - 1)).each do |j|
draw_vertical_line(start_point_x,
start_point_y,
line_length)
start_point_x += interval_x
end
start_point_x = start_point_x_init
start_point_y += line_length + interval_y
end
end
end
### main
draw_vertical_kakeami(start_point_x, start_point_y,
line_length, interval_x, interval_y,
times_x, times_y)
# 参考文献
# https://github.com/erinata/auto_click
@smison
Copy link
Author

smison commented Mar 20, 2015

手書きっぽく揺らすなら下記のように定義すればよい

  def draw_vertical_line(sx, sy, line_length)
    tx = sx
    ty = sy

    tx += [-1, -1, -1, 1, 1, 1, 0].sample
    ty += [-1, -1, -1, 1, 1, 1, 0].sample

    (0..(line_length - 1)).each do |i|
      send_input( [@@leftdown] )
      mouse_move tx, ty
      tx += [-1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0].sample
      ty += [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0].sample
      send_input( [@@leftup] )
    end
    sleep 0.3 # tegaki_dtでカケアミを綺麗に描画するのに必要
  end

@smison
Copy link
Author

smison commented Mar 20, 2015

なぜinterval, timesをキャンバスサイズから算出しないか、というと、window位置を自動で取得していないので始点が厳密に取れないため。ひとまず使えればいいので、window位置の取得はfuture workとします。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment