Q&A

  • Sendkey 같은거 없나요?
비주얼 베이직에는 Sendkey라고 그 키를 누른 것 같은 효과를 내 주는게 있는데요 델파이에는 그런게 없나요?
1  COMMENTS
  • Profile
    윤광석 2002.02.15 05:01
    예전에 받은 소스에요... 저도 자세히 내용 잘 몰라요..
    한번 참조해보세요...

    procedure PostKeyEx(hWindow : HWnd; Key : Word; const Shift : TShiftState; SpecialKey : Boolean);
    type
      TBuffers = Array[0..1] of TKeyboardState;
    var
      pKeyBuffers : ^TBuffers;
      lParam : LongInt;
    begin
      if IsWindow(hWindow) then
      begin
        pKeyBuffers := nil;
        lParam := MakeLong(0, MapVirtualkey(Key,0));
        if SpecialKey then lParam := lParam or $1000000;
        New(pKeyBuffers);
        try
          GetKeyboardState(pKeyBuffers^[1]);
          FillChar(pKeyBuffers^[0],SizeOf(TKeyboardState), 0);
          if ssShift in Shift then pKeyBuffers^[0][VK_SHIFT] := $80;
          if ssAlt in Shift then
          begin
            pKeyBuffers^[0][VK_MENU] := $80;
            lParam := lParam or $20000000;
          end;
          if ssCtrl   in Shift then pKeyBuffers^[0][VK_CONTROL] := $80;
          if ssRight  in Shift then pKeyBuffers^[0][VK_RBUTTON] := $80;
          if ssLeft   in Shift then pKeyBuffers^[0][VK_LBUTTON] := $80;
          if ssMiddle in Shift then pKeyBuffers^[0][VK_MBUTTON] := $80;
          SetKeyboardState(pKeyBuffers^[0]);
          if ssAlt in Shift then
          begin
            PostMessage(hWindow, WM_SYSKEYDOWN, Key, lParam);
            PostMessage(hWindow, WM_SYSKEYUP, Key, lParam or $C0000000);
          end
          else
          begin
            PostMessage(hWindow, WM_KEYDOWN, Key, lParam);
            PostMessage(hWindow, WM_KEYUP, Key, lParam or $C0000000);
          end;
          Application.ProcessMessages;
          SetKeyboardState(pKeyBuffers^[1]);
        finally
          if pKeyBuffers <> nil then Dispose(pKeybuffers);
        end;
      end;
    end;