Input is data given by a user. It often occurs through the mouse or keyboard, such as a mouse click or keyboard press. Input is important if a game intends to respond to user commands. ClanLib offers two classes to read input: a keyboard class and a mouse class.
To read information from the keyboard, such as which key the user is currently holding down or which key is not being pressed, the CL_Keyboard class is used. Specifically, to determine the status of any key, the get_keycode method should be called. This method returns true or false, depending on whether or not a key is held down. True is returned if the key is pressed, and false otherwise.
//if Escape is not being pressed... If(!CL_Keyboard::get_keycode(CL_KEY_ESCAPE)) { //Do something here }
Aside from the mouse scroll wheel, there are essentially two fields of information that can be read from the mouse: cursor position and button status. Cursor position refers to the (x, y) coordinate of the mouse pointer on the screen. The button status refers to whether the left, middle (if there is one), or right mouse button is pressed. The mouse is encapsulated into the CL_Mouse class.
To retrieve the x and y locations of the cursor, the get_x and get_y methods can be called. Consider the following code:
int Xpos = CL_Mouse::get_x(), int YPos = CL_Mouse::get_y();
Testing whether or not a specified mouse button is pressed is much like determining whether a key on the keyboard is pressed. Here, the get_keycode method is called.
//If left mouse button pressed if(CL_Mouse::get_keycode(CL_MOUSE_LEFT)) { //do something here }