input.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // Copyright 2015 Hajime Hoshi
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package ebiten
  15. import (
  16. "github.com/hajimehoshi/ebiten/internal/ui"
  17. )
  18. // IsKeyPressed returns a boolean indicating whether key is pressed.
  19. func IsKeyPressed(key Key) bool {
  20. return ui.IsKeyPressed(ui.Key(key))
  21. }
  22. // CursorPosition returns a position of a mouse cursor.
  23. func CursorPosition() (x, y int) {
  24. return ui.CursorPosition()
  25. }
  26. // IsMouseButtonPressed returns a boolean indicating whether mouseButton is pressed.
  27. func IsMouseButtonPressed(mouseButton MouseButton) bool {
  28. return ui.IsMouseButtonPressed(ui.MouseButton(mouseButton))
  29. }
  30. // GamepadAxisNum returns the number of axes of the gamepad.
  31. //
  32. // NOTE: Gamepad API is available only on desktops, Chrome and Firefox.
  33. // To use this API, browsers might require rebooting the browser.
  34. func GamepadAxisNum(id int) int {
  35. return ui.GamepadAxisNum(id)
  36. }
  37. // GamepadAxis returns the float value [-1.0 - 1.0] of the axis.
  38. //
  39. // NOTE: Gamepad API is available only on desktops, Chrome and Firefox.
  40. // To use this API, browsers might require rebooting the browser.
  41. func GamepadAxis(id int, axis int) float64 {
  42. return ui.GamepadAxis(id, axis)
  43. }
  44. // GamepadButtonNum returns the number of the buttons of the gamepad.
  45. //
  46. // NOTE: Gamepad API is available only on desktops, Chrome and Firefox.
  47. // To use this API, browsers might require rebooting the browser.
  48. func GamepadButtonNum(id int) int {
  49. return ui.GamepadButtonNum(id)
  50. }
  51. // IsGamepadButtonPressed returns the boolean indicating the buttons is pressed or not.
  52. //
  53. // NOTE: Gamepad API is available only on desktops, Chrome and Firefox.
  54. // To use this API, browsers might require rebooting the browser.
  55. func IsGamepadButtonPressed(id int, button GamepadButton) bool {
  56. return ui.IsGamepadButtonPressed(id, ui.GamepadButton(button))
  57. }