Is Control key down?

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
bertolino
Experienced Solver
Experienced Solver
Posts: 77
Joined: Wed Aug 14, 2013 8:07 am
Location: France
Contact:

Is Control key down?

Post by bertolino »

I want to know if Control key is down when moving the mouse
but I can't make it work in all cases (and I get the same behavior with the Shift key).
- It works if Control key is pressed then mouse is moved with left button down.
- It doesn't work if Control key is pressed then mouse is moved without left button down.
- It doesn't work if mouse is moved with left button down then Control key is pressed.

I tried to get the Control key status by different ways:

Code: Select all

Bind(wxEVT_MOTION, &MyFrame::OnMouseMove, this);
...	
void MyFrame::OnMouseMove(wxMouseEvent & event)
{
	wxKeyboardState kbs;
	if (event.ControlDown() || kbs.ControlDown())
		wxLogMessage(wxT("You moved the mouse with Control key down!"));  
}
By the way, OnKeyDown below is called when the Control key is released...

Code: Select all

Bind(wxEVT_KEY_DOWN, &MyFrame::OnKeyDown, this);
...
void MyFrame::OnKeyDown(wxKeyEvent & event)
{
	if (event.ControlDown())
		wxLogMessage(wxT("You pressed the Control key!"));
}
Minimalist code attached.
Many thanks for any idea about this,

Pascal
Attachments
control_key.cpp
(1.27 KiB) Downloaded 127 times
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7458
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Is Control key down?

Post by ONEEYEMAN »

Hi,
How does it work in the keyboard sample?

Thank you.
bertolino
Experienced Solver
Experienced Solver
Posts: 77
Joined: Wed Aug 14, 2013 8:07 am
Location: France
Contact:

Re: Is Control key down?

Post by bertolino »

Thanks for the idea OneEyeMan!
I just compiled and run the keyboard sample:
When pressing Control, nothing happens.
When releasing Control, Hook, KeyDown and KeyUp events (in this order) occur.

Pascal
User avatar
doublemax
Moderator
Moderator
Posts: 19114
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Is Control key down?

Post by doublemax »

Use the source, Luke!
bertolino
Experienced Solver
Experienced Solver
Posts: 77
Joined: Wed Aug 14, 2013 8:07 am
Location: France
Contact:

Re: Is Control key down?

Post by bertolino »

Thanks for your answer Doublemax.
Actually, I didn't mention it in my post but I already tested
wxGetKeyState(WXK_CONTROL) and wxGetKeyState(WXK_RAW_CONTROL)
without any success.
That is, the behavior is still the same that I described in my previous post.
I wonder what I'm doing wrong or maybe there's no way it can work (but I would be surprised)...

Pascal
User avatar
doublemax
Moderator
Moderator
Posts: 19114
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Is Control key down?

Post by doublemax »

Which platform and wxWidgets version are you using?
Use the source, Luke!
bertolino
Experienced Solver
Experienced Solver
Posts: 77
Joined: Wed Aug 14, 2013 8:07 am
Location: France
Contact:

Re: Is Control key down?

Post by bertolino »

What a good question you asked!
It allowed me to find the origin of the problem:
I'm developing Windows applications using 2 MacBook Pro,
one with BootCamp, the other one with a virtual Windows
machine
and the issue I encountered was with both of them
(until now, I never had any strange behavior in my
Windows / wxWidgets applications running on a Mac).
Since your last post, I ran the test on a regular PC and it worked fine.
I guess in this issue, wxWidgets (I use 3.1.0) is not incriminated and
the problem is on the side of Bootcamp or the virtual machine management.

By the way, is there somewhere a list of the potential issues when
using wxWidgets applications in these special environments?

Anyway, many thanks for your prompt replies and your valuable help.

Pascal
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7458
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Is Control key down?

Post by ONEEYEMAN »

Hi,
Out of curiosity - which Windows version do you have in Bootcamp and in VM?
Which compiler did you use in both environment?

Maybe it is a compiler + environment which interfere with the testing of the application?

Thank you.
bertolino
Experienced Solver
Experienced Solver
Posts: 77
Joined: Wed Aug 14, 2013 8:07 am
Location: France
Contact:

Re: Is Control key down?

Post by bertolino »

Hello OneEyeMan,

BootCamp : Windows 7 Pro / Visual Studio Pro 2012.
VM (Parallels): Windows 10 Pro / Visual Studio Pro 2015.

The program that works correctly on a regular PC was compiled
in the VM, so it seems that the problem doesn't come from the compiler
itself but from the execution environment.

Best regards from France!

Pascal
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7458
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Is Control key down?

Post by ONEEYEMAN »

Hi,
Yes, if it compiled inside VM and ran successfully on a regular PC that it is definitely a VM.
Do you run VirtualBox or VMWare? Is it possible that the VM software has a hook installed on the Ctrl key for Mac? Or maybe for the key combination you are trying to use?

Thank you.
bertolino
Experienced Solver
Experienced Solver
Posts: 77
Joined: Wed Aug 14, 2013 8:07 am
Location: France
Contact:

Re: Is Control key down?

Post by bertolino »

Hi,
I use Parallels and yes, there are hooks for several keys.
I have to look into this.
Thanks for your suggestion,

Pascal
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7458
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Is Control key down?

Post by ONEEYEMAN »

Hi,
This is exactly the reason I, personally, try to avoid testing on the VM. ;-)
You never know what VE will bring compare to the actual machine with the OS installed.

Thank you.
Post Reply