library ssdll;

uses
  Windows, Messages;

const
  SysHook : HHook = 0;
  flag : boolean = true;
  Password : word = 0;
  Wnd : Hwnd = 0;

function SysMsgProc(code : integer; wParam : word; lParam : longint) : longint; export; stdcall;
begin
  Result := CallNextHookEx(SysHook, Code, wParam, lParam);
  if code = HC_ACTION
  then
    begin
      Wnd := TMsg(Pointer(lParam)^).hwnd;
      case TMsg(Pointer(lParam)^).message of
        WM_LBUTTONDOWN : if (
                            ((TMsg(Pointer(lParam)^).wParam and MK_CONTROL) = MK_CONTROL) and
                            ((TMsg(Pointer(lParam)^).wParam and MK_SHIFT) = MK_SHIFT)
                            )
                         then
                           if flag and (Password = 0)
                           then
                             begin
                               Password := SendMessage(Wnd, em_getpasswordchar, 0, 0);
                               if Password <> 0
                               then
                                 begin
                                   SendMessage(Wnd, em_setpasswordchar, 0, 0);
                                   InvalidateRect(Wnd, nil, true);
                                   flag := false;
                                 end
                             end;
        WM_LBUTTONUP : if (
                          ((TMsg(Pointer(lParam)^).wParam and MK_CONTROL) = MK_CONTROL) and
                          ((TMsg(Pointer(lParam)^).wParam and MK_SHIFT) = MK_SHIFT)
                          )
                       then
                         if (not Flag) and (Password <> 0)
                         then
                           begin
                             SendMessage(Wnd, em_setpasswordchar, Password, 0);
                             InvalidateRect(Wnd, nil, true);
                             flag := true;
                             Password := 0;
                           end;
      end;
      Result := 0;
    end
end;

function SetHook(Hook : Boolean) : Boolean; export; stdcall;
begin
  Result := false;
  if Hook
  then
    begin
      if SysHook = 0
      then
        SysHook := SetWindowsHookEx(WH_GETMESSAGE{WH_CALLWNDPROC}, @SysMsgProc, HInstance, 0);
      Result := (SysHook <> 0);
    end
  else
    begin
      if SysHook <> 0
      then
        begin
          UnhookWindowsHookEx(SysHook);
          SysHook := 0;
          Result := true;
        end;
    end;
end;

exports
  SETHOOK index 1;

begin
end.
