Save-Point
Mouse - Printable Version

+- Save-Point (https://www.save-point.org)
+-- Forum: Archives (https://www.save-point.org/forum-105.html)
+--- Forum: Creation Asylum Archives (https://www.save-point.org/forum-90.html)
+---- Forum: Scripts & Code Snippets (https://www.save-point.org/forum-92.html)
+----- Forum: RPG Maker XP Code (https://www.save-point.org/forum-93.html)
+------ Forum: New Functionality/Features Scripts (https://www.save-point.org/forum-99.html)
+------ Thread: Mouse (/thread-6700.html)



Mouse - corbaque - 08-30-2007

Mouse
by Corbaque
Aug 30 2007

This is a locked, single-post thread from Creation Asylum. Archived here to prevent its loss.
No support is given. If you are the owner of the thread, please contact administration.


Hello all :P

Would you like to make a joke to players ?
The mouse is in life !!! O_O !!!

Add this script before main, named it "Mouse" :

Code:
#===================================
# Mouse
#---------------------------------------------------------------
# Created by Corbaque
#===================================
class Mouse < Sprite
  # Game screen
  Win = Win32API.new('user32', 'FindWindowA', %w(p p), 'i').call('RGSS Player', nil)
  # Adapt cursor to client
  Scr2cli = Win32API.new('user32', 'ScreenToClient', %w(l p), 'i')
  # Get cursor pos
  Pos = Win32API.new('user32', 'GetCursorPos', 'p', 'i')
  # Set cursor pos
  Set = Win32API.new('user32','SetCursorPos','ii','i')
  #-------------------------------------------------------------
  # Update
  #-------------------------------------------------------------
  def Mouse.update
    # Get cursor position
    pos = [0, 0].pack('ll'); Pos.call(pos)
    # Update in game cursor
    $cursor.x, $cursor.y = pos.unpack('ll') if Scr2cli.call(Win, pos) != 0
  end
  #-------------------------------------------------------------
  # Set cursor pos
  #-------------------------------------------------------------
  def set(x, y)
    # Adapt position to the game screen
    pos = [0, 0].pack('ll'); Scr2cli.call(Win, pos)
    # Set Position
    a, b = pos.unpack('ll'); Set.call(x-a, y-b)
  end
end
$cursor = Mouse.new


How to use ?
To update the cursor position :
Code:
Mouse.update


To set a new position (not only on the game !! ^^)
Code:
Mouse.set(x, y)

(Mouse.set(0, 0) put cursor at the top left of game screen)

The cursor is the $cursor sprite.
You can add a bitmap if you want :P

And it's all =)