Board index » delphi » Shift+Del Keys Not Being 'Seen'

Shift+Del Keys Not Being 'Seen'

I'm having a real problem trying to get my ListView component in my
form to catch Shift/Del when I want to delete some data from the
listview and with the shift key held down.

This used to work and now it does not - I can't remember the last time
I tried it but last month I moved my files over to a new notebook
computer that has win98 (ugh!) on it - my old sys had win95.  I also
upgraded to Delphi 3.02 while I was at it.

I have the code to do the delete working fine, it's just that the
KeyPress event won't 'see' the Shift/Del combination:

if (Key = 46) and ([ssShift] = Shift) then

When I press Shift and Del, Key value is 16 (the shift key) and not 46
the Del key as I believe it should be.  Shift == ssShift so that's OK.

The form's KeyPreview property is set to True.

Any thoughts appreciated...

Ralph

 

Re:Shift+Del Keys Not Being 'Seen'


Quote
Ralph Freshour wrote:

> I'm having a real problem trying to get my ListView component in my
> form to catch Shift/Del when I want to delete some data from the
> listview and with the shift key held down.

> This used to work and now it does not - I can't remember the last time
> I tried it but last month I moved my files over to a new notebook
> computer that has win98 (ugh!) on it - my old sys had win95.  I also
> upgraded to Delphi 3.02 while I was at it.

> I have the code to do the delete working fine, it's just that the
> KeyPress event won't 'see' the Shift/Del combination:

> if (Key = 46) and ([ssShift] = Shift) then

> When I press Shift and Del, Key value is 16 (the shift key) and not 46
> the Del key as I believe it should be.  Shift == ssShift so that's OK.

> The form's KeyPreview property is set to True.

> Any thoughts appreciated...

> Ralph

Maybe some codes have changed. There are pre-defined constants for the keys
(they start with VK_) Try this in the OnKeyDown event:

  if (Key = VK_DELETE) and (Shift = [ssShift]) then ...

Sasan.

Re:Shift+Del Keys Not Being 'Seen'


Good idea - I tried that but it still did not work!! - there must be
something else going on here but I can't figure out what it is.

Ralph

On Mon, 11 Jan 1999 17:51:09 +0100, Sasan Adami

Quote
<s.ad...@its.tudelft.nl> wrote:

>Ralph Freshour wrote:

>> I'm having a real problem trying to get my ListView component in my
>> form to catch Shift/Del when I want to delete some data from the
>> listview and with the shift key held down.

>> This used to work and now it does not - I can't remember the last time
>> I tried it but last month I moved my files over to a new notebook
>> computer that has win98 (ugh!) on it - my old sys had win95.  I also
>> upgraded to Delphi 3.02 while I was at it.

>> I have the code to do the delete working fine, it's just that the
>> KeyPress event won't 'see' the Shift/Del combination:

>> if (Key = 46) and ([ssShift] = Shift) then

>> When I press Shift and Del, Key value is 16 (the shift key) and not 46
>> the Del key as I believe it should be.  Shift == ssShift so that's OK.

>> The form's KeyPreview property is set to True.

>> Any thoughts appreciated...

>> Ralph

>Maybe some codes have changed. There are pre-defined constants for the keys
>(they start with VK_) Try this in the OnKeyDown event:

>  if (Key = VK_DELETE) and (Shift = [ssShift]) then ...

>Sasan.

Re:Shift+Del Keys Not Being 'Seen'


The problem is "(Shift = [ssShift])"

Try instead:
  if (ssShift in Shift) and (Key=VK_delete) then....

--
----------------------
Regards
Robert Cerny
Remove both qwe when replying
email: robert.qwe.ce...@neosys.xrs.qwe.si

No questions via email, unless explicitly invited.

Quote
Ralph Freshour wrote in message <369ab583.1056...@news.mindspring.com>...

Re:Shift+Del Keys Not Being 'Seen'


On Tue, 12 Jan 1999 05:11:20 GMT, "John smith"

Quote
<johnsm...@microsoft.com> wrote:
>The problem is "(Shift = [ssShift])"

>Try instead:
>  if (ssShift in Shift) and (Key=VK_delete) then....

