KeyHit
This function gets the keyhit state of a window.
Syntax
Parameters
- keycode: the key to check. See the Key class for available key codes.
Returns
Returns true if the specified key is has been pressed since the last time it was checked, otherwise false is returned.
Example
#include "Leadwerks.h"
using namespace Leadwerks;
Model* model = NULL;
int keyhits=0;
int main(int argc, const char *argv[])
{
Leadwerks::Window* window = Leadwerks::Window::Create();
Context* context = Context::Create(window);
World* world = World::Create();
Camera* camera = Camera::Create();
camera->Move(0,0,-3);
Light* light = DirectionalLight::Create();
light->SetRotation(35,35,0);
//Create a model
model = Model::Box();
model->SetColor(0.0,0.0,1.0);
while (true)
{
if (window->Closed() || window->KeyDown(Key::Escape)) return false;
model->Turn(0,Leadwerks::Time::GetSpeed(),0);
Leadwerks::Time::Update();
world->Update();
world->Render();
//Press the space key to see the result
if (window->KeyHit(Key::Space)) keyhits++;
context->SetBlendMode(Blend::Alpha);
context->DrawText("Space key hits: "+String(keyhits),2,2);
context->SetBlendMode(Blend::Solid);
context->Sync(false);
}
return 0;
}