package ocaml-canvas

  1. Overview
  2. Docs

Event descriptions

All event descriptions contain the canvas on which the event occured and the timestamp indicating when the event occured.

type timestamp = Stdlib.Int64.t

Timestamps represent the time in microseconds, from an arbitrary starting point

type 'a canvas_event = {
  1. canvas : Canvas.t;
  2. timestamp : timestamp;
  3. data : 'a;
}

Generic description of events occurring on canvases

type position = int * int

A position is a pair of integers

type size = int * int

A size is a pair of integers

type key =
  1. | KeyEscape
  2. | KeyF1
  3. | KeyF2
  4. | KeyF3
  5. | KeyF4
  6. | KeyF5
  7. | KeyF6
  8. | KeyF7
  9. | KeyF8
  10. | KeyF9
  11. | KeyF10
  12. | KeyF11
  13. | KeyF12
  14. | KeyPrintScreen
    (*

    absent from Mac Keyboards

    *)
  15. | KeyScrollLock
    (*

    absent from Mac Keyboards

    *)
  16. | KeyPause
    (*

    absent from Mac Keyboards

    *)
  17. | KeyGraveTilde
  18. | Key1Exclamation
  19. | Key2At
  20. | Key3Number
  21. | Key4Dollar
  22. | Key5Percent
  23. | Key6Caret
  24. | Key7Ampersand
  25. | Key8Asterisk
  26. | Key9LParenthesis
  27. | Key0RParenthesis
  28. | KeyMinusUndersclre
  29. | KeyEqualPlus
  30. | KeyBackspace
  31. | KeyTab
  32. | KeyQ
  33. | KeyW
  34. | KeyE
  35. | KeyR
  36. | KeyT
  37. | KeyY
  38. | KeyU
  39. | KeyI
  40. | KeyO
  41. | KeyP
  42. | KeyLBracketCurly
  43. | KeyRBracketCurly
  44. | KeyBackslashPipe
    (*

    replaced by KeyNonUSNumberTilde on ISO KB

    *)
  45. | KeyCapsLock
  46. | KeyA
  47. | KeyS
  48. | KeyD
  49. | KeyF
  50. | KeyG
  51. | KeyH
  52. | KeyJ
  53. | KeyK
  54. | KeyL
  55. | KeySemicolonColon
  56. | KeyQuoteDoublequote
  57. | KeyNonUSNumberTilde
    (*

    extra key left of Return on ISO KB, although generally mapped to KeyBackslashPipe instead

    *)
  58. | KeyReturn
  59. | KeyLShift
  60. | KeyNonUSBackslashPipe
    (*

    extra key right of LShift on ISO KB

    *)
  61. | KeyZ
  62. | KeyX
  63. | KeyC
  64. | KeyV
  65. | KeyB
  66. | KeyN
  67. | KeyM
  68. | KeyCommaLess
  69. | KeyPeriodGreater
  70. | KeySlashQuestion
  71. | KeyRShift
  72. | KeyLControl
  73. | KeyLMeta
    (*

    left Windows / Command key

    *)
  74. | KeyLAlt
  75. | KeySpacebar
  76. | KeyRAlt
  77. | KeyRMeta
    (*

    right Windows / Command key

    *)
  78. | KeyMenu
  79. | KeyRControl
  80. | KeyInsert
    (*

    replaced by a Fn key on Mac (with a different code)

    *)
  81. | KeyHome
  82. | KeyPageUp
  83. | KeyDeleteForward
  84. | KeyEend
  85. | KeyPageDown
  86. | KeyUpArrow
  87. | KeyLeftArrow
  88. | KeyDownArrow
  89. | KeyRightArrow
  90. | KeyPadNumlockClear
    (*

    on Mac, Clear replaces NumLock

    *)
  91. | KeyPadEquals
    (*

    on Mac keyboards only

    *)
  92. | KeyPadDivide
  93. | KeyPadMultiply
  94. | KeyPadMinus
  95. | KeyPad7Home
  96. | KeyPad8UpArrow
  97. | KeyPad9PageUp
  98. | KeyPadPlus
  99. | KeyPad4LeftArrow
  100. | KeyPad5
  101. | KeyPad6RightArrow
  102. | KeyPadComma
    (*

    specific to Brazilian keyboards

    *)
  103. | KeyPad1End
  104. | KeyPad2DownArrow
  105. | KeyPad3PageDown
  106. | KeyPad0Insert
  107. | KeyPadDecimalDelete
  108. | KeyPadEnter
  109. | KeyF13
  110. | KeyF14
  111. | KeyF15
  112. | KeyF16
  113. | KeyF17
  114. | KeyF18
  115. | KeyF19
  116. | KeyF20
  117. | KeyF21
  118. | KeyF22
  119. | KeyF23
  120. | KeyF24
  121. | KeyInternational1
    (*

    extra key left of RShift on JIS and Brazilian KB

    *)
  122. | KeyInternational2
    (*

    Katakana/Hiragana key right of Space on JIS KB

    *)
  123. | KeyInternational3
    (*

    extra key left of Backspace on JIS KB

    *)
  124. | KeyInternational4
    (*

    Henkan key right of Space on JIS KB

    *)
  125. | KeyInternational5
    (*

    Muhenkan key left of Space on JIS KB

    *)
  126. | KeyInternational6
    (*

    Kanma (comma) key right of KP0 on JIS KB

    *)
  127. | KeyInternational7
    (*

    Double-Byte/Single-Byte toggle key

    *)
  128. | KeyInternational8
    (*

    Undefined

    *)
  129. | KeyInternational9
    (*

    Undefined

    *)
  130. | KeyLang1
    (*

    Hangul/English toggle key (Korean)

    *)
  131. | KeyLang2
    (*

    Hanja conversion key (Korean)

    *)
  132. | KeyLang3
    (*

    Katakana key (Japanese)

    *)
  133. | KeyLang4
    (*

    Hiragana key (Japanese)

    *)
  134. | KeyLand5
    (*

    Zenkaku/Hankaku key (Japanese)

    *)
  135. | KeyHelp
  136. | KeyMute
  137. | KeyVolumeUp
  138. | KeyVolumeDown
    (*

    A physical keyboard key, assuming an ideal "extended" QWERTY keyboard that synthetizes various layouts, including ANSI, ISO and JIS. Note that the symbol on the key may be different from the symbolic key name: this allows to refer to keys by their physical location, which can be useful for instance in games.

    *)
