package allg5

// #include <allegro5/allegro.h>
import "C"

type Key int

const (
	KeyA           Key = 1
	KeyB               = 2
	KeyC               = 3
	KeyD               = 4
	KeyE               = 5
	KeyF               = 6
	KeyG               = 7
	KeyH               = 8
	KeyI               = 9
	KeyJ               = 10
	KeyK               = 11
	KeyL               = 12
	KeyM               = 13
	KeyN               = 14
	KeyO               = 15
	KeyP               = 16
	KeyQ               = 17
	KeyR               = 18
	KeyS               = 19
	KeyT               = 20
	KeyU               = 21
	KeyV               = 22
	KeyW               = 23
	KeyX               = 24
	KeyY               = 25
	KeyZ               = 26
	Key0               = 27
	Key1               = 28
	Key2               = 29
	Key3               = 30
	Key4               = 31
	Key5               = 32
	Key6               = 33
	Key7               = 34
	Key8               = 35
	Key9               = 36
	KeyPad0            = 37
	KeyPad1            = 38
	KeyPad2            = 39
	KeyPad3            = 40
	KeyPad4            = 41
	KeyPad5            = 42
	KeyPad6            = 43
	KeyPad7            = 44
	KeyPad8            = 45
	KeyPad9            = 46
	KeyF1              = 47
	KeyF2              = 48
	KeyF3              = 49
	KeyF4              = 50
	KeyF5              = 51
	KeyF6              = 52
	KeyF7              = 53
	KeyF8              = 54
	KeyF9              = 55
	KeyF10             = 56
	KeyF11             = 57
	KeyF12             = 58
	KeyEscape          = 59
	KeyTilde           = 60
	KeyMinus           = 61
	KeyEquals          = 62
	KeyBackspace       = 63
	KeyTab             = 64
	KeyOpenBrace       = 65
	KeyCloseBrace      = 66
	KeyEnter           = 67
	KeySemicolon       = 68
	KeyQuote           = 69
	KeyBackslash       = 70
	KeyBackslash2      = 71 /* DirectInput calls this DIK_OEM_102: "< > | on UK/Germany keyboards" */
	KeyComma           = 72
	KeyFullstop        = 73
	KeySlash           = 74
	KeySpace           = 75
	KeyInsert          = 76
	KeyDelete          = 77
	KeyHome            = 78
	KeyEnd             = 79
	KeyPageUp          = 80
	KeyPageDown        = 81
	KeyLeft            = 82
	KeyRight           = 83
	KeyUp              = 84
	KeyDown            = 85
	KeyPadSlash        = 86
	KeyPadAsterisk     = 87
	KeyPadMinus        = 88
	KeyPadPlus         = 89
	KeyPadDelete       = 90
	KeyPadEnter        = 91
	KeyPrintScreen     = 92
	KeyPause           = 93
	KeyAbntC1          = 94
	KeyYen             = 95
	KeyKana            = 96
	KeyConvert         = 97
	KeyNoConvert       = 98
	KeyAt              = 99
	KeyCircumflex      = 100
	KeyColon2          = 101
	KeyKanji           = 102
	KeyPadEquals       = 103 /* MacOS X */
	KeyBackQuote       = 104 /* MacOS X */
	KeySemicolon2      = 105 /* MacOS X -- TODO: ask lillo what this should be */
	KeyCommand         = 106 /* MacOS X */
	KeyBack            = 107 /* Android back key */
	KeyVolumeUp        = 108
	KeyVolumeDown      = 109
	KeySearch          = 110
	KeyDPadCenter      = 111
	KeyButtonX         = 112
	KeyButtonY         = 113
	KeyDPadUp          = 114
	KeyDPadDown        = 115
	KeyDPadLeft        = 116
	KeyDPadRight       = 117
	KeySelect          = 118
	KeyStart           = 119
	KeyButtonL1        = 120
	KeyButtonR1        = 121
	KeyButtonL2        = 122
	KeyButtonR2        = 123
	KeyButtonA         = 124
	KeyButtonB         = 125
	KeyThumbL          = 126
	KeyThumbR          = 127
	KeyUnknown         = 128
	KeyModifiers       = 215
	KeyLShift          = 215
	KeyRShift          = 216
	KeyLCtrl           = 217
	KeyRCtrl           = 218
	KeyAlt             = 219
	KeyAltGr           = 220
	KeyLWin            = 221
	KeyRWin            = 222
	KeyMenu            = 223
	KeyScrollLock      = 224
	KeyNumLock         = 225
	KeyCapsLock        = 226
)

type KeyMod uint

const (
	KeyModShift      KeyMod = 0x00001
	KeyModCtrl              = 0x00002
	KeyModAlt               = 0x00004
	KeyModLWin              = 0x00008
	KeyModRWin              = 0x00010
	KeyModMenu              = 0x00020
	KeyModAltGr             = 0x00040
	KeyModCommand           = 0x00080
	KeyModScrollLock        = 0x00100
	KeyModNumlock           = 0x00200
	KeyModCapsLock          = 0x00400
	KeyModInaltseq          = 0x00800
	KeyModAccent1           = 0x01000
	KeyModAccent2           = 0x02000
	KeyModAccent3           = 0x04000
	KeyModAccent4           = 0x08000
)

func IsKeyDown(k Key) bool {
	var state C.ALLEGRO_KEYBOARD_STATE
	C.al_get_keyboard_state(&state)
	return bool(C.al_key_down(&state, C.int(k)))
}

func IsAnyKeyDown(keys ...Key) bool {
	var state C.ALLEGRO_KEYBOARD_STATE
	C.al_get_keyboard_state(&state)
	for _, k := range keys {
		if bool(C.al_key_down(&state, C.int(k))) {
			return true
		}
	}
	return false
}