123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234 |
- #ifndef __OMOUSE_H
- #define __OMOUSE_H
- #ifndef __ALL_H
- #include <ALL.h>
- #endif
- #define DIRECTINPUT_VERSION 0x300
- #include <dinput.h>
- enum MouseEventType
- {
- LEFT_BUTTON = 0,
- RIGHT_BUTTON = LEFT_BUTTON+1,
- KEY_PRESS = 2,
- LEFT_BUTTON_RELEASE = 4,
- RIGHT_BUTTON_RELEASE = LEFT_BUTTON_RELEASE+1,
- KEY_RELEASE = 6,
- };
- #define LEFT_BUTTON_MASK 1
- #define RIGHT_BUTTON_MASK 2
- #define LEFT_SHIFT_KEY_MASK 0x001
- #define RIGHT_SHIFT_KEY_MASK 0x002
- #define SHIFT_KEY_MASK 0x003
- #define LEFT_CONTROL_KEY_MASK 0x004
- #define RIGHT_CONTROL_KEY_MASK 0x008
- #define CONTROL_KEY_MASK 0x00c
- #define LEFT_ALT_KEY_MASK 0x010
- #define RIGHT_ALT_KEY_MASK 0x020
- #define ALT_KEY_MASK 0x030
- #define NUM_LOCK_STATE_MASK 0x040
- #define CAP_LOCK_STATE_MASK 0x080
- #define SCROLL_LOCK_STATE_MASK 0x100
- #define INSERT_STATE_MASK 0x200
- #define GRAPH_KEY_MASK 0x400
- #define MOUSE_X_UPPER_LIMIT (VGA_WIDTH-5)
- #define MOUSE_Y_UPPER_LIMIT (VGA_HEIGHT-5)
- #define DEFAULT_DOUBLE_SPEED_THRESHOLD 8
- #define DEFAULT_TRIPLE_SPEED_THRESHOLD 16
- struct MouseClick
- {
- int x, y;
- int release_x, release_y;
- int count;
- DWORD time;
- DWORD release_time;
- };
- struct MouseEvent
- {
- MouseEventType event_type;
- DWORD time;
- unsigned short skey_state;
-
- int x, y;
- unsigned scan_code;
- };
- class Mouse
- {
- public:
- char init_flag;
- char handle_flicking;
- char* vga_update_buf;
- HHOOK key_hook_handle;
-
- LPDIRECTINPUT direct_input;
- LPDIRECTINPUTDEVICE di_mouse_device, di_keyb_device;
-
- int cur_x, cur_y;
- int left_press, right_press;
-
- unsigned short skey_state;
-
- int bound_x1;
- int bound_y1;
- int bound_x2;
- int bound_y2;
-
- int double_speed_threshold;
- int triple_speed_threshold;
-
- unsigned short event_skey_state;
- char has_mouse_event;
- MouseEventType mouse_event_type;
- MouseClick click_buffer[2];
-
- unsigned scan_code;
- unsigned key_code;
-
- enum { EVENT_BUFFER_SIZE = 20 };
- MouseEvent event_buffer[EVENT_BUFFER_SIZE];
- int head_ptr;
- int tail_ptr;
- public:
- Mouse();
- ~Mouse();
- void init(HINSTANCE, HWND, LPDIRECTINPUT createdDirectInput=0);
- void deinit();
- void add_event(MouseEvent *);
- void add_key_event(unsigned, DWORD);
- int get_event();
- void poll_event();
-
- void update_skey_state();
-
- void show();
- void hide();
- void hide_area(int,int,int,int);
- void show_area();
-
- int in_area(int,int,int,int);
- int press_area(int,int,int,int,int=0);
- int wait_press(int timeOutSecond=0);
-
- void set_boundary(int, int, int, int);
- void reset_boundary();
-
- int single_click(int,int,int,int,int=0);
- int double_click(int,int,int,int,int=0);
- int any_click (int,int,int,int,int=0);
- int any_click(int=0);
- int release_click(int,int,int,int,int=0);
- int click_x(int buttonId=0) { return click_buffer[buttonId].x; }
- int click_y(int buttonId=0) { return click_buffer[buttonId].y; }
- int release_x(int buttonId=0) { return click_buffer[buttonId].release_x; }
- int release_y(int buttonId=0) { return click_buffer[buttonId].release_y; }
- int click_count(int buttonId=0) { return click_buffer[buttonId].count; }
- int is_mouse_event() { return has_mouse_event; }
- int is_key_event() { return scan_code; }
- int is_any_event() { return has_mouse_event || scan_code; }
- int is_press_button_event() { return has_mouse_event && (mouse_event_type == LEFT_BUTTON || mouse_event_type == RIGHT_BUTTON); }
- int is_release_button_event() { return has_mouse_event && (mouse_event_type == LEFT_BUTTON_RELEASE || mouse_event_type == RIGHT_BUTTON_RELEASE); }
- void reset_click();
- static int is_key(unsigned keyCode, unsigned short skeyState, unsigned short charValue, unsigned flags = 0 );
- static int is_key(unsigned keyCode, unsigned short skeyState, char *keyStr, unsigned flags = 0 );
-
- private:
- long micky_to_displacement(DWORD);
- };
- extern Mouse mouse;
- #endif
|