Page 1 of 1

Is Control key down?

Posted: Tue Apr 10, 2018 2:36 pm
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

Re: Is Control key down?

Posted: Tue Apr 10, 2018 3:23 pm
by ONEEYEMAN
Hi,
How does it work in the keyboard sample?

Thank you.

Re: Is Control key down?

Posted: Tue Apr 10, 2018 3:38 pm
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

Re: Is Control key down?

Posted: Tue Apr 10, 2018 3:45 pm
by doublemax

Re: Is Control key down?

Posted: Tue Apr 10, 2018 4:01 pm
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

Re: Is Control key down?

Posted: Tue Apr 10, 2018 4:26 pm
by doublemax
Which platform and wxWidgets version are you using?

Re: Is Control key down?

Posted: Wed Apr 11, 2018 7:53 am
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

Re: Is Control key down?

Posted: Wed Apr 11, 2018 2:32 pm
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.

Re: Is Control key down?

Posted: Wed Apr 11, 2018 8:26 pm
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

Re: Is Control key down?

Posted: Wed Apr 11, 2018 8:34 pm
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.

Re: Is Control key down?

Posted: Thu Apr 12, 2018 7:01 am
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

Re: Is Control key down?

Posted: Thu Apr 12, 2018 2:37 pm
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.