Giter Club home page Giter Club logo

auto_click's Introduction

AutoClick

Smulating mouse click, cursor movement and keystrokes

Install

To install auto_click:

gem install auto_click

To update auto_click:

gem update auto_click

Basic Usage

Using auto_click is easy. To use the methods provided by auto_click. You need to require the gem and include the module:

require 'auto_click'
include AutoClickMethods

To move the mouse cursor to 50,50 ( the top left corner is 0,0) and perform a double left click:

mouse_move(50,50)
double_click

To move the mouse cursor to 50,50 and perform a right click:

mouse_move(50,50)
right_click

To move the mouse cursor to the middle of the screen:

mouse_move_percentage(0.5,0.5)

To scroll up (forward) 10 wheel steps:

mouse_scroll(10)

To scroll down (backward) 5 wheel steps:

mouse_scroll(-5)

To get the current cursor position

cursor_position

To drag the icon on (50,50) to (200,300):

left_drag(50,50,200,300)

Suppose the notepad window on the top left corner of the screen, to type “Auto Click” in notepad. (Methods like get_windows(“notepad”) will be implemented in future release. So that you do not need to use this left click things to get focus on the notepad window.…..in later release.…..)

mouse_move(100,100)
leftclick
type('Auto Click!')

The type method will Send keystroke for every characters of the string. It will ensure that the capslock is off and hold shift when it is typing a capital character or a character that need shift down (e.g. ‘!’). Notice that you need to escape the character \ and ‘ in single quote string, and you need to escape \ “ and # in double quote string. For example, to type #”\ , you can either do:

type('#\'\'\\')

or

type("\#''\\")

Advanced Usage

The methods shown in Basic Usage are convenient, but sometimes you may need more control on your mouse actions and key strokes.

To show the current cursor x and y position in pixels:

puts cursor_position[0]
puts cursor_position[1]

To move the mouse cursor downward 300 pixels

mouse_move(cursor_position[0]+300,cursor_position[1])

Yes this is not very efficient but mouse_move_relative methods will be implemented in later releases.

If you wish to left click and hold:

mouse_down(:left)

And remember to release the button later:

mouse_up(:left)

To perform a double_click, instead of using:

double_click

You can use two click calls:

left_click
left_click

And of course if for some reasons you need double middle mouse click, you can:

middle_click
middle_click

For get more refined control to key strokes simulation, you can use the method key_stroke, key_up and key_down methods

To send keystroke ‘a’:

key_stroke('a')

To send keystroke tab:

key_stroke('tab')

Therefore, to type “Auto Click!” , you can either use the simple type method stated basic usage section, or you can do:

key_down('shift')        
key_stroke('a')  
key_up('shift')
key_stroke('u')
key_stroke('t')
key_stroke('o')
key_stroke('space')
key_down('shift')
key_stroke('c')
key_up('shift')
key_stroke('l')
key_stroke('i')
key_stroke('c')
key_stroke('k')
key_down('shift')
key_stroke('num1')
key_up('shift')

And you can have detail adjustments to the keyboard behaviour that you need.

Notice that ‘a’ means the key ‘a’ instead of the letter ‘a’. Therefore key_stroke(‘a’) and key_stroke(‘A’) are basically the same. If the capslock is off but you want to type the capitalized A, you need to:

key_down('shift')        
key_stroke('a')  
key_up('shift')

A list of key stroke names will be included in the readme later. ‘a’ to ‘z’, ‘num0’ to ‘num9’, ‘f1’ to ‘f12’, ‘shift’ ‘ctrl’ ‘alt’ ‘win’ ‘tab’ ‘del’ ‘ins’ ‘return’ ‘esc’ ‘pageup’ ‘pagedown’ ‘left’ ‘right’ ‘up’ ‘down’ ‘equal’ ‘hyphen’.…..etc are all acceptable key names. I am trying to cater a certain number of name variations, for example:

key_stroke('left') 
key_stroke('leftarrow')
key_stroke('leftkey')

will do the same thing.

If you know the virtual key code you can directly enter the key code, for example:

key_stroke(0x41)

is the same as

key_stroke('a')

The list of virtual key codes can be found at msdn.microsoft.com/en-us/library/dd375731(v=vs.85).aspx

There are some methods which are not discussed here. Please see the following Method List for all the available methods.

Namespace

If you do not want include the auto_click methods, instead of using

include AutoClickMethods

you can construct a new instance of AutoClick and invoke the methods from the instance:

ac = AutoClick.new()
ac.mouse_move(50,50)

Method List

  • left_click

  • right_click

  • middle_click

  • double_click

  • mouse_down(button_name)

  • mouse_up(button_name)

  • cursor_position

  • mouse_move(x,y)

  • mouse_move_percentage(x_percent,y_percent)

  • mouse_scroll(step)

  • left_drag(x_start,y_start,x_end,y_end)

  • right_drag(x_start,y_start,x_end,y_end)

  • type(string)

  • key_stroke(key_name)

  • key_down(key_name)

  • key_up(key_name)

To Do List

  • Backward compatibility with 32-bit Ruby

  • Add options of movement speed of mouse so the cursor is actually “moving” instead of just show up at the destination instantly

  • GetWindow and GetWindowFocus Method

  • Refactor the ugly type(string) method

  • Use code block to implement modifier keys

  • More effective way to move mouse relative to current position

Change log

(for full change log please refer to the CHANGELOG file in the repository)

  • 0.5.0 Users have to explicitly use “include AutoClickMethods” to include the methods, add mouse_move_percentage and get_screen_resolution

  • 0.4.0 Fix the 64bit bug and Fixnum! bug

  • 0.3.0 Update to use DL Library

License

MIT license

Copyright © 2010-2019 by Chungsang Tom Lam

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

auto_click's People

Contributors

brianpurgert avatar erinata avatar kojix2 avatar m1kal avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

auto_click's Issues

user32: cannot open shared object file: No such file or directory (Fiddle::DLError)

Hey!

I'm trying to add this library to a small project I have and I'm having the following error when I try to run it:

/home/grun/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/fiddle-1.1.0/lib/fiddle.rb:61:in `initialize': user32: cannot open shared object file: No such file or directory (Fiddle::DLError)
        from /home/grun/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/fiddle-1.1.0/lib/fiddle.rb:61:in `new'
        from /home/grun/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/fiddle-1.1.0/lib/fiddle.rb:61:in `dlopen'
        from /home/grun/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/fiddle-1.1.0/lib/fiddle/import.rb:86:in `block in dlload'
        from /home/grun/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/fiddle-1.1.0/lib/fiddle/import.rb:77:in `collect'
        from /home/grun/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/fiddle-1.1.0/lib/fiddle/import.rb:77:in `dlload'
        from /home/grun/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/auto_click-0.5.9/lib/auto_click/user32.rb:3:in `<module:User32>'
        from /home/grun/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/auto_click-0.5.9/lib/auto_click/user32.rb:1:in `<top (required)>'
        from <internal:/home/grun/.rbenv/versions/3.0.1/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
        from <internal:/home/grun/.rbenv/versions/3.0.1/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
        from /home/grun/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/auto_click-0.5.9/lib/auto_click.rb:4:in `<top (required)>'
        from <internal:/home/grun/.rbenv/versions/3.0.1/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:160:in `require'
        from <internal:/home/grun/.rbenv/versions/3.0.1/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:160:in `rescue in require'
        from <internal:/home/grun/.rbenv/versions/3.0.1/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:149:in `require'
        from lib/main.rb:5:in `<main>'
<internal:/home/grun/.rbenv/versions/3.0.1/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require': cannot load such file -- auto_click (LoadError)
        from <internal:/home/grun/.rbenv/versions/3.0.1/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
        from lib/main.rb:5:in `<main>'

It's a pure ruby project with very few dependencies.
Here's my Gemfile and Gemfile.lock:

source 'https://rubygems.org'

gem 'pry'
gem 'auto_click'
gem 'watir'
gem 'fiddle'
GEM
  remote: https://rubygems.org/
  specs:
    auto_click (0.5.9)
    childprocess (4.1.0)
    coderay (1.1.3)
    fiddle (1.1.0)
    method_source (1.0.0)
    pry (0.14.1)
      coderay (~> 1.1)
      method_source (~> 1.0)
    regexp_parser (2.2.0)
    rexml (3.2.5)
    rubyzip (2.3.2)
    selenium-webdriver (4.1.0)
      childprocess (>= 0.5, < 5.0)
      rexml (~> 3.2, >= 3.2.5)
      rubyzip (>= 1.2.2)
    watir (7.1.0)
      regexp_parser (>= 1.2, < 3)
      selenium-webdriver (~> 4.0)

PLATFORMS
  ruby

DEPENDENCIES
  auto_click
  fiddle
  pry
  watir

BUNDLED WITH
   2.2.15

Any ideas of what it might be?

Auto click is not getting installed

Hi, I have installed ruby (version 2.0) and while trying to install the 'auto click' gem(in windows 7 and windows 10), I get the following error:-
ERROR: Could not find a valid gem 'auto' (>= 0), here is why:
Unable to download data from https://rubygems.org/ - SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed (https://rubygems.org/latest_specs.4.8.gz)
ERROR: Could not find a valid gem 'click' (>= 0), here is why:
Unable to download data from https://rubygems.org/ - SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed (https://rubygems.org/latest_specs.4.8.gz)

SendInput dont work

Hello, erinata!
I know, auto_click project is too old, but if you can, please, help me :).
I'm trying to use "type" and "key_stroke" methods, but no one is not working: no errors, no messages. Simply, no action.
After the seeking in source code, i'm find what they based on SendInput method.
Perhaps, this is depending of operating system and Ruby version? My current config:
Windows 7 x64 SP1 Corporate, ruby 2.0.0p481 (2014-05-08) [x64-mingw32]

unable to install auto_click

I keep getting -
ERROR: While executing gem ... (ArgumentError)
undefined class/module YAML::PrivateType
on an attempt to "gem install auto_click"

I uninstalled ruby (ver 1.9.2) and a bunch of other gems. Successfully re-installed gems after re-installing ruby1.9.2. But all attemprts to "gem install auto_click" as per the instructions of the wiki resulted in -

ERROR: While executing gem ... (ArgumentError)
undefined class/module YAML::PrivateType

Any help will be appreciated. Thanks!

Fixnum! nomethoderror on ruby 2.3.x

Hello, I am having an issue when i am passing a string into method type.

the error i get is
undefined method Fixnum!' for VirtualKey:Module (NoMethodError)`

I am using ruby 2.3.1 with plans to upgrade to 2.4.x soon.

Was curious why Fixnum! was written. and if there were any plans to upgrade the gem for ruby compatibility.

Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.