How to show mouse cursor in game display?

Joined
Jan 22, 2019
Messages
3
Reaction score
0
First Language
portuguese
Primarily Uses
RMVXA
Hello,
Im using this mouse module in my project:

Code:
module Mouse
  # Declarações de API
  GAME_WINDOW = Win32API.new("user32", "GetActiveWindow",  "v",  "l").call
  GET_RECT    = Win32API.new("user32", "GetWindowRect",    "lp", "l")
  CUR_POS     = Win32API.new("user32", "GetCursorPos",     "p",  "l")
  GET_CLICK   = Win32API.new("user32", "GetAsyncKeyState", "l",  "l")
 
  # Constantes
  LEFT    = 1
  RIGHT   = 2
  SCROLL  = 4
  BUTTON4 = 5
  BUTTON5 = 6
 
  # Auxiliar
  @state  = {LEFT => 0, RIGHT => 0, SCROLL => 0, BUTTON4 => 0, BUTTON5 => 0}
 
  # Métodos
  module_function
 
  # Atualização
  def update
    @state.each{|key, value|
      @state[key] = (GET_CLICK.call(key) != 0 ? @state[key] + 1 : 0)
      @state[key] = 15 if @state[key] == 17
    }
  end
 
  # Método para posição em relação à janela
  def pos
    buffer = [[0,0].pack("l*"), [0,0].pack("l*")]
  
    GET_RECT.call(GAME_WINDOW, buffer[0])
    CUR_POS.call(buffer[1])
  
    return buffer[1].unpack("l*").zip(buffer[0].unpack("l*")).map{|a, b| a - b}
  end
 
  def x
    return self.pos[0] - 2
  end
 
  def y
    return self.pos[1] - 23
  end
 
  def in_area?(ix, iy, lx, ly)
    return true if self.x >= ix  and self.x <= lx and self.y >= iy and self.y <= ly
    return false
  end
 
  # Click único
  def click?(button = LEFT)
    return @state[button] == 1
  end
 
  # Pressionado
  def press?(button = LEFT)
    return @state[button] > 0
  end
 
  # Repetindo
  def repeat?(button = LEFT)
    return @state[button] == 1 || @state[button] == 16
  end
end
=begin
class << Mouse
  show_cursor = Win32API.new('user32', 'ShowCursor', 'l', 'l')
  show_cursor.call(0)

  $mousec = Sprite.new
  $mousec.z = 10001
  $mousec.x = $mousec.y = 1000
  $mouse_icon = 'mecha_icon'
  $mousec.bitmap = Script.cache($mouse_icon)
 
  alias wor_mouse_upd_mouse update unless $@
  def Mouse.update
    wor_mouse_upd_mouse
    if $mouse_old_icon.nil? or $mouse_old_icon != $mouse_icon
      $mouse_old_icon = $mouse_icon
      $mousec.bitmap = Script.cache($mouse_old_icon)
    end
    if self.pos.nil? or self.pos.empty?
      $mousec.x = 1000 if $mousec.x != 1000
      $mousec.y = 1000 if $mousec.y != 1000
    else
      $mousec.x = self.x if $mousec.x != self.x
      $mousec.y = self.y if $mousec.y != self.y
    end
  end
end
=end
But if I play the game in full screen (alt+enter) the mouse cursor just disappear. How can I make the cursor being visible?
 

KK20

Just some XP Scripter
Veteran
Joined
Oct 11, 2018
Messages
110
Reaction score
49
First Language
English
Primarily Uses
RMXP
The commented out section at the bottom of the script (which draws a sprite where the mouse cursor is at) is the only guaranteed way. Using the system's default mouse cursor does not work as the Game.exe is built to hide the cursor after a second of inactivity. I've tried looking into this more by observing Window Messages and repeatedly calling ShowCursor(true), but I never came to a solution. You would have to build your own Game.exe I believe.
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Profile Posts

Oh, stop with the Melodrama...

...Listen to it instead!

anybody else like getting baked whilst coding?

When you go to the beach watch out for coconuts. Coconuts are more dangerous than sharks. Fact.
Try to get into pixelart again, so far its a sucess.
Also finally found a useful pixeltutorial which helps a lot.
♫ Anyone knows an ant can't move a rubber tree plant, but he's got high hopes, he's got high hopes, he's got high apple pie in the sky hopes ♫

Forum statistics

Threads
93,616
Messages
913,989
Members
123,182
Latest member
SaberRoy
Top