keydown event

If you are using wxDev-C++ for your wxWidgets design, please ask your questions here instead of in IDE Related.
Post Reply
wojtek
In need of some credit
In need of some credit
Posts: 5
Joined: Sat Nov 12, 2011 10:35 am

keydown event

Post by wojtek »

hello, i have a problem with keyboard support. i write 3d editor with wx and opengl.
in opengl window, user is able to move through a 3d space with mouse and keys.
if i put down "move key". it moves one time, then it sleeps for a while
and then it countinues moving.

how to make movements smooth? i think that it is connected with repetition of
keyboard buttons, after pressing one for a while.

some code:

Code: Select all

void Viewport::OnKeyDown(wxKeyEvent &event) {
    switch(event.GetKeyCode()) {
        case WXK_UP:
            kamera.move(speed);
[...]
i have also a question about keycodes. how to check if "wsad" keys are pressed?
i have tried with

Code: Select all

case 'w':
case 'W':
but it does not work for me (windows xp)
jgrzybowski
Earned some good credits
Earned some good credits
Posts: 113
Joined: Sat Sep 24, 2011 9:32 pm
Location: Poland

Re: keydown event

Post by jgrzybowski »

According to second case - keycodes. You have already used a following method of wxKeyCode class: int GetKeyCode(). This function returns ASCII key code (int) or virtual code (like WXK_UP). ASCII key codes you can find here: http://www.asciitable.com/ So letter small "w" has ASCII code 119.
Regards
Jarek
wojtek
In need of some credit
In need of some credit
Posts: 5
Joined: Sat Nov 12, 2011 10:35 am

Re: keydown event

Post by wojtek »

hello, i've solved my problem by removing from program:

Code: Select all

EVT_KEY_DOWN(Viewport::OnKeyDown)
EVT_KEY_UP(Viewport::OnKeyUp)
and then i added in main loop something like:

Code: Select all

    if(wxGetKeyState((wxKeyCode)'d') || wxGetKeyState((wxKeyCode)'D')) {
        kamera.move(speed);
it's not elegant, but wxwidgets doesn't provide another way to do this.
Post Reply