Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Where is the information what key has been pressed(Where is the information what key has been pressed)
Where is the information what key has been pressed [message #1065684] Thu, 27 June 2013 07:01 Go to next message
Janusz Dalecki is currently offline Janusz DaleckiFriend
Messages: 56
Registered: January 2010
Location: Sydney
Member
I am using:
text.addVerifyListener(new VerifyListener() {
      boolean ignore;

      @Override
      public void verifyText(VerifyEvent e) {
}});

... to filter characters that can be entered into my text field. I need to detect that Ctrl-x has been pressed so to delete the selected text. I don't seem to be able to find that info in the VerifyEvent event (the character member is empty).

Regards,
Janusz
Re: Where is the information what key has been pressed [message #1066247 is a reply to message #1065684] Mon, 01 July 2013 17:17 Go to previous messageGo to next message
li ran is currently offline li ranFriend
Messages: 11
Registered: June 2013
Junior Member
why not key listener? then use mask for your

maybe this will help you


stackoverflow.com/questions/5842190/how-to-detect-ctrl-f-in-my-swt-application
Re: Where is the information what key has been pressed [message #1066290 is a reply to message #1066247] Tue, 02 July 2013 01:12 Go to previous messageGo to next message
Janusz Dalecki is currently offline Janusz DaleckiFriend
Messages: 56
Registered: January 2010
Location: Sydney
Member
I have tried VerifyKeyListener - same problem,
Regards,
Janusz
Re: Where is the information what key has been pressed [message #1066488 is a reply to message #1066290] Tue, 02 July 2013 20:26 Go to previous messageGo to next message
li ran is currently offline li ranFriend
Messages: 11
Registered: June 2013
Junior Member
dunno, worked for me


import org.eclipse.swt.SWT;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.KeyListener;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;


public class cntlXcheck {

	public static void main(String[] args) {
	    final Display
	    display = new Display();
	    Shell shell = new Shell(display);
	    shell.setBounds(10, 10, 200, 200);
	    shell.setLayout(new FillLayout());
	    Text text = new Text(shell, SWT.NONE);
	    text.addKeyListener(new KeyListener() {
			
			public void keyReleased(KeyEvent arg0) {
				if (arg0.keyCode == 'x' && arg0.stateMask == SWT.CTRL){
					System.out.println("pressed");
				}
				
			}
			
			public void keyPressed(KeyEvent arg0) {
				// TODO Auto-generated method stub
				
			}
		});
	    
	    shell.open();
	    while (!shell.isDisposed()) {
	        if (!display.readAndDispatch()) display.sleep();
	    }
	    display.dispose();
	}
}

Re: Where is the information what key has been pressed [message #1066532 is a reply to message #1066488] Wed, 03 July 2013 03:26 Go to previous message
Janusz Dalecki is currently offline Janusz DaleckiFriend
Messages: 56
Registered: January 2010
Location: Sydney
Member
I have this code fragment to handle it:

}
@Override
      public void verifyText(VerifyEvent e) {
        ControlDecoration decorator = (ControlDecoration) text.getData(DECORATOR_DATA);
        boolean isCtrlX = (e.stateMask == SWT.CTRL) && (e.character == '\u0018');
        if (((e.stateMask & SWT.CTRL) == SWT.CTRL) && (e.keyCode == 'x')) {
          System.out.println();
        } ...
     

I set a break point at System.out.println() but debugger never hits it - although I press multiple times ctrl-x.
Regards,
Janusz
Previous Topic:verifyKey not working as printed in the Eclipse article
Next Topic:Problem with "org.eclipse.swt.SWTError: No more handles"
Goto Forum:
  


Current Time: Mon Dec 22 11:35:55 GMT 2014

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

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