views:

418

answers:

3

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  A: 

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

http://www.howtogeek.com/forum/topic/shiftctrl0-not-working-in-vista

Then I found this MS knowledgebase article:

"Input method editor keyboard shortcut (CTRL+SHIFT+0) switches the input language in Vista" http://support.microsoft.com/kb/967893

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.

_J_
I found the howtogeek.com article before asking my question. It only states the problem exists, but does not provide a practical solution.
Jan Goyvaerts
+8  A: 

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.

fbonnet
Thanks, that worked. Odd that my searches in Google and Bing didn't find this. I guess the dumb part is that a clean install of Vista with US locale settings has only one keyboard layout and no IME and thus no need for a system-wide hotkey to switch between anything.
Jan Goyvaerts
@Jan: perhaps it would be better if Google allowed Regex searches? ;-)
Argalatyr
Google search turns up this article. How to fix for Windows 7 though?
Warren P
+2  A: 

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

Bruce McGee