Thanks for the help John - ssShift is defined in a set by Delphi and
as such must be bracketed as in [ssShift] - your suggested line
(unless there is a typo in it that I cannot see) does not even compile
- additional thoughts most welcome...

Ralph

Quote

>--
>----------------------
>Regards
>Robert Cerny
>Remove both qwe when replying
>email: robert.qwe.ce...@neosys.xrs.qwe.si

>No questions via email, unless explicitly invited.
>Ralph Freshour wrote in message <369ab583.1056...@news.mindspring.com>...

Re:Shift+Del Keys Not Being 'Seen'


Quote
Ralph Freshour wrote:

> Good idea - I tried that but it still did not work!! - there must be
> something else going on here but I can't figure out what it is.

> Ralph

* did you implement the OnKeyDown handler of the *form* ? If you use
OnKeyDown of the listview and some other control has the focus, it doesn't
work. Also make sure KeyPreview:=True for the form.
* use the OnKeyDown and not the OnKeyPress event. OnKeyPress will give you
the Key as a Char and no Shift parameter. OnKeyDown will give you the Key as
a word.
* use a breakpoint to test if the eventhandler is executed on a keypress.

  procedure TMainForm.FormKeyDown(Sender: TObject; var Key: Word;
                                  Shift: TShiftState);
  begin
    if (Key = VK_DELETE)and(Shift = [ssShift]) then
    begin
      .......
    end;
  end;

works for me!

Sasan.

Re:Shift+Del Keys Not Being 'Seen'


Does not compile?
You surely typed something wrong.
Shift is defined as set and ssShift is a member of set, so "ssShift in
Shift" is perfectly legal and compilable. Shift = [ssShift] will evaluate to
true only when only shift is pressed, if you press Ctrl or Alt in addition,
it will be false.
Set the breakpoint in event handler to see if it gets there, if not, the
problem is elsewhere.

BTW, I'm not John.
--
----------------------
Regards
Robert Cerny
Remove both qwe when replying
email: robert.qwe.ce...@neosys.xrs.qwe.si

No questions via email, unless explicitly invited.

Quote
Ralph Freshour wrote in message <369adeb9.958...@news.mindspring.com>...
>On Tue, 12 Jan 1999 05:11:20 GMT, "John smith"
><johnsm...@microsoft.com> wrote:

>>The problem is "(Shift = [ssShift])"

>>Try instead:
>>  if (ssShift in Shift) and (Key=VK_delete) then....

>Thanks for the help John - ssShift is defined in a set by Delphi and
>as such must be bracketed as in [ssShift] - your suggested line
>(unless there is a typo in it that I cannot see) does not even compile
>- additional thoughts most welcome...

Re:Shift+Del Keys Not Being 'Seen'


You were right - somehow I *did* type something wrong - when I went
back and typed it in again, it compiled OK!

Although it still did not 'fire' and trap, I found that ssAlt and
ssCtrl *did* work OK with the Del key - now I'm wondering why the
ssShift constant still does not work???

Ralph

On Tue, 12 Jan 1999 16:47:00 GMT, "John smith"

Quote
<johnsm...@microsoft.com> wrote:
>Does not compile?
>You surely typed something wrong.
>Shift is defined as set and ssShift is a member of set, so "ssShift in
>Shift" is perfectly legal and compilable. Shift = [ssShift] will evaluate to
>true only when only shift is pressed, if you press Ctrl or Alt in addition,
>it will be false.
>Set the breakpoint in event handler to see if it gets there, if not, the
>problem is elsewhere.

>BTW, I'm not John.
>--
>----------------------
>Regards
>Robert Cerny
>Remove both qwe when replying
>email: robert.qwe.ce...@neosys.xrs.qwe.si

>No questions via email, unless explicitly invited.
>Ralph Freshour wrote in message <369adeb9.958...@news.mindspring.com>...
>>On Tue, 12 Jan 1999 05:11:20 GMT, "John smith"
>><johnsm...@microsoft.com> wrote:

>>>The problem is "(Shift = [ssShift])"

>>>Try instead:
>>>  if (ssShift in Shift) and (Key=VK_delete) then....

