Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Arrow key not working in component

I use the Gecko SDK, a component that allows you to view web pages.
I use this component to create an html editor.

This problem happens when going off editing web pages.
The problem is that the arrow keys and the tab does not work with my component. I tried to find an answer to this problem, but I didn't find one. I found a track here, but the function does not work.

Function Movement (dx, dy) does not exist. Thank you for helping me solve this problem.

Procedure Tform1.TraiteMessages(Var msg : TMsg; Var Handled: boolean);
var
  dx, dy : integer;
begin   dx: 0; dy := 0; 
  With msg do
  begin
    IF Message = WM_KEYDOWN then
    Case  wparam of
      VK_LEFT  : dx := -1;
      VK_RIGHT : dx :=  1;
      VK_UP    : dy := -1;
      VK_DOWN  : dy :=  1;
    end;
  end;
  IF (dy = 0) AND (Dx = 0) then Handled := false else
  begin
    handled := true;     // message traité
    Mouvement(dx, dy)    // exécution du tracé 
  end;
end;

1 Answers

Add this to your component's class:

procedure HandleDlgCode(var Msg:TMessage); message WM_GETDLGCODE;

and then in the implementation section:

procedure TComponentClass.HandleDlgCode(var Msg:TMessage);
var
  M: PMsg;
begin
  Msg.Result := DLGC_WANTALLKEYS or DLGC_WANTARROWS or DLGC_WANTCHARS or DLGC_HASSETSEL;
  if Msg.lParam <> 0 then
    begin
      M := PMsg(Msg.lParam);
      case M.message of
        WM_KEYDOWN, WM_KEYUP, WM_CHAR:
        begin
          Perform(M.message, M.wParam, M.lParam);
          Msg.Result := Msg.Result or DLGC_WANTMESSAGE;
        end;
      end;
    end
  else
    Msg.Result := Msg.Result or DLGC_WANTMESSAGE;
end;

I've just copy-pasted this code from my own numeric editor, so it works.

like image 176
Cosmin Prund Avatar answered Sep 20 '25 09:09

Cosmin Prund