FLmouse
Prev | Orchestra Opcodes and Operators | Next

## FLmouse

FLmouse — Returns the mouse position and the state of the three mouse buttons.

## Description

FLmouse returns the coordinates of the mouse position within an FLTK panel and the state of the three mouse buttons.

## Syntax

    kx, ky, kb1, kb2, kb3 FLmouse [imode]

## Initialization

imode – (optional, default = 0) Determines the mode for mouse location reporting.

- 0 - Absolute position normalized to range 0-1

- 1 - Absolute raw pixel position

- 2 - Raw pixel position, relative to FLTK panel

## Performance

kx, ky – the mouse coordinates, whose range depends on the imode argument (see above).

kb1, kb2, kb3 – the states of the mouse buttons, 1 when corresponding button is pressed, 0 when the button is not pressed.

FLmouse returns the coordinates of the mouse position and the state of the three mouse buttons. The coordinates can be retrieved in three modes depending on the imode argument value (see above). Modes 0 and 1 report mouse position in relation to the complete screen (Absolute mode), while mode 2, reports the pixel position within an FLTK panel. Notice that FLmouse is only active when the mouse cursor passes on an FLpanel area.

## Examples

Here is an example of the FLmouse opcode. It uses the file FLmouse.csd.

Example 285. Example of the FLmouse opcode.

See the sections Real-time Audio and Command Line Flags for more information on using command line flags.

    <CsoundSynthesizer>
    <CsOptions>
    ; Select audio/midi flags here according to platform
    ; Audio out   Audio in    No messages
    -odac           -iadc     -d     ;;;RT audio I/O
    </CsOptions>
    <CsInstruments>

    sr=44100
    ksmps=128
    nchnls=2

    ;Example by Andres Cabrera 2007
    giwidth = 400
    giheight = 300
    FLpanel "FLmouse", giwidth, giheight, 10, 10
    FLpanelEnd

    FLrun

    0dbfs = 1

    instr 1
      kx, ky, kb1, kb2, kb3    FLmouse 2
      ktrig changed kx, ky  ;Print only if coordinates have changed
      printf "kx = %f   ky = %f \n", ktrig, kx, ky
    kfreq = ((giwidth - ky)*1000/giwidth) + 300

    ; y coordinate determines frequency, x coordinate determines amplitude
    ; Left mouse button (kb1) doubles the frequency
    ; Right mouse button (kb3) activates sound on channel 2
      aout oscil kx /giwidth , kfreq * (kb1 + 1), 1
      outs aout, aout * kb3
    endin

    </CsInstruments>
    <CsScore>
    f 1 0 1024 10 1

    i 1 0 120
    e

    </CsScore>
    </CsoundSynthesizer>

## Credits

Author: Gabriel Maldonado

New in version 5.06

Prev | Up | Next
FLloadsnap | Home | flooper