>>Thanks for the help John - ssShift is defined in a set by Delphi and
>>as such must be bracketed as in [ssShift] - your suggested line
>>(unless there is a typo in it that I cannot see) does not even compile
>>- additional thoughts most welcome...

Re:Shift+Del Keys Not Being 'Seen'


if Shift = [ssShift] then
works fine here

Ralph Freshour <ra...@primemail.com> a crit dans l'article
<369cc06e.877...@news.mindspring.com>...

Quote
> You were right - somehow I *did* type something wrong - when I went
> back and typed it in again, it compiled OK!

> Although it still did not 'fire' and trap, I found that ssAlt and
> ssCtrl *did* work OK with the Del key - now I'm wondering why the
> ssShift constant still does not work???

> Ralph

> On Tue, 12 Jan 1999 16:47:00 GMT, "John smith"
> <johnsm...@microsoft.com> wrote:

> >Does not compile?
> >You surely typed something wrong.
> >Shift is defined as set and ssShift is a member of set, so "ssShift in
> >Shift" is perfectly legal and compilable. Shift = [ssShift] will
evaluate to
> >true only when only shift is pressed, if you press Ctrl or Alt in
addition,
> >it will be false.
> >Set the breakpoint in event handler to see if it gets there, if not, the
> >problem is elsewhere.

> >BTW, I'm not John.
> >--
> >----------------------
> >Regards
> >Robert Cerny
> >Remove both qwe when replying
> >email: robert.qwe.ce...@neosys.xrs.qwe.si

> >No questions via email, unless explicitly invited.
> >Ralph Freshour wrote in message <369adeb9.958...@news.mindspring.com>...
> >>On Tue, 12 Jan 1999 05:11:20 GMT, "John smith"
> >><johnsm...@microsoft.com> wrote:

> >>>The problem is "(Shift = [ssShift])"

> >>>Try instead:
> >>>  if (ssShift in Shift) and (Key=VK_delete) then....

> >>Thanks for the help John - ssShift is defined in a set by Delphi and
> >>as such must be bracketed as in [ssShift] - your suggested line
> >>(unless there is a typo in it that I cannot see) does not even compile
> >>- additional thoughts most welcome...

Re:Shift+Del Keys Not Being 'Seen'


Did you check NumLock? Should be off. Otherwise you'll have to check the
other char on del key (period or comma).

--
----------------------
Regards
Robert Cerny
Remove both qwe when replying
email: robert.qwe.ce...@neosys.xrs.qwe.si

No questions via email, unless explicitly invited.

Quote
Ralph Freshour wrote in message <369cc06e.877...@news.mindspring.com>...
>You were right - somehow I *did* type something wrong - when I went
>back and typed it in again, it compiled OK!

>Although it still did not 'fire' and trap, I found that ssAlt and
>ssCtrl *did* work OK with the Del key - now I'm wondering why the
>ssShift constant still does not work???

Re:Shift+Del Keys Not Being 'Seen'


On Wed, 13 Jan 1999 21:10:47 GMT, "John smith"

Quote
<johnsm...@microsoft.com> wrote:
>Did you check NumLock? Should be off. Otherwise you'll have to check the
>other char on del key (period or comma).

Yes - num lock is off...

FYI - I can do the following OK:

if (ssAlt in Shift) and (Key = VK_DELETE) then

if (ssShift in Shift) and (Key = VK_HOME) then

if (ssCtrl in Shift) and (Key = VK_DELETE) then

but not this:

if (ssShift in Shift) and (Key = VK_DELETE) then

Ralph

Quote

>--
>----------------------
>Regards
>Robert Cerny
>Remove both qwe when replying
>email: robert.qwe.ce...@neosys.xrs.qwe.si

>No questions via email, unless explicitly invited.
>Ralph Freshour wrote in message <369cc06e.877...@news.mindspring.com>...
>>You were right - somehow I *did* type something wrong - when I went
>>back and typed it in again, it compiled OK!

>>Although it still did not 'fire' and trap, I found that ssAlt and
>>ssCtrl *did* work OK with the Del key - now I'm wondering why the
>>ssShift constant still does not work???

Other Threads