-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInput.fs
37 lines (31 loc) · 859 Bytes
/
Input.fs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
(*
Processes keyboard and mouse input
*)
module Input
open Microsoft.Xna.Framework
open Microsoft.Xna.Framework.Input
//Find a key in a list of keys
let findKey key list =
List.exists (fun k -> k = key) list
//Get a list of pressed keys
let getKeyboardInput () =
let ks = Keyboard.GetState ()
let keys =
[ Keys.Up
Keys.Down
Keys.Left
Keys.Right
Keys.Space
Keys.Escape ]
List.filter (fun k -> ks.IsKeyDown (k)) keys
//Get a list of pressed mouse buttons
let getMouseInput () =
let ms = Mouse.GetState ()
let buttons =
[ ms.LeftButton
ms.RightButton ]
List.filter (fun b -> b = ButtonState.Pressed) buttons
//Get the mouse posiiton
let getMousePosition () =
let ms = Mouse.GetState ()
Vector2 (float32 ms.Position.X, float32 ms.Position.Y)