Libraries.Game.InputMonitor Documentation

The InputMonitor class can be used to test the state of the keyboard or mouse at any time. This will poll the input for its status.

Example Code

use Libraries.Game.InputMonitor
use Libraries.Game.Game
use Libraries.Interface.Events.KeyboardEvent

class Main is Game

    InputMonitor monitor
    KeyboardEvent keys

    action Main
        StartGame()
    end

    action Update(number time)
        if monitor:IsKeyPressed(keys:SPACE)
            output "The space bar is pressed!"
        end
    end

end

Inherits from: Libraries.Language.Object

Actions Documentation

Compare(Libraries.Language.Object object)

This action compares two object hash codes and returns an integer. The result is larger if this hash code is larger than the object passed as a parameter, smaller, or equal. In this case, -1 means smaller, 0 means equal, and 1 means larger. This action was changed in Quorum 7 to return an integer, instead of a CompareResult object, because the previous implementation was causing efficiency issues.

Parameters

Return

integer: The Compare result, Smaller, Equal, or Larger.

Example

Object o
Object t
integer result = o:Compare(t) //1 (larger), 0 (equal), or -1 (smaller)

Equals(Libraries.Language.Object object)

This action determines if two objects are equal based on their hash code values.

Parameters

Return

boolean: True if the hash codes are equal and false if they are not equal.

Example

use Libraries.Language.Object
use Libraries.Language.Types.Text
Object o
Text t
boolean result = o:Equals(t)

GetHashCode()

This action gets the hash code for an object.

Return

integer: The integer hash code of the object.

Example

Object o
integer hash = o:GetHashCode()

GetMouseX()

Returns the X coordinate of the mouse's location on the screen.

Return

integer:

Example

use Libraries.Game.InputMonitor
use Libraries.Game.Game
use Libraries.Interface.Events.MouseEvent

class Main is Game

    InputMonitor monitor
    MouseEvent mouseButtons

    action Main
        StartGame()
    end

    action Update(number time)
        if monitor:IsMouseButtonPressed(mouseButtons:LEFT)
            output "The mouse X coordinate is at " + monitor:GetMouseX()
        end
    end

end

GetMouseY()

Returns the Y coordinate of the mouse's location on the screen.

Return

integer:

Example

use Libraries.Game.InputMonitor
use Libraries.Game.Game
use Libraries.Interface.Events.MouseEvent

class Main is Game

    InputMonitor monitor
    MouseEvent mouseButtons

    action Main
        StartGame()
    end

    action Update(number time)
        if monitor:IsMouseButtonPressed(mouseButtons:LEFT)
            output "The mouse Y coordinate is at " + monitor:GetMouseY()
        end
    end

end

IsClicked()

Returns true if the left, right, or middle mouse button are held down.

Return

boolean:

Example

use Libraries.Game.InputMonitor
use Libraries.Game.Game

class Main is Game

    InputMonitor monitor

    action Main
        StartGame()
    end

    action Update(number time)
        if monitor:IsClicked()
            output "A mouse button is held down!"
        end
    end

end

IsKeyPressed(integer keyCode)

This action will test if the given key is currently pressed down on the keyboard. To select which key to test, use the constants from the KeyboardEvent class.

Parameters

  • integer keyCode

Return

boolean:

Example

use Libraries.Game.InputMonitor
use Libraries.Game.Game
use Libraries.Interface.Events.KeyboardEvent

class Main is Game

    InputMonitor monitor
    KeyboardEvent keys

    action Main
        StartGame()
    end

    action Update(number time)
        if monitor:IsKeyPressed(keys:SPACE)
            output "The space bar is pressed!"
        end
    end

end

IsMouseButtonPressed(integer buttonCode)

This will test if a particular button is pressed on the mouse. Use the constants from the MouseEvent class to test the buttons.

Parameters

  • integer buttonCode

Return

boolean:

Example

use Libraries.Game.InputMonitor
use Libraries.Game.Game
use Libraries.Interface.Events.MouseEvent

class Main is Game

    InputMonitor monitor
    MouseEvent mouseButtons

    action Main
        StartGame()
    end

    action Update(number time)
        if monitor:IsMouseButtonPressed(mouseButtons:LEFT)
            output "The left mouse button is pressed!"
        end
    end

end

IsScrolled()

Checks if the mouse scroll wheel has been moved. If the wheel is scrolled up, the integer will be positive. If it has been scrolled down, it will be negative.

Return

integer:

Example

use Libraries.Game.InputMonitor
use Libraries.Game.Game

class Main is Game

    InputMonitor monitor

    action Main
        StartGame()
    end

    action Update(number time)
        integer scrollAmount = monitor:IsScrolled()
        if scrollAmount not= 0
            output "The scroll bar moved " + scrollAmount + " units!"
        end
    end

end

ItemIsClicked(Libraries.Interface.Item2D item, integer button)

This action will test to see if the given Item was clicked on the last frame using the given button. To choose the button value, use the constants from the MouseEvent class.

Parameters

Return

boolean:

Example

use Libraries.Game.InputMonitor
use Libraries.Game.Game
use Libraries.Interface.Item
use Libraries.Interface.Events.MouseEvent

class Main is Game

    InputMonitor monitor
    Item item
    MouseEvent mouseButtons

    action Main
        StartGame()
    end

    action CreateGame
        item:SetPosition(100, 100)
        item:SetWidth(300)
        item:SetHeight(300)
    end

    action Update(number time)
        if ItemIsClicked(item, mouseButtons:LEFT)
            output "The item is clicked with the left mouse button!"
        end
    end

end

ItemIsClicked(Libraries.Interface.Item2D item)

This action will test to see if the given Item is being clicked.

Parameters

Return

boolean:

Example

use Libraries.Game.InputMonitor
use Libraries.Game.Game
use Libraries.Interface.Item

class Main is Game

    InputMonitor monitor
    Item item

    action Main
        StartGame()
    end

    action CreateGame
        item:SetPosition(100, 100)
        item:SetWidth(300)
        item:SetHeight(300)
    end

    action Update(number time)
        if ItemIsClicked(item)
            output "The item is clicked!"
        end
    end

end

NumberOfKeysPressed()

This action returns the number of keys that are currently pressed on the keyboard.

Return

integer: The number of keys that are pressed.

Example

use Libraries.Game.Game
use Libraries.Game.InputMonitor

class Main is Game

    InputMonitor monitor

    action Main
        StartGame()
    end

    action Update(number seconds)
        integer keys = monitor:NumberOfKeysPressed()
        if keys > 0
            output keys + " keys are pressed."
        end
    end
end