Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » VerifyListener, statemask
VerifyListener, statemask [message #514267] Sat, 13 February 2010 05:12 Go to next message
Pietro is currently offline Pietro
Messages: 27
Registered: July 2009
Junior Member
Hi,
I'm trying to detect when user has pressed CTRL+V to paste text in my
textbox.
With KeyListener all do right but when I use VerifyListener statemask is
always zero.
I'm on Windows XP and I'm using SWT version 3.448.
Here is a portion of code:
public void verifyText(VerifyEvent arg0) {
arg0.doit = false;
// System.out.println("carattere: " + arg0.character);
if (arg0.stateMask == SWT.CTRL && arg0.keyCode == 99)
{
System.out.println("CTRL C is pressed");
}
else if (arg0.stateMask == SWT.CTRL && arg0.keyCode == 118)
{
System.out.println("CTRL V is pressed");
}
else
System.out.println(arg0.stateMask + " *** " + arg0.keyCode);
}
}

Is this a bug?

Thanks in advance,
Pietro
Re: VerifyListener, statemask [message #514773 is a reply to message #514267] Tue, 16 February 2010 10:36 Go to previous messageGo to next message
Grant Gayed is currently offline Grant Gayed
Messages: 2151
Registered: July 2009
Senior Member
Hi Pietro,

I see this too. I don't know if it's intentional or not, since the main
point of the Verify event is to verify whether the text should be inserted.
However since VerifyEvent extends KeyEvent, the KeyDown information probably
could be provided as well. Feel free to log a request for this with SWT at
https://bugs.eclipse.org/bugs/enter_bug.cgi?product=Platform &component=SWT&bug_severity=enhancement .

In the meantime, I think the only way to detect a case like this is to
listen in KeyDown, and if Ctrl+V is detected then set some property on the
Text so that it knows that the next received Verify event came from Ctrl+V.
(Keep in mind that Shift+Insert also pastes, and Command+V on OS X).

Grant


"Pietro Santurelli" <santurelli@inwind.it> wrote in message
news:hl5tj0$bjf$1@build.eclipse.org...
> Hi,
> I'm trying to detect when user has pressed CTRL+V to paste text in my
> textbox.
> With KeyListener all do right but when I use VerifyListener statemask is
> always zero.
> I'm on Windows XP and I'm using SWT version 3.448.
> Here is a portion of code:
> public void verifyText(VerifyEvent arg0) {
> arg0.doit = false;
> // System.out.println("carattere: " + arg0.character);
> if (arg0.stateMask == SWT.CTRL && arg0.keyCode == 99)
> {
> System.out.println("CTRL C is pressed");
> }
> else if (arg0.stateMask == SWT.CTRL && arg0.keyCode == 118)
> {
> System.out.println("CTRL V is pressed");
> }
> else
> System.out.println(arg0.stateMask + " *** " + arg0.keyCode);
> }
> }
>
> Is this a bug?
>
> Thanks in advance,
> Pietro
Re: VerifyListener, statemask [message #514873 is a reply to message #514773] Tue, 16 February 2010 23:26 Go to previous messageGo to next message
Pietro is currently offline Pietro
Messages: 27
Registered: July 2009
Junior Member
Hi Grant,
thanks for your response.
I've found that when user enter a key combination (say CTRL+v), the
property keyCode of VerifyEvent is 0.
I can utilize that value to understand that user has entered a key
combination.
Is that rigth?

Thanks,
Pietro

P.S.
Exceuse me for my poor english

Il 16/02/2010 16.20, Grant Gayed ha scritto:
> Hi Pietro,
>
> I see this too. I don't know if it's intentional or not, since the main
> point of the Verify event is to verify whether the text should be inserted.
> However since VerifyEvent extends KeyEvent, the KeyDown information probably
> could be provided as well. Feel free to log a request for this with SWT at
> https://bugs.eclipse.org/bugs/enter_bug.cgi?product=Platform &component=SWT&bug_severity=enhancement .
>
> In the meantime, I think the only way to detect a case like this is to
> listen in KeyDown, and if Ctrl+V is detected then set some property on the
> Text so that it knows that the next received Verify event came from Ctrl+V.
> (Keep in mind that Shift+Insert also pastes, and Command+V on OS X).
>
> Grant
>
>
> "Pietro Santurelli"<santurelli@inwind.it> wrote in message
> news:hl5tj0$bjf$1@build.eclipse.org...
>> Hi,
>> I'm trying to detect when user has pressed CTRL+V to paste text in my
>> textbox.
>> With KeyListener all do right but when I use VerifyListener statemask is
>> always zero.
>> I'm on Windows XP and I'm using SWT version 3.448.
>> Here is a portion of code:
>> public void verifyText(VerifyEvent arg0) {
>> arg0.doit = false;
>> // System.out.println("carattere: " + arg0.character);
>> if (arg0.stateMask == SWT.CTRL&& arg0.keyCode == 99)
>> {
>> System.out.println("CTRL C is pressed");
>> }
>> else if (arg0.stateMask == SWT.CTRL&& arg0.keyCode == 118)
>> {
>> System.out.println("CTRL V is pressed");
>> }
>> else
>> System.out.println(arg0.stateMask + " *** " + arg0.keyCode);
>> }
>> }
>>
>> Is this a bug?
>>
>> Thanks in advance,
>> Pietro
>
>
Re: VerifyListener, statemask [message #515082 is a reply to message #514873] Wed, 17 February 2010 16:28 Go to previous message
Grant Gayed is currently offline Grant Gayed
Messages: 2151
Registered: July 2009
Senior Member
Yes, this approach should mostly work. The only common case I can think of
where this would give a false-positive is Ctrl+Z. Also, it is possible that
some accessibility assistive technologies could give the user a way of
manipulating text without the corresponding keystrokes, which could also
give a false-positive. Whether these cases matter to you or not depends on
why you want to handle the paste-from-clipboard case specially.

Grant


"Pietro Santurelli" <santurelli@inwind.it> wrote in message
news:hlf9nr$4l6$1@build.eclipse.org...
> Hi Grant,
> thanks for your response.
> I've found that when user enter a key combination (say CTRL+v), the
> property keyCode of VerifyEvent is 0.
> I can utilize that value to understand that user has entered a key
> combination.
> Is that rigth?
>
> Thanks,
> Pietro
>
> P.S.
> Exceuse me for my poor english
>
> Il 16/02/2010 16.20, Grant Gayed ha scritto:
> > Hi Pietro,
> >
> > I see this too. I don't know if it's intentional or not, since the main
> > point of the Verify event is to verify whether the text should be
inserted.
> > However since VerifyEvent extends KeyEvent, the KeyDown information
probably
> > could be provided as well. Feel free to log a request for this with SWT
at
> >
https://bugs.eclipse.org/bugs/enter_bug.cgi?product=Platform &component=SWT&bug_severity=enhancement .
> >
> > In the meantime, I think the only way to detect a case like this is to
> > listen in KeyDown, and if Ctrl+V is detected then set some property on
the
> > Text so that it knows that the next received Verify event came from
Ctrl+V.
> > (Keep in mind that Shift+Insert also pastes, and Command+V on OS X).
> >
> > Grant
> >
> >
> > "Pietro Santurelli"<santurelli@inwind.it> wrote in message
> > news:hl5tj0$bjf$1@build.eclipse.org...
> >> Hi,
> >> I'm trying to detect when user has pressed CTRL+V to paste text in my
> >> textbox.
> >> With KeyListener all do right but when I use VerifyListener statemask
is
> >> always zero.
> >> I'm on Windows XP and I'm using SWT version 3.448.
> >> Here is a portion of code:
> >> public void verifyText(VerifyEvent arg0) {
> >> arg0.doit = false;
> >> // System.out.println("carattere: " + arg0.character);
> >> if (arg0.stateMask == SWT.CTRL&& arg0.keyCode == 99)
> >> {
> >> System.out.println("CTRL C is pressed");
> >> }
> >> else if (arg0.stateMask == SWT.CTRL&& arg0.keyCode == 118)
> >> {
> >> System.out.println("CTRL V is pressed");
> >> }
> >> else
> >> System.out.println(arg0.stateMask + " *** " +
arg0.keyCode);
> >> }
> >> }
> >>
> >> Is this a bug?
> >>
> >> Thanks in advance,
> >> Pietro
> >
> >
>
Previous Topic:problem with virtual table
Next Topic:NullPointerException printing on mac
Goto Forum:
  


Current Time: Thu Oct 23 14:28:56 GMT 2014

Powered by FUDForum. Page generated in 0.02991 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software