type flags = {
  1. flag_shift : bool;
  2. flag_alt : bool;
  3. flag_control : bool;
  4. flag_meta : bool;
  5. flag_capslock : bool;
  6. flag_numlock : bool;
  7. flag_dead : bool;
}

The state of various keyboard flags

type key_data = {
  1. key : key;
    (*

    Physical key that was pressed/released

    *)
  2. char : Stdlib.Uchar.t;
    (*

    Equivalent Unicode character in the current layout

    *)
  3. flags : flags;
    (*

    State of various modifier keys when the event occured

    *)
}

Describes a keyboard event

type button =
  1. | ButtonNone
  2. | ButtonLeft
  3. | ButtonMiddle
  4. | ButtonRight
  5. | ButtonWheelUp
  6. | ButtonWheelDown
    (*

    A mouse button

    *)
type button_data = {
  1. position : position;
    (*

    Cursor position when the event occured

    *)
  2. button : button;
    (*

    Button that was pressed/released

    *)
}

Describes a mouse button event

val frame : unit canvas_event React.event

Occurs when the backend determines it is time to draw a new frame. A typical frequency is 60 times per second, though this varies depending on the platform.

val focus_in : unit canvas_event React.event

Occurs when the canvas becomes active as a result of being clicked or tabbed-into

val focus_out : unit canvas_event React.event

Occurs when the canvas becomes inactive as a result of another canvas being clicked or tabbed-into

val resize : size canvas_event React.event

Occurs when the canvas is resized by a user action

val move : position canvas_event React.event

Occurs when the canvas is moved by a user action

val close : unit canvas_event React.event

Occurs when the user clicks the close button

val key_down : key_data canvas_event React.event

Occurs when the user presses a key on the keyboard. The event description contains both the physical key (of type Event.key and the Unicode character corresponding to that key (if any), according to the current keyboard layout. For instance, pressing the "A" key on an AZERTY keyboard will yield a physical key Event.KeyQ and the Unicode code point for character "A".

val key_up : key_data canvas_event React.event

Occurs when the user releases a key on the keyboard

val button_down : button_data canvas_event React.event

Occurs when the user presses a mouse button

val button_up : button_data canvas_event React.event

Occurs when the user releases a mouse button

val mouse_move : size canvas_event React.event

Occurs when the user moves the mouse cursor

val event_timestamp : Stdlib.Int64.t React.signal

The timestamp of the last canvas event that occurred

val int_of_key : key -> int

int_of_key k returns a platform-independent integer representation of key k. This integer corresponds to the key code as defined by the USB standard for keybords.

val key_of_int : int -> key

key_of_int i returns the key corresponding to the platform-independent integer i in the range 0-255.

Exceptions:

  • Invalid_argument if i < 0 or i > 255
OCaml

Innovation. Community. Security.