[Lazarus] Problem with onkeydown

claude.pomalo at free.fr claude.pomalo at free.fr
Thu Sep 16 11:05:48 CEST 2010


Selon zeljko <zeljko at holobit.net>:

> On Thursday 16 September 2010 02:30, claude.pomalo at free.fr wrote:
> > hello
> >
> > I have made a  program with Lazarus. This application make some work
> > according to key pressed from the numpad and function key. It work fine on
> > win32 but i have a big problem with linux-gtk2
> >
> > the action on a key is handled by the OnKeyDown event but on linux, the
> > input in a modal windows is returned in onkeydown from parent and fire the
> > event when return to parent windows.
> > I have tried to disable onKeyDown before showing the modal windows with
> > OnKeyDown := nil
> >
> > and enabling after closing modal windows but the input from modal windows
> > is handled by onkeydown
> >
> > I have try to clear event like when the programm was buid with delphi using
> >
> > While PeekMessage(Msg, 0, LM_KEYFIRST, LM_KEYLAST,1) do
> >
> > but this not work
> >
> > is there a way to clear the keyboard input after the input key is process
> >
> > my development to port this application to linux  is blocked by this
> > problem and i have found no solution
> >
> > many thanks for answer and sorry for my bad english
>
> It's hard to say what to do without code.
> Best would be to attach example here (this is issue opened by you I guess):
> http://bugs.freepascal.org/view.php?id=17387
>
> zeljko
>
> --
> _______________________________________________
> Lazarus mailing list
> Lazarus at lists.lazarus.freepascal.org
> http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
>


thank for your answer

here is my onkeydown handler

Procedure TFmain.FormKeyDown(Sender: TObject; Var Key: Word; Shift:
TShiftState);
Var
  numTouche: integer;
Begin
  if sender = Fmain then
  begin
       If Not act Then
          exit;
       numTouche := 0;
       Case key Of
            VK_1..VK_9:
            Begin
                  numTouche := key - 35;
                  cmd(key,numTouche);
                  exit;
            End;
            219:
            begin
                 cmd(Key,23);
                 exit;
            end;

            187:
            begin
                 cmd(key,24);
                 exit;
            end;
            VK_F1..VK_F12:
            Begin
                 numTouche := key - 111;
                 cmd(key, numTouche);
                 exit;
            End;
            VK_NUMPAD0..VK_NUMPAD9, VK_RETURN, VK_DIVIDE, VK_MULTIPLY, VK_ADD,
VK_SUBTRACT, VK_DECIMAL,
            VK_ESCAPE, VK_OEM_PERIOD:
            begin
                 cmd(key,0);
                 exit;
            End;
       end;
 end
End;

the cmd() function process the key and button on screen (for touchscreen and
mouse) with button on screen no problem but from keyboard the FormKeydown is
process many time after this code

here is a fragment of the function cmd() code

K_F1..VK_F12:
                      Begin
                        // remise a zero panel des erreurs
                        If Ferror = true Then
                          st.Caption := '';

                        // pas de ticket en cours : erreur
                        If Not Fticket Then
                        Begin
                             erreur(ERR_NOTICKET);
                             exit;
                        End;

                        if  FmultiPaiement then
                        begin
                            erreur (ERR_MULTI);
                            exit;
                        end;
                        //le prix n'a pas été saisi
                        If Not Fprix Then
                        Begin
                             erreur(ERR_NOPRIX);
                             exit;
                        End;


                        // touche non programmé
                        If (BtnArray[numTouche].Enabled = false) Then
                        Begin
                                erreur(ERR_NOPROGRAMME);
                                exit;
                        End;
                        LcdLabel.Caption := BtnArray[numTouche].hint;
                        prix := trim(LcdNombre.Caption);
                        dep := LcdLabel.Caption;
                        insere_grille(dep, prix);
                        TotalEnCours(prix, true);
                        // imprime la ligne si une imprimante est active
                        If FescposImprime Then
                        Begin
                             escpos.Add(ticket_formate(dep,prix, InfoEscPos.
                             escpos.PrintLn;
                        End;
                        liste_ajout(dep, prix);
                        Fdepartement := false;
                        Fprix := false;
                        Fsoustotal := false;
                        if extra then
                        begin
                           onKeydown := nil;
                           fextra.showmodal;
                           onkeydown := @FormKeyDown;
                        end;
                        EmptyKeyQueue;
                        exit;
                      End;


returning from fextra.showmodal, refire Onkeydown if close the modal form with
the result of the fextra input

fextra is only a form with a Tedit. I have try with an input function but same
result

emptykeyqueue is code like in my fist post that clear key message


thanks




More information about the Lazarus mailing list