$mouse

From Scriptwiki
Revision as of 08:55, 31 January 2007 by Cail (talk | contribs) (added category)

Jump to: navigation, search

$mouse
Properties: win, x, y, mx, my, dx, dy, key, lb

Returns the x, y position of the current mouse event, and whether the left mouse button, shift key, and/or control key are pressed. The $mouse identifier can be used in the mouse/click events.

For $mouse.key you can use the & bitwise operator to check if the left button, shift key, and/or control key are pressed:

if ($mouse.key & 1) echo left button is pressed.
if ($mouse.key & 2) echo control key is pressed.
if ($mouse.key & 4) echo shift key is pressed.
if ($mouse.key & 8) echo alt key is pressed.
if ($mouse.key & 16) echo right mouse button is pressed.

Properties:

.win     property returns the name of the active window.
.x/.y    returns mouse x- and y-coordinates relative to active window
.mx/.my  returns mouse x- and y-coordinates relative to mirc window
.dx/.dy  returns mouse x- and y-coordinates relative to desktop
.lb      property returns $true if a mouse event occurred over a listbox, or $false if it didn't.

Example:

; First we'll need to create a picture window from editbox:
; -p means it's a picture window, first @test is the name of the window, the second @test is the name of the popupfile 
; (we'll use the window's name so we can use the menu prefix in remote script)
/window -p @test @test

; the menu for our @test window
menu @test {
  ; "mouse" triggers whenever mouse moves in the window, and executes draw alias
  mouse:draw

  ; "dclick" triggers whenever user doubleclicks in the window, we'll use this to clear the window
  dclick:clear @test
}

; this is the alias that is executed everytime mouse moves in @test window
alias draw { 
  ; an if to check if left mouse button is pressed, if so draw a dot into the window with colorcode 4, size 2px, 
  ; and read the X and Y location for the dot from $mouse.x and $mouse.y
  if ($mouse.key & 1) { drawdot @test 4 2 $mouse.x $mouse.y } 

  ; else if left mouse button wasn't pressed, see if right mouse button was
  ; we'll do the drawdot like earlier, but use background color as the color (erase) and make it a bit bigger
  elseif ($mouse.key & 16) { drawdot @test $color(background) 6 $mouse.x $mouse.y }
}