Mouse event and key event together ? Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
krishnaprasad
Experienced Solver
Experienced Solver
Posts: 77
Joined: Tue Oct 21, 2008 6:07 pm

Mouse event and key event together ?

Post by krishnaprasad » Mon Dec 15, 2008 8:42 pm

Is there a way i can see if a key has been pressed and then set a flag using which the mouse event is called ? I would need to see if spacebar is pressed and if yes, i would need to change the cursor and call a panning function

timg
Earned some good credits
Earned some good credits
Posts: 148
Joined: Mon Jan 23, 2006 6:52 pm

Post by timg » Mon Dec 15, 2008 9:08 pm

Couldn't you set the flag in a KEY_DOWN event and clear it in a KEY_UP event?

framepointer
Super wx Problem Solver
Super wx Problem Solver
Posts: 264
Joined: Mon Aug 07, 2006 3:25 pm
Location: Baia Mare, Romania
Contact:

Post by framepointer » Mon Dec 15, 2008 9:45 pm

Hi.

You can use EVT_KEY_DOWN and EVT_KEY_UP.
In the key down event set a boolean value to true if the key is SPACE. In the key up event unset the boolean value if the key is SPACE.

In the mouse event just check for this boolean value. Of course, the devs could add an array which could hold the keys currently pressed :D

Also, since the events are called in order, if you hold down space and click, you will be able to determine it exactly.

Regards
Software is like sex,
It's better when it's free.
~Linus Torvalds

DavidHart
Site Admin
Site Admin
Posts: 3888
Joined: Thu Jan 12, 2006 6:23 pm
Location: IoW, UK

Post by DavidHart » Mon Dec 15, 2008 10:15 pm

Hi,

I'm not sure whether you want to check the mouse state in a key-event, or vice versa. But you can use one of http://docs.wxwidgets.org/stable/wx_mis ... mousestate and http://docs.wxwidgets.org/stable/wx_mis ... etkeystate

Regards,

David

Post Reply