11
votes

I start with a new Delphi VCL application, add Menus to the uses clause, drop a label on the form, and assign the form's OnShortCut event:

procedure TForm1.FormShortCut(var Msg: TWMKey; var Handled: Boolean);
begin
  Label1.Caption := ShortCutToText(ShortCut(Msg.CharCode, KeyDataToShiftState(Msg.KeyData)));
end;

On XP, this works correctly for all shortcut key combinations that I've tried, including Shift+Ctrl+0. On Vista and Windows 7, the test application displays Shift+Ctrl+1 through Shift+Ctrl+9, but not Shift+Ctrl+0. Other combinations like Shift+0, Ctrl+0, and even Shift+Ctrl+Alt+0 are displayed fine.

Running the application under the debugger, I find that the OnShortCut event is never fired with Msg.CharCode = Ord('0') if both the Shift and Ctrl keys are held down while the 0 key is pressed.

The Delphi IDE has the same problem under Vista. Ctrl+Shift+1 sets bookmark 1, but Ctrl+Shift+0 does not set bookmark 0, which it should.

I've tested this with Delphi 2007 and 2010 on virgin installs of Windows Vista and 7 in VMware, so there's no 3rd party software trapping the keys. I haven't tried any other development tools to determine if the problem is with Delphi or with Vista itself.

3
Very interesting I just reproduced the behaviour here on Vista with a Delphi 6 app.J__

3 Answers

15
votes

Shift+Ctrl+0 is preassigned in Vista to the input method editor (IME) :

http://support.microsoft.com/kb/967893

This will solve your problem but will impact users of IMEs (mostly asian versions), so you should consider not using this shortcut.

3
votes

It seems you're not the first to ask this, I found this thread on the How-To Geek Forums.

Then I found this MS knowledge base article:

"Input method editor keyboard shortcut (CTRL+SHIFT+0) switches the input language in Vista"

It is used to switch between languages. There is a workaround to turn this off. I just tried it and it works, the application now recognises Ctrl+Shift+0.

3
votes

Try the old school Ctrl+K Ctrl+0 to set bookmark 0.