12 typedef struct hotKey_struct
{
18 static list_t
*listHotKey
;
19 static my_time_t lastActive
;
21 static hotKey_t
*newHotKey(SDLKey key
, void (*handler
) ())
25 new = malloc(sizeof(hotKey_t
));
28 new->handler
= handler
;
33 static void destroyHotKey(hotKey_t
*hotkey
)
38 static hotKey_t
*findHotkey(SDLKey key
)
42 for (i
= 0; i
< listHotKey
->count
; i
++) {
45 this = (hotKey_t
*) listHotKey
->list
[i
];
47 if (this->key
== key
) {
57 listHotKey
= list_new();
58 lastActive
= timer_get_current_time();
61 void hot_key_register(SDLKey key
, void (*handler
) ())
65 if (findHotkey(key) != NULL) {
66 assert(!"Conflict with register key");
69 hotkey
= newHotKey(key
, handler
);
70 list_ins(listHotKey
, 0, hotkey
);
73 void hot_key_unregister(SDLKey key
)
78 hotkey
= findHotkey(key
);
81 fatal("Unregistering not registered hotkey");
84 my_index
= list_search(listHotKey
, hotkey
);
85 assert(my_index
!= -1);
86 list_del_item(listHotKey
, my_index
, destroyHotKey
);
89 void hot_key_enable(SDLKey key
)
93 hotkey
= findHotkey(key
);
96 fatal("Enabling not registered hotkey");
99 lastActive
= timer_get_current_time();
100 hotkey
->active
= TRUE
;
103 void hot_key_disable(SDLKey key
)
107 hotkey
= findHotkey(key
);
109 if (hotkey
== NULL
) {
110 fatal("Disabling not registered hotkey");
113 lastActive
= timer_get_current_time();
114 hotkey
->active
= FALSE
;
119 my_time_t currentTime
;
123 currentTime
= timer_get_current_time();
125 if (currentTime
- lastActive
< HOTKEY_ACTIVE_INTERVAL
) {
129 mapa
= SDL_GetKeyState(NULL
);
131 for (i
= 0; i
< listHotKey
->count
; i
++) {
134 this = (hotKey_t
*) listHotKey
->list
[i
];
136 if (mapa
[this->key
] == SDL_PRESSED
&& this->active
== TRUE
) {
137 lastActive
= timer_get_current_time();
138 /*printf("hotKey = %d\n", this->key);*/
148 list_destroy_item(listHotKey
, destroyHotKey
);