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

Summary

Actions Summary Table

ActionsDescription
Compare(Libraries.Language.Object object)This action compares two object hash codes and returns a CompareResult.
Equals(Libraries.Language.Object object)This action determines if two objects are equal based on their hash code values.
GetHashCode()This action gets the hash code for an object.
GetMouseX()Returns the X coordinate of the mouse's location on the screen.
GetMouseY()Returns the Y coordinate of the mouse's location on the screen.
IsClicked()Returns true if the left, right, or middle mouse button are held down.
IsKeyPressed(integer keyCode)This action will test if the given key is currently pressed down on the keyboard.
IsMouseButtonPressed(integer buttonCode)This will test if a particular button is pressed on the mouse.
IsScrolled()Checks if the mouse scroll wheel has been moved.
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.
ItemIsClicked(Libraries.Interface.Item2D item)This action will test to see if the given Item is being clicked.
NumberOfKeysPressed()This action returns the number of keys that are currently pressed on the keyboard.

Actions Documentation

Compare(Libraries.Language.Object object)

This action compares two object hash codes and returns a CompareResult. The compare result is either larger if this hash code is larger than the object passed as a parameter, smaller, or equal.

Example Code

use Libraries.Language.Support.CompareResult
        Object o
        Object t
        CompareResult result = o:Compare(t)

Parameters

Return

Libraries.Language.Support.CompareResult: The Compare result, Smaller, Equal, or Larger.

Equals(Libraries.Language.Object object)

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

Example Code

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

Parameters

Return

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

GetHashCode()

This action gets the hash code for an object.

Example Code

Object o
        integer hash = o:GetHashCode()

Return

integer: The integer hash code of the object.

GetMouseX()

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

Example Code

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

Return

integer:

GetMouseY()

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

Example Code

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

Return

integer:

IsClicked()

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

Example Code

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

Return

boolean:

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.

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

Parameters

Return

boolean:

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.

Example Code

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

Parameters

Return

boolean:

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.

Example Code

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

Return

integer:

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.

Example Code

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

Parameters

Return

boolean:

ItemIsClicked(Libraries.Interface.Item2D item)

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

Example Code

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

Parameters

Return

boolean:

NumberOfKeysPressed()

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

Example Code

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

Return

integer: The number of keys that are pressed.