how catch combination of key??

M

Mohammad Omer

Hi,

I am working on SDI base application using vs2k5. I need to perform
some task on combination of keys (link ctrl+v). I wrote WM_KEYDOWN
message in my view for control command keys (like Delete, Insert, etc)
but unable to catch combination of keys in WM_KEYDOWN message. I tried
to use GetKeyStatus function in WM_KEYDOWN message but not gets any
positive results. Please guide me, how I can control combination of
keys in WM_KEYDOWN message, like, if I wants to perform some task on
ctrl+v for this, what I do for it??

Regards,

-aims
 
D

David Lowndes

I am working on SDI base application using vs2k5. I need to perform
some task on combination of keys (link ctrl+v). I wrote WM_KEYDOWN
message in my view for control command keys (like Delete, Insert, etc)
but unable to catch combination of keys in WM_KEYDOWN message.

For the situation you mentioned you'd normally create an accelerator
entry for the key combination in the application's resource.

Dave
 
B

Ben Voigt

David Lowndes said:
For the situation you mentioned you'd normally create an accelerator
entry for the key combination in the application's resource.

And be sure to call TranslateMessage from your message loop.
 
M

Mohammad Omer

For the situation you mentioned you'd normally create an accelerator
entry for the key combination in the application's resource.

It will not work for me because I need to perform some actions on ctrl
+v. I tried following code in WM_KEYDOWN which work on ctrl+shift+v
but not working on ctrl+v.

if(nChar == 'V' && (0x8000 & GetKeyState(VK_CONTROL)))
{
//do some thing
...
}

can you please guide me how i can fix this problem??

Regards,
-aims
 
D

David Lowndes

For the situation you mentioned you'd normally create an accelerator
It will not work for me because I need to perform some actions on ctrl
+v.

What do you mean? That's what accelerators are intended for.
I tried following code in WM_KEYDOWN which work on ctrl+shift+v
but not working on ctrl+v.

if(nChar == 'V' && (0x8000 & GetKeyState(VK_CONTROL)))
{
//do some thing
...
}

I can't see any apparent reason why that shouldn't work - what code do
you have for the Ctrl+Shift+V case?

Dave
 
M

Mohammad Omer

if(nChar == 'V' && (0x8000 & GetKeyState(VK_CONTROL)))
Hi Dave!

This code works when I removed all combination related to Ctrl and
Shift keys from Accelerated. The following entries was in my
accelerated file.
Shift+Insert
Ctrl+C
Ctrl+X
But I am not able to understand why it was not working. I was trying
to control Ctrl+V key combination which was not in my accelerated keys
list. Accelerated key has high priority and then pass to messages??
 
M

Mohammad Omer

Dave,
Can you explain in more detail what you removed?

I was making SDI base application and by that time following
information I seen, which includes Ctrl+V as well.

IDR_MAINFRAME ACCELERATORS
BEGIN
"N", ID_FILE_NEW, VIRTKEY,CONTROL
"O", ID_FILE_OPEN, VIRTKEY,CONTROL
"S", ID_FILE_SAVE, VIRTKEY,CONTROL
"P", ID_FILE_PRINT, VIRTKEY,CONTROL
"Z", ID_EDIT_UNDO, VIRTKEY,CONTROL
"X", ID_EDIT_CUT, VIRTKEY,CONTROL
"C", ID_EDIT_COPY, VIRTKEY,CONTROL
"V", ID_EDIT_PASTE, VIRTKEY,CONTROL
VK_BACK, ID_EDIT_UNDO, VIRTKEY,ALT
VK_DELETE, ID_EDIT_CUT, VIRTKEY,SHIFT
VK_INSERT, ID_EDIT_COPY, VIRTKEY,CONTROL
VK_INSERT, ID_EDIT_PASTE, VIRTKEY,SHIFT
VK_F6, ID_NEXT_PANE, VIRTKEY
VK_F6, ID_PREV_PANE, VIRTKEY,SHIFT
END

After that I was removed ID_EDIT_PASTE resource ID from accelerator
table and try to capture Ctrl+V by code but it was not working.. One
by One I removed all entries from accelerator but WM_KEYDOWN message
start working on when no entry left in accelerator table..
By "accelerated file", do you mean the accelerator table resource for
your application - or something else?

I wrote "accelerator file" by mistaken that is accelerator table..

Regards,
-aims
 
D

David Lowndes

if(nChar == 'V' && (0x8000 & GetKeyState(VK_CONTROL)))
Hi Dave!

This code works when I removed all combination related to Ctrl and
Shift keys from Accelerated.

Can you explain in more detail what you removed?
The following entries was in my
accelerated file.
Shift+Insert
Ctrl+C
Ctrl+X

By "accelerated file", do you mean the accelerator table resource for
your application - or something else?
But I am not able to understand why it was not working. I was trying
to control Ctrl+V key combination which was not in my accelerated keys
list.

Which (and what type of) window are you trying to catch these
accelerator key combinations for?

Dave
 
D

David Lowndes

Can you explain in more detail what you removed?
I was making SDI base application and by that time following
information I seen, which includes Ctrl+V as well.

IDR_MAINFRAME ACCELERATORS
BEGIN
...
END

After that I was removed ID_EDIT_PASTE resource ID from accelerator
table and try to capture Ctrl+V by code but it was not working.

OK, I just wanted to be clear that it was the resource accelerator
table you were referring to.
One
by One I removed all entries from accelerator but WM_KEYDOWN message
start working on when no entry left in accelerator table.

I don't immediately know why that should be - are you saying that you
don't receive *any* WM_KEYDOWN messages, or just the ones that had
accelerators defined?

Why do you want to do the key detection in code rather than relying on
the existing accelerator & command messages they will create?

Dave
 
M

Mohammad Omer

I don't immediately know why that should be - are you saying that you
don't receive *any* WM_KEYDOWN messages, or just the ones that had
accelerators defined?

Why do you want to do the key detection in code rather than relying on
the existing accelerator & command messages they will create?

some how accelerators was not working.. thats why, i was write
WM_KEYDOWN message..

Regards,
-aims
 
D

David Lowndes

I don't immediately know why that should be - are you saying that you
some how accelerators was not working.. thats why, i was write
WM_KEYDOWN message..

I think you should find out why they're (apparently) not working for
you - try using Spy++ to see where the command messages for the
accelerator keystrokes are going.

Dave
 
M

Mohammad Omer

I think you should find out why they're (apparently) not working for
you - try using Spy++ to see where the command messages for the
accelerator keystrokes are going.

Hi Dave,

Please guide me, how to use Spy++ to see where the command messages
for the accelerator keystrokes are going?
Will I use "Find Window tool", select Messages Radio button Under
"Show Label" and using Finder Tool check all messages. Is this right
procedure?? Please guide me, In case of wrong.

Regards,

-aims
 
D

David Lowndes

Please guide me, how to use Spy++ to see where the command messages
for the accelerator keystrokes are going?
Will I use "Find Window tool", select Messages Radio button Under
"Show Label" and using Finder Tool check all messages. Is this right
procedure?

Use Log Messages, and its Finder tool to select the top level window
of your application. You can also set the Child Windows check box. In
the messages pane, just select WM_COMMAND. Then try the accelerator
keys and check you do see the command messages being generated.

Assuming you do, then that's proof that the accelerator is working and
you should be able to handle those command messages in your
application.

Dave
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top