Re: [DUG]: Trapping and using a CTRL-ENTER
Thanks Greg that's just what I wanted. Mark Greg Nixon wrote: > Take out your else contition. The control will hit the KeyDown first but if > you take out the else condition you will get the showmessage('Control > Enter') as you are pressing two keys - (Two keydown events) > > -Original Message- > From: Mark Howard <[EMAIL PROTECTED]> > To: Multiple recipients of list delphi <[EMAIL PROTECTED]> > Date: Monday, 29 March 1999 22:00 > Subject: Re: [DUG]: Trapping and using a CTRL-ENTER > > Thanks to those who responded to this question. I have tried those that > APPEAR > to be the most straightforward. > > Greg I have tried the following code, based on your suggestion. > > procedure TMainForm.DocEntryTrMesEditKeyDown(Sender: TObject; > var Key: Word; Shift: TShiftState); > begin > if ssCtrl in Shift then > begin >if key = vk_return then showmessage('Control Enter') >else >ShowMessage('No Go') >end; > end; > > What I get, though, is a No Go as soon as the Control key is pressed, before > I > press Enter. > What have I missed please. > > Mark > > Greg Nixon wrote: > > > // The Datasource is the controls datasource // > > ShortCutCheckKeyDown(Key, Shift, Datasource); > > > > // Add this procedure to a unit in your library // > > > > Procedure ShortCutCheckKeyDown(var Key: Word; > > var Shift: TShiftState; DbLink: TDatasource); > > begin > >{If not connected to a database don't try anything > > or you will get an AV} > >If DbLink = nil then exit; > >If ssctrl in Shift then begin > > If (dblink.state in [dsInsert, dsedit]) then begin > > If key = vk_return then begin > > dblink.dataset.post; > > Key := 0; > > Shift := []; > > end; > > end; > >end; > > end; > > > > -Original Message- > > From: Mark Howard <[EMAIL PROTECTED]> > > To: Multiple recipients of list delphi <[EMAIL PROTECTED]> > > Date: Sunday, 28 March 1999 20:00 > > Subject: [DUG]: Trapping and using a CTRL-ENTER > > > > Hi guys > > A simple question. > > > > In variety of controls (StringGrid, ComboBox, EditBox) I want to be able > > to detect if the user has pressed a CTRL-ENTER combination. > > If he has, I want to invoke the Save procedure. If CTRL-ENTER is NOT > > pressed, the control should just handle the key-press as it usually > > does. > > This is to save the user having to hunt for the mouse and the SAVE > > button, if they prefer. > > > > Can someone please give me a short example of how you would detect and > > use this, I can't find any examples of the use of OnKeyDown in the > > documentation. > > eg (in pseudo code) an OnKeyDown event: > > if (Key = Chr(13) and ShiftState = ssCtrl) then SaveStuff > > > > In a similar vein - is it possible to detect the pressing of TAB before > > it does what it does, ie moves focus to the next control? > > > > -- > - > > New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED] > > Website: http://www.delphi.org.nz > > > > -- > - > > New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED] > > Website: http://www.delphi.org.nz > > --- > New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED] > Website: http://www.delphi.org.nz > > --- > New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED] > Website: http://www.delphi.org.nz --- New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED] Website: http://www.delphi.org.nz
Re: [DUG]: Trapping and using a CTRL-ENTER
Al Yes - the VK_xxx constants are defined in Windows.Pas - Note that if you want to check A .. Z then you must use something like GetKeyState(Ord('A')) ... -Original Message- From: Alistair George <[EMAIL PROTECTED]> To: Multiple recipients of list delphi <[EMAIL PROTECTED]> Date: Tuesday, 30 March 1999 10:19 Subject: RE: [DUG]: Trapping and using a CTRL-ENTER Hey Paul; are you actually getting it to work by putting VK_RETURN there? My compiler screws its nose unless I use ascii. Cheers, Al+ > procedure TForm1.FormKeyUp(Sender: TObject; var Key: Word; > Shift: TShiftState); > begin > if (Key = VK_RETURN) and (GetKeyState(VK_CONTROL) and $80 <> 0) then > begin > // do stuff > end; > end; --- New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED] Website: http://www.delphi.org.nz --- New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED] Website: http://www.delphi.org.nz
RE: [DUG]: Trapping and using a CTRL-ENTER
Hey Paul; are you actually getting it to work by putting VK_RETURN there? My compiler screws its nose unless I use ascii. Cheers, Al+ > procedure TForm1.FormKeyUp(Sender: TObject; var Key: Word; > Shift: TShiftState); > begin > if (Key = VK_RETURN) and (GetKeyState(VK_CONTROL) and $80 <> 0) then > begin > // do stuff > end; > end; --- New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED] Website: http://www.delphi.org.nz
Re: [DUG]: Trapping and using a CTRL-ENTER
Mark I should have said if (Key = VK_RETURN) and (ssCtrl in Shift) then I must be getting old :-( Mind you the other way is useful for any key as it looks at the state of the key at the time the API call is executed so you can use any key combinations. In fact by using GetKeyboardState you should be able to use whole handfuls of key combinations !! -Original Message- From: Paul Lowman <[EMAIL PROTECTED]> To: [EMAIL PROTECTED] <[EMAIL PROTECTED]> Date: Tuesday, 30 March 1999 09:56 Subject: Re: [DUG]: Trapping and using a CTRL-ENTER >Mark try this (or something like it) > >procedure TForm1.FormKeyUp(Sender: TObject; var Key: Word; > Shift: TShiftState); >begin > if (Key = VK_RETURN) and (GetKeyState(VK_CONTROL) and $80 <> 0) then > begin >// do stuff > end; >end; --- New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED] Website: http://www.delphi.org.nz
Re: [DUG]: Trapping and using a CTRL-ENTER
Mark try this (or something like it) procedure TForm1.FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState); begin if (Key = VK_RETURN) and (GetKeyState(VK_CONTROL) and $80 <> 0) then begin // do stuff end; end; To: Multiple recipients of list delphi <[EMAIL PROTECTED]> > Date: Sunday, 28 March 1999 20:00 > Subject: [DUG]: Trapping and using a CTRL-ENTER > > Hi guys > A simple question. > > In variety of controls (StringGrid, ComboBox, EditBox) I want to be able > to detect if the user has pressed a CTRL-ENTER combination. > If he has, I want to invoke the Save procedure. If CTRL-ENTER is NOT > pressed, the control should just handle the key-press as it usually > does. --- New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED] Website: http://www.delphi.org.nz
Re: [DUG]: Trapping and using a CTRL-ENTER
Take out your else contition. The control will hit the KeyDown first but if you take out the else condition you will get the showmessage('Control Enter') as you are pressing two keys - (Two keydown events) -Original Message- From: Mark Howard <[EMAIL PROTECTED]> To: Multiple recipients of list delphi <[EMAIL PROTECTED]> Date: Monday, 29 March 1999 22:00 Subject: Re: [DUG]: Trapping and using a CTRL-ENTER Thanks to those who responded to this question. I have tried those that APPEAR to be the most straightforward. Greg I have tried the following code, based on your suggestion. procedure TMainForm.DocEntryTrMesEditKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); begin if ssCtrl in Shift then begin if key = vk_return then showmessage('Control Enter') else ShowMessage('No Go') end; end; What I get, though, is a No Go as soon as the Control key is pressed, before I press Enter. What have I missed please. Mark Greg Nixon wrote: > // The Datasource is the controls datasource // > ShortCutCheckKeyDown(Key, Shift, Datasource); > > // Add this procedure to a unit in your library // > > Procedure ShortCutCheckKeyDown(var Key: Word; > var Shift: TShiftState; DbLink: TDatasource); > begin >{If not connected to a database don't try anything > or you will get an AV} >If DbLink = nil then exit; >If ssctrl in Shift then begin > If (dblink.state in [dsInsert, dsedit]) then begin > If key = vk_return then begin > dblink.dataset.post; > Key := 0; > Shift := []; > end; > end; >end; > end; > > -Original Message- > From: Mark Howard <[EMAIL PROTECTED]> > To: Multiple recipients of list delphi <[EMAIL PROTECTED]> > Date: Sunday, 28 March 1999 20:00 > Subject: [DUG]: Trapping and using a CTRL-ENTER > > Hi guys > A simple question. > > In variety of controls (StringGrid, ComboBox, EditBox) I want to be able > to detect if the user has pressed a CTRL-ENTER combination. > If he has, I want to invoke the Save procedure. If CTRL-ENTER is NOT > pressed, the control should just handle the key-press as it usually > does. > This is to save the user having to hunt for the mouse and the SAVE > button, if they prefer. > > Can someone please give me a short example of how you would detect and > use this, I can't find any examples of the use of OnKeyDown in the > documentation. > eg (in pseudo code) an OnKeyDown event: > if (Key = Chr(13) and ShiftState = ssCtrl) then SaveStuff > > In a similar vein - is it possible to detect the pressing of TAB before > it does what it does, ie moves focus to the next control? > > -- - > New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED] > Website: http://www.delphi.org.nz > > -- - > New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED] > Website: http://www.delphi.org.nz --- New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED] Website: http://www.delphi.org.nz --- New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED] Website: http://www.delphi.org.nz
RE: [DUG]: Trapping and using a CTRL-ENTER
Sorry, I dont have the time to actually try this but I suspect the keyscan routine is providing the keys as they are scanned into the serial keyboard buffer, in other words, one always comes before the other even though they are pressed together. If thats the case, then trap the keyfound key as below: > procedure TMainForm.DocEntryTrMesEditKeyPress(Sender: TObject; > var Key: Char); > begin if keyfound=key then exit; >if (keyfound = #10) and (key = #13) then ShowMessage('Control Enter') > else > ShowMessage('No Go'); > keyfound:=key; {dont forget to reset keyfound after you have finished with it} > end; > > First problem : My keyboard seems to be generating an ascii 10 > (not 17) for the > control key. Which should it be? > Second problem: When I press a Ctrl/Enter combination I get No Go > but when I > press them in sequence I get Control Enter. > > What am I missing please? > > Thanks > Mark > > Alistair George wrote: > > > VK_CONTROL = 17; > > VK_RETURN = 13; {same as ENTER} > > > > OR you could do a combo key like follows (define keyfound as a global > > variable) > > procedure TCamForm.FormKeyPress(Sender: TObject; var Key: Char); > > begin > > {NB a case expression would be better if u were only gonna use > ascii values} > > if keyfound=#9 {tab} > > and key=#101 then > > ShowMessage('Haha, Tab was first') > > else > > if keyfound=#9 > > and key='e'{instead of writing ascii} > > then > > ShowMessage('Haha, Tab was LAST'); > > end; > > keyfound:=key; > > exit; > > > > Typically, for menu Ctrl-X for exit, once you have set up mainform for > > key-preview then you just double click your menu component, > select the menu > > item eg Exit, Ctrl-X in the object inspector shortcut for that > particular > > menu item. > > Easypeasy. > > Alistair+ > > > -Original Message- > > > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]On > > > Behalf Of Mark Howard > > > Sent: Sunday, 28 March 1999 15:45 > > > To: Multiple recipients of list delphi > > > Subject: [DUG]: Trapping and using a CTRL-ENTER > > > > > > > > > Hi guys > > > A simple question. > > > > > > In variety of controls (StringGrid, ComboBox, EditBox) I want > to be able > > > to detect if the user has pressed a CTRL-ENTER combination. > > > If he has, I want to invoke the Save procedure. If CTRL-ENTER is NOT > > > pressed, the control should just handle the key-press as it usually > > > does. > > > This is to save the user having to hunt for the mouse and the SAVE > > > button, if they prefer. > > > > > > Can someone please give me a short example of how you would detect and > > > use this, I can't find any examples of the use of OnKeyDown in the > > > documentation. > > > eg (in pseudo code) an OnKeyDown event: > > > if (Key = Chr(13) and ShiftState = ssCtrl) then SaveStuff > > > > > > In a similar vein - is it possible to detect the pressing of > TAB before > > > it does what it does, ie moves focus to the next control? > > > > > > > > > -- > > > - > > > New Zealand Delphi Users group - Delphi List - > [EMAIL PROTECTED] > > > Website: http://www.delphi.org.nz > > > > > > > > -- > - > > New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED] > > Website: http://www.delphi.org.nz > > > > -- > - > New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED] > Website: http://www.delphi.org.nz > --- New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED] Website: http://www.delphi.org.nz
Re: [DUG]: Trapping and using a CTRL-ENTER
Thanks to those who responded to this question. I have tried those that APPEAR to be the most straightforward. Greg I have tried the following code, based on your suggestion. procedure TMainForm.DocEntryTrMesEditKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); begin if ssCtrl in Shift then begin if key = vk_return then showmessage('Control Enter') else ShowMessage('No Go') end; end; What I get, though, is a No Go as soon as the Control key is pressed, before I press Enter. What have I missed please. Mark Greg Nixon wrote: > // The Datasource is the controls datasource // > ShortCutCheckKeyDown(Key, Shift, Datasource); > > // Add this procedure to a unit in your library // > > Procedure ShortCutCheckKeyDown(var Key: Word; > var Shift: TShiftState; DbLink: TDatasource); > begin >{If not connected to a database don't try anything > or you will get an AV} >If DbLink = nil then exit; >If ssctrl in Shift then begin > If (dblink.state in [dsInsert, dsedit]) then begin > If key = vk_return then begin > dblink.dataset.post; > Key := 0; > Shift := []; > end; > end; >end; > end; > > -Original Message- > From: Mark Howard <[EMAIL PROTECTED]> > To: Multiple recipients of list delphi <[EMAIL PROTECTED]> > Date: Sunday, 28 March 1999 20:00 > Subject: [DUG]: Trapping and using a CTRL-ENTER > > Hi guys > A simple question. > > In variety of controls (StringGrid, ComboBox, EditBox) I want to be able > to detect if the user has pressed a CTRL-ENTER combination. > If he has, I want to invoke the Save procedure. If CTRL-ENTER is NOT > pressed, the control should just handle the key-press as it usually > does. > This is to save the user having to hunt for the mouse and the SAVE > button, if they prefer. > > Can someone please give me a short example of how you would detect and > use this, I can't find any examples of the use of OnKeyDown in the > documentation. > eg (in pseudo code) an OnKeyDown event: > if (Key = Chr(13) and ShiftState = ssCtrl) then SaveStuff > > In a similar vein - is it possible to detect the pressing of TAB before > it does what it does, ie moves focus to the next control? > > --- > New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED] > Website: http://www.delphi.org.nz > > --- > New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED] > Website: http://www.delphi.org.nz --- New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED] Website: http://www.delphi.org.nz
Re: [DUG]: Trapping and using a CTRL-ENTER
Alistair Thanks for your reply. I have tried the following, based on your suggestion but I still have problems. procedure TMainForm.DocEntryTrMesEditKeyPress(Sender: TObject; var Key: Char); begin if (keyfound = #10) and (key = #13) then ShowMessage('Control Enter') else ShowMessage('No Go'); keyfound:=key; end; First problem : My keyboard seems to be generating an ascii 10 (not 17) for the control key. Which should it be? Second problem: When I press a Ctrl/Enter combination I get No Go but when I press them in sequence I get Control Enter. What am I missing please? Thanks Mark Alistair George wrote: > VK_CONTROL = 17; > VK_RETURN = 13; {same as ENTER} > > OR you could do a combo key like follows (define keyfound as a global > variable) > procedure TCamForm.FormKeyPress(Sender: TObject; var Key: Char); > begin > {NB a case expression would be better if u were only gonna use ascii values} > if keyfound=#9 {tab} > and key=#101 then > ShowMessage('Haha, Tab was first') > else > if keyfound=#9 > and key='e'{instead of writing ascii} > then > ShowMessage('Haha, Tab was LAST'); > end; > keyfound:=key; > exit; > > Typically, for menu Ctrl-X for exit, once you have set up mainform for > key-preview then you just double click your menu component, select the menu > item eg Exit, Ctrl-X in the object inspector shortcut for that particular > menu item. > Easypeasy. > Alistair+ > > -Original Message- > > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]On > > Behalf Of Mark Howard > > Sent: Sunday, 28 March 1999 15:45 > > To: Multiple recipients of list delphi > > Subject: [DUG]: Trapping and using a CTRL-ENTER > > > > > > Hi guys > > A simple question. > > > > In variety of controls (StringGrid, ComboBox, EditBox) I want to be able > > to detect if the user has pressed a CTRL-ENTER combination. > > If he has, I want to invoke the Save procedure. If CTRL-ENTER is NOT > > pressed, the control should just handle the key-press as it usually > > does. > > This is to save the user having to hunt for the mouse and the SAVE > > button, if they prefer. > > > > Can someone please give me a short example of how you would detect and > > use this, I can't find any examples of the use of OnKeyDown in the > > documentation. > > eg (in pseudo code) an OnKeyDown event: > > if (Key = Chr(13) and ShiftState = ssCtrl) then SaveStuff > > > > In a similar vein - is it possible to detect the pressing of TAB before > > it does what it does, ie moves focus to the next control? > > > > > > -- > > - > > New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED] > > Website: http://www.delphi.org.nz > > > > --- > New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED] > Website: http://www.delphi.org.nz --- New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED] Website: http://www.delphi.org.nz
RE: [DUG]: Trapping and using a CTRL-ENTER
How about putting a Menu Item (PopUP/File/Save?) on the form and setting it's shortcut key to CTRL-ENTER?? For this Key combination you would have to set the shortcut CTRL-ENTER combination using code. Myles. Hi guys A simple question. In variety of controls (StringGrid, ComboBox, EditBox) I want to be able to detect if the user has pressed a CTRL-ENTER combination. If he has, I want to invoke the Save procedure. If CTRL-ENTER is NOT pressed, the control should just handle the key-press as it usually does. This is to save the user having to hunt for the mouse and the SAVE button, if they prefer. Can someone please give me a short example of how you would detect and use this, I can't find any examples of the use of OnKeyDown in the documentation. eg (in pseudo code) an OnKeyDown event: if (Key = Chr(13) and ShiftState = ssCtrl) then SaveStuff In a similar vein - is it possible to detect the pressing of TAB before it does what it does, ie moves focus to the next control? --- New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED] Website: http://www.delphi.org.nz --- New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED] Website: http://www.delphi.org.nz application/ms-tnef
Re: [DUG]: Trapping and using a CTRL-ENTER
In your keydown event add the following (I have an exteaded version I used within my controls so I don't have to add it in code all the time) // The Datasource is the controls datasource // ShortCutCheckKeyDown(Key, Shift, Datasource); // Add this procedure to a unit in your library // Procedure ShortCutCheckKeyDown(var Key: Word; var Shift: TShiftState; DbLink: TDatasource); begin {If not connected to a database don't try anything or you will get an AV} If DbLink = nil then exit; If ssctrl in Shift then begin If (dblink.state in [dsInsert, dsedit]) then begin If key = vk_return then begin dblink.dataset.post; Key := 0; Shift := []; end; end; end; end; -Original Message- From: Mark Howard <[EMAIL PROTECTED]> To: Multiple recipients of list delphi <[EMAIL PROTECTED]> Date: Sunday, 28 March 1999 20:00 Subject: [DUG]: Trapping and using a CTRL-ENTER Hi guys A simple question. In variety of controls (StringGrid, ComboBox, EditBox) I want to be able to detect if the user has pressed a CTRL-ENTER combination. If he has, I want to invoke the Save procedure. If CTRL-ENTER is NOT pressed, the control should just handle the key-press as it usually does. This is to save the user having to hunt for the mouse and the SAVE button, if they prefer. Can someone please give me a short example of how you would detect and use this, I can't find any examples of the use of OnKeyDown in the documentation. eg (in pseudo code) an OnKeyDown event: if (Key = Chr(13) and ShiftState = ssCtrl) then SaveStuff In a similar vein - is it possible to detect the pressing of TAB before it does what it does, ie moves focus to the next control? --- New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED] Website: http://www.delphi.org.nz --- New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED] Website: http://www.delphi.org.nz