Add scancode and virtual key and fix some sdl stuff on Windows
This commit is contained in:
@@ -305,9 +305,9 @@ int main()
|
||||
eventHandler.OnKeyPressed.Connect([&targetPos, &cameraNode, &smoothMovement, &window](const Nz::EventHandler*, const Nz::WindowEvent::KeyEvent& event)
|
||||
{
|
||||
// Une touche a été pressée !
|
||||
if (event.code == Nz::Keyboard::Key::Escape)
|
||||
if (event.virtualKey == Nz::Keyboard::VKey::Escape)
|
||||
window.Close();
|
||||
else if (event.code == Nz::Keyboard::F1)
|
||||
else if (event.virtualKey == Nz::Keyboard::VKey::F1)
|
||||
{
|
||||
if (smoothMovement)
|
||||
{
|
||||
@@ -348,34 +348,34 @@ int main()
|
||||
if (move)
|
||||
{
|
||||
// Si la touche espace est enfoncée, notre vitesse de déplacement est multipliée par deux
|
||||
if (Nz::Keyboard::IsKeyPressed(Nz::Keyboard::Space))
|
||||
if (Nz::Keyboard::IsKeyPressed(Nz::Keyboard::VKey::Space))
|
||||
cameraSpeed *= 2.f;
|
||||
|
||||
// Pour que nos déplacement soient liés à la rotation de la caméra, nous allons utiliser
|
||||
// les directions locales de la caméra
|
||||
|
||||
// Si la flèche du haut ou la touche Z (vive ZQSD !!) est pressée, on avance
|
||||
if (Nz::Keyboard::IsKeyPressed(Nz::Keyboard::Up) || Nz::Keyboard::IsKeyPressed(Nz::Keyboard::Z))
|
||||
if (Nz::Keyboard::IsKeyPressed(Nz::Keyboard::VKey::Up) || Nz::Keyboard::IsKeyPressed(Nz::Keyboard::VKey::Z))
|
||||
targetPos += cameraNode.GetForward() * cameraSpeed;
|
||||
|
||||
// Si la flèche du bas ou la touche S est pressée, on recule
|
||||
if (Nz::Keyboard::IsKeyPressed(Nz::Keyboard::Down) || Nz::Keyboard::IsKeyPressed(Nz::Keyboard::S))
|
||||
if (Nz::Keyboard::IsKeyPressed(Nz::Keyboard::VKey::Down) || Nz::Keyboard::IsKeyPressed(Nz::Keyboard::VKey::S))
|
||||
targetPos += cameraNode.GetBackward() * cameraSpeed;
|
||||
|
||||
// Etc...
|
||||
if (Nz::Keyboard::IsKeyPressed(Nz::Keyboard::Left) || Nz::Keyboard::IsKeyPressed(Nz::Keyboard::Q))
|
||||
if (Nz::Keyboard::IsKeyPressed(Nz::Keyboard::VKey::Left) || Nz::Keyboard::IsKeyPressed(Nz::Keyboard::VKey::Q))
|
||||
targetPos += cameraNode.GetLeft() * cameraSpeed;
|
||||
|
||||
// Etc...
|
||||
if (Nz::Keyboard::IsKeyPressed(Nz::Keyboard::Right) || Nz::Keyboard::IsKeyPressed(Nz::Keyboard::D))
|
||||
if (Nz::Keyboard::IsKeyPressed(Nz::Keyboard::VKey::Right) || Nz::Keyboard::IsKeyPressed(Nz::Keyboard::VKey::D))
|
||||
targetPos += cameraNode.GetRight() * cameraSpeed;
|
||||
|
||||
// Majuscule pour monter, notez l'utilisation d'une direction globale (Non-affectée par la rotation)
|
||||
if (Nz::Keyboard::IsKeyPressed(Nz::Keyboard::LShift) || Nz::Keyboard::IsKeyPressed(Nz::Keyboard::RShift))
|
||||
if (Nz::Keyboard::IsKeyPressed(Nz::Keyboard::VKey::LShift) || Nz::Keyboard::IsKeyPressed(Nz::Keyboard::VKey::RShift))
|
||||
targetPos += Nz::Vector3f::Up() * cameraSpeed;
|
||||
|
||||
// Contrôle (Gauche ou droite) pour descendre dans l'espace global, etc...
|
||||
if (Nz::Keyboard::IsKeyPressed(Nz::Keyboard::LControl) || Nz::Keyboard::IsKeyPressed(Nz::Keyboard::RControl))
|
||||
if (Nz::Keyboard::IsKeyPressed(Nz::Keyboard::VKey::LControl) || Nz::Keyboard::IsKeyPressed(Nz::Keyboard::VKey::RControl))
|
||||
targetPos += Nz::Vector3f::Down() * cameraSpeed;
|
||||
}
|
||||
|
||||
|
||||
@@ -677,7 +677,8 @@ void SpacebattleExample::Leave(Ndk::StateMachine& fsm)
|
||||
{
|
||||
m_ambientMusic.Stop();
|
||||
m_onMouseMoved.Disconnect();
|
||||
m_shared.target->SetCursor(Nz::SystemCursor_Default);
|
||||
if (m_shared.target)
|
||||
m_shared.target->SetCursor(Nz::SystemCursor_Default);
|
||||
m_shared.world3D->RemoveSystem<LaserBeamSystem>();
|
||||
m_shared.world3D->RemoveSystem<SpaceshipSystem>();
|
||||
m_turretFireSound.Stop();
|
||||
|
||||
@@ -123,17 +123,17 @@ int main()
|
||||
{
|
||||
case Nz::WindowEventType_KeyPressed:
|
||||
{
|
||||
switch (event.key.code)
|
||||
switch (event.key.virtualKey)
|
||||
{
|
||||
case Nz::Keyboard::Backspace:
|
||||
case Nz::Keyboard::VKey::Backspace:
|
||||
stateMachine.ChangeState(shared.demos[demoIndex]);
|
||||
break;
|
||||
|
||||
case Nz::Keyboard::Escape:
|
||||
case Nz::Keyboard::VKey::Escape:
|
||||
app.Quit();
|
||||
break;
|
||||
|
||||
case Nz::Keyboard::Left:
|
||||
case Nz::Keyboard::VKey::Left:
|
||||
{
|
||||
if (shared.demos.size() <= 1)
|
||||
break;
|
||||
@@ -146,7 +146,7 @@ int main()
|
||||
break;
|
||||
}
|
||||
|
||||
case Nz::Keyboard::Right:
|
||||
case Nz::Keyboard::VKey::Right:
|
||||
{
|
||||
if (shared.demos.size() <= 1)
|
||||
break;
|
||||
@@ -159,14 +159,14 @@ int main()
|
||||
break;
|
||||
}
|
||||
|
||||
case Nz::Keyboard::Pause:
|
||||
case Nz::Keyboard::VKey::Pause:
|
||||
{
|
||||
auto& velocitySystem = shared.world3D->GetSystem<Ndk::VelocitySystem>();
|
||||
velocitySystem.Enable(!velocitySystem.IsEnabled());
|
||||
break;
|
||||
}
|
||||
|
||||
case Nz::Keyboard::F5:
|
||||
case Nz::Keyboard::VKey::F5:
|
||||
{
|
||||
Nz::Image screenshot;
|
||||
screenshot.Create(Nz::ImageType_2D, Nz::PixelFormatType_RGBA8, 1920, 1080);
|
||||
@@ -197,5 +197,7 @@ int main()
|
||||
window.Display();
|
||||
}
|
||||
|
||||
shared.target = nullptr;
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -33,10 +33,10 @@ int main(int argc, char* argv[])
|
||||
Nz::EventHandler& eventHandler = mainWindow.GetEventHandler();
|
||||
eventHandler.OnKeyPressed.Connect([](const Nz::EventHandler*, const Nz::WindowEvent::KeyEvent& e)
|
||||
{
|
||||
std::cout << Nz::Keyboard::GetKeyName(e.code) << std::endl;
|
||||
std::cout << Nz::Keyboard::GetKeyName(e.virtualKey) << std::endl;
|
||||
|
||||
// Profitons-en aussi pour nous donner un moyen de quitter le programme
|
||||
if (e.code == Nz::Keyboard::Escape)
|
||||
if (e.virtualKey == Nz::Keyboard::VKey::Escape)
|
||||
Ndk::Application::Instance()->Quit(); // Cette ligne casse la boucle Run() de l'application
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user