Sorry if you did not want this but I think you will.

This code will open/close the properties with a + next to them in the object
inspector by clicking the + key, or the -

I modified it slighly for D4. I first found it ages ago for D2, but lost it.
I found it tonight, and thought that most people on the list would be
interested.

I wish Borland included some code like this in the object inspector by
default.

Just install it into a package.
================================================================
Unit Ext_IDE;

interface

procedure Register;

implementation

uses
  Windows, Dialogs, Messages, SysUtils, Classes, Forms;

var
 IsDelphi4 : Boolean;

function Keypressed_at_Anywhere(Key: WParam; Shift: TShiftState): Boolean;
var
  Eat_Key: Boolean;
begin
  Eat_Key:= False;  // do not eat the key by default


  // Single Key pressed
  if (Shift = []) or (Shift = [ssShift]) then
    Case Key Of
      VK_F10: ;
    End;


  // Ctrl Key pressed
  if ssCtrl in Shift then
    Case Key Of
      ord('0'): ;
      ord('1'): ;
      {...}
      ord('Y'): ;
      ord('Z'): ;
      VK_F2: ;
      VK_F3: ;
      VK_F5: ;
      VK_F6: ;
      VK_F10: ;
      VK_F11: ;
    End;


  // Alt Key pressed
  if ssAlt in Shift then
    Case Key Of
      ord('1'): ;
      ord('2'): ;
      {...}
      ord('Y'): ;
      ord('Z'): ;
      VK_F1: ;
      VK_F2: ;
      VK_F5: ;
      VK_F7: ;
      VK_F8: ;
      VK_F9: ;
      VK_F11: ;
      VK_F12: ;
    End;

  Keypressed_at_Anywhere:= Eat_Key;
end;

function GetObjInspListBox(WinHndle: HWnd; lPar: LongInt): BOOL; stdcall;
var
  CurrentClass: Array[0..100] of Char;
  OK : Boolean;
begin
  CurrentClass[0]:= #0;
  GetClassName(WinHndle, CurrentClass, sizeOf(CurrentClass)-1);
  OK := False;
  if (IsDelphi4) then
   begin
    if StrIComp(CurrentClass, 'TInspListBox') = 0 then
      OK:= TRUE;
   end
  else if StrIComp(CurrentClass, 'TPropListBox') = 0 then
    OK := TRUE;
  if (OK) then
   begin
    {we found the ListBox of Objectinspector}
    PLongInt(lPar)^:= WinHndle;
    GetObjInspListBox:= False;
   end
   else
    GetObjInspListBox:= True;
end;

function Keypressed_at_ObjectInspector(Key: WParam; Shift: TShiftState):
Boolean;
var
  Eat_Key: Boolean;
  ObjInspListHandle: LongInt;
  CurrentSel: Integer;
  CurrentItemRect: TRect;
begin
  Eat_Key:= False;  // do not eat the key by default


  // Single Key pressed at Objectinspector
  if (Shift = []) or (Shift = [ssShift]) then begin
    if Key in [VK_ADD, VK_SUBTRACT, VKKeyScan('+'), VKKeyScan('-'),
VK_RETURN] then
      begin
      ObjInspListHandle:= 0;
      EnumChildWindows(GetActiveWindow, @GetObjInspListBox,
LongInt(@ObjInspListHandle));
      if ObjInspListHandle <> 0 then
        begin
        CurrentSel:= SendMessage(ObjInspListHandle, LB_GETCURSEL, 0, 0);
        if CurrentSel <> LB_ERR then
          if SendMessage(ObjInspListHandle, LB_GETITEMRECT, CurrentSel,
                         LongInt(@CurrentItemRect)) <> LB_ERR then
            SendMessage(ObjInspListHandle, WM_LBUTTONDBLCLK, MK_LBUTTON,
                        MakeLong(CurrentItemRect.Left,
CurrentItemRect.Top));
      end
    else
      ShowMessage('Can''t find the list box');

    end;
  end;


  // Ctrl Key pressed at Objectinspector
  if ssCtrl in Shift then
    Case Key Of
      ord('0'): ;
      ord('1'): ;
      {...}
      ord('Y'): ;
      ord('Z'): ;
      VK_F2: ;
      VK_F3: ;
      VK_F5: ;
      VK_F6: ;
      VK_F10: ;
      VK_F11: ;
    End;


  // Alt Key pressed at Objectinspector
  if ssAlt in Shift then
    Case Key Of
      ord('1'): ;
      ord('2'): ;
      {...}
      ord('Y'): ;
      ord('Z'): ;
      VK_F1: ;
      VK_F2: ;
      VK_F5: ;
      VK_F7: ;
      VK_F8: ;
      VK_F9: ;
      VK_F11: ;
      VK_F12: ;
    End;

  Keypressed_at_ObjectInspector:= Eat_Key;
end;

function Keypressed_at_EditWindow(Key: WParam; Shift: TShiftState): Boolean;
var
  Eat_Key: Boolean;
begin
  Eat_Key:= False;  // do not eat the key by default

  // Single Key pressed at EditWindow
  if (Shift = []) or (Shift = [ssShift]) then
    Case Key Of
      ord('0'): ;
      ord('1'): ;
      {...}
      ord('Y'): ;
      ord('Z'): ;
    End;

  // Ctrl Key pressed at EditWindow
  if ssCtrl in Shift then
    Case Key Of
      ord('0'): ;
      ord('1'): ;
      {...}
      ord('Y'): ;
      ord('Z'): ;
      VK_F2: ;
      VK_F3: ;
      VK_F5: ;
      VK_F6: ;
      VK_F10: ;
      VK_F11: ;
    End;

  // Alt Key pressed at EditWindow
  if ssAlt in Shift then
    Case Key Of
      ord('1'): ;
      ord('2'): ;
      {...}
      ord('Y'): ;
      ord('Z'): ;
      VK_F1: ;
      VK_F2: ;
      VK_F5: ;
      VK_F7: ;
      VK_F8: ;
      VK_F9: ;
      VK_F11: ;
      VK_F12: ;
    End;

  Keypressed_at_EditWindow:= Eat_Key;
end;

function Keypressed_at_MenuWindow(Key: WParam; Shift: TShiftState): Boolean;
var
  Eat_Key: Boolean;
begin
  Eat_Key:= False;  // do not eat the key by default


  // Single Key pressed at MenuWindow
  if (Shift = []) or (Shift = [ssShift]) then
    Case Key Of
      ord('0'): ;
      ord('1'): ;
      {...}
      ord('Y'): ;
      ord('Z'): ;
    End;

  // Ctrl Key pressed at MenuWindow
  if ssCtrl in Shift then
    Case Key Of
      ord('0'): ;
      ord('1'): ;
      {...}
      ord('Y'): ;
      ord('Z'): ;
      VK_F2: ;
      VK_F3: ;
      VK_F5: ;
      VK_F6: ;
      VK_F10: ;
      VK_F11: ;
    End;

  // Alt Key pressed at MenuWindow
  if ssAlt in Shift then
    Case Key Of
      ord('1'): ;
      ord('2'): ;
      {...}
      ord('Y'): ;
      ord('Z'): ;
      VK_F1: ;
      VK_F2: ;
      VK_F5: ;
      VK_F7: ;
      VK_F8: ;
      VK_F9: ;
      VK_F11: ;
      VK_F12: ;
    End;

  Keypressed_at_MenuWindow:= Eat_Key;
end;


{---------------------------------------------------------------------------
-------------------
                  KeyBoard - Filter
----------------------------------------------------------------------------
-------------------}
var
  ExtIDE_KBDHookHandle: HHook;

function KeyBoardHookProc(nCode: Integer; Charcode: WPARAM; KeyData:
LPARAM): DWORD;
stdcall;
var
  CurrentWindowClass: Array[0..100] of Char;
  EatTheKey: Boolean;
  CurrentShiftState: TShiftState;
Begin
  if (nCode < 0) or (nCode <> HC_ACTION) then begin
    KeyBoardHookProc:= CallNextHookEx(ExtIDE_KBDHookHandle, nCode, CharCode,
KeyData);
    Exit;
  End;

  {(lParam and $80000000) = 0 ,wenn Taste gedr�ckt wurde
   (lParam and $80000000) <> 0 ,wenn Taste losgelassen wurde}
  if (KeyData and $80000000) <> 0 then begin
    KeyBoardHookProc:= CallNextHookEx(ExtIDE_KBDHookHandle, 0, Charcode,
KeyData);
    Exit;
  end;

  CurrentShiftState:= KeyDataToShiftState(KeyData);
  EatTheKey:= Keypressed_at_Anywhere(CharCode, CurrentShiftState);

  if not EatTheKey and (GetClassName(GetActiveWindow, CurrentWindowClass,
                                     sizeOf(CurrentWindowClass)-1) > 0) then
begin
    if StrIComp(CurrentWindowClass, 'TPropertyInspector') = 0 then
      Keypressed_at_ObjectInspector(CharCode, CurrentShiftState)
    else if StrIComp(CurrentWindowClass, 'TEditWindow') = 0 then
      Keypressed_at_EditWindow(CharCode, CurrentShiftState)
    else if StrIComp(CurrentWindowClass, 'TAppBuilder') = 0 then
      Keypressed_at_MenuWindow(CharCode, CurrentShiftState);
  end;

  if not EatTheKey then
    {put Key into the system queue again}
    KeyBoardHookProc:= CallNextHookEx(ExtIDE_KBDHookHandle, 0, CharCode,
KeyData)
  else
    KeyBoardHookProc:= 1;
End;

procedure Register;
begin
  // no component to register
end;

var
  CurrProgram: Array[0..255] of Char;

initialization
  ExtIDE_KBDHookHandle:= 0;
  CurrProgram[0]:= #0;
  GetModuleFileName(hInstance, CurrProgram, sizeOf(CurrProgram)-1);
  {loaded into IDE?}
  if (UpperCase(ExtractFileExt(CurrProgram)) = '.BPL') then // Delphi 4
    IsDelphi4 := TRUE
  else
    IsDelphi4 := FALSE;

  if (UpperCase(ExtractFileExt(CurrProgram)) = '.DCL') or // Delphi 2
     (UpperCase(ExtractFileExt(CurrProgram)) = '.DPL') or // Delphi 3
     (UpperCase(ExtractFileExt(CurrProgram)) = '.BPL') or // Delphi 4
     (UpperCase(ExtractFileExt(CurrProgram)) = '.CCL') then // C++Builder 1
      begin
    ExtIDE_KBDHookHandle:= SetWindowsHookEx(wh_KeyBoard,
TFNHookProc(@KeyBoardHookProc),
                                          0, GetCurrentThreadId);
     end;
finalization
  {remove Keyboard-Hook if Delphi shuts down}
  if (ExtIDE_KBDHookHandle <> 0) then
    UnHookWindowsHookEx(ExtIDE_KBDHookHandle);
End.

---------------------------------------------------------------------------
    New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
                  Website: http://www.delphi.org.nz

Reply via email to