Sha256: 00bda5cd21ac9da3daac88666c77b3ee322048d68a090e52cd0819be7f1d7321

Contents?: true

Size: 1.11 KB

Versions: 1

Compression:

Stored size: 1.11 KB

Contents

module MyScripts
  # This script prevents screen saver from locking down Windows by randomly moving
  # mouse pointer a bit every 4 minutes or so. Why would you need this? Well, if your
  # XP box is in a domain with security-crazy admins who have immutable policy of
  # forced screen saver after 5 minutes of inactivity you'd feel the pain...
  #
  class Wake < Script
    SLEEP_TIME = 4 * 60 # seconds

    def initialize( name, argv, cli )

      require 'win/gui/input'

      define_method :move_mouse_randomly do
        x, y = Win::Gui::Input::get_cursor_pos
        x1, y1 = x+rand(3)-1, y+rand(3)-1
        Win::Gui::Input::mouse_event(Win::Gui::Input::MOUSEEVENTF_ABSOLUTE, x1, y1, 0, 0)
        puts "Cursor positon set to #{x1}, #{y1}"
      end

      super
    end

    def run
      case @argv.size
        when 0
          sleep_time = SLEEP_TIME
        when 1
          sleep_time = @argv.first * 60
        else
          usage "[minutes] - prevents screen auto lock-up by moving mouse pointer every (4) [minutes]"
      end

      loop do
        move_mouse_randomly
        sleep sleep_time
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
my_scripts-0.0.17 lib/my_scripts/wake.rb