Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / April 2007

Tip: Looking for answers? Try searching our database.

how catch combination of key??

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Mohammad Omer - 09 Apr 2007 13:15 GMT
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
David Lowndes - 09 Apr 2007 14:26 GMT
>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
Ben Voigt - 09 Apr 2007 15:34 GMT
> >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
[quoted text clipped - 3 lines]
> 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.

> Dave
Mohammad Omer - 09 Apr 2007 15:42 GMT
> 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
David Lowndes - 09 Apr 2007 17:23 GMT
>> 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.

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.
[quoted text clipped - 4 lines]
>  ...
>}

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

Dave
Mohammad Omer - 10 Apr 2007 06:32 GMT
> >if(nChar == 'V' && (0x8000 & GetKeyState(VK_CONTROL)))
> >{
> >  //do some thing
> >  ...
> >}

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??
David Lowndes - 10 Apr 2007 08:51 GMT
>> >if(nChar == 'V' && (0x8000 & GetKeyState(VK_CONTROL)))
>> >{
[quoted text clipped - 6 lines]
>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
Mohammad Omer - 10 Apr 2007 09:30 GMT
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
David Lowndes - 10 Apr 2007 13:01 GMT
>> Can you explain in more detail what you removed?
>
[quoted text clipped - 8 lines]
>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
Mohammad Omer - 15 Apr 2007 08:06 GMT
> 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
David Lowndes - 15 Apr 2007 09:44 GMT
>> 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
[quoted text clipped - 5 lines]
>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
Mohammad Omer - 16 Apr 2007 00:44 GMT
> 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
David Lowndes - 16 Apr 2007 07:52 GMT
>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
Mohammad Omer - 16 Apr 2007 21:01 GMT
Hi,

Right, Thanks Dave.. :)

Regards,
-aims

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.