Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [platform-swt-dev] KeyEvent.character


A FAQ Entry would definitely help.  But you get "props" for putting it in the 2.1 release notes!

The snippets and FAQ are great, but unlike other projects (like GEF), there is no easy way to get to the SWT homepage from the Eclipse.org homepage. This needs to be fixed for all platform components.



"Steve Northover" <Steve_Northover@xxxxxxxxxx>
Sent by: platform-swt-dev-admin@xxxxxxxxxxx

04/22/2003 10:05 AM
Please respond to platform-swt-dev

       
        To:        platform-swt-dev@xxxxxxxxxxx
        cc:        platform-swt-dev@xxxxxxxxxxx, platform-swt-dev-admin@xxxxxxxxxxx
        Subject:        Re: [platform-swt-dev] KeyEvent.character




Because Ctrl+A is ^A is ASCII SOH is the hex value 0x01.  It's in the 2.1 JavaDoc.  This comes up a lot.  Maybe we need a FAQ?



"Federico Gentile" <fgentile@xxxxxxxxxxxxxxxxxx>
Sent by: platform-swt-dev-admin@xxxxxxxxxxx

04/22/2003 09:48 AM
Please respond to platform-swt-dev

       
       To:        <platform-swt-dev@xxxxxxxxxxx>

       cc:        

       Subject:        [platform-swt-dev] KeyEvent.character




Regarding this snippet

http://dev.eclipse.org/viewcvs/index.cgi/~checkout~/platform-swt-home/sn
ippits/snippet25.html

(See at the bottom of the message for the code itself)

Why do I get this output when I press CTRL+something?

I pressed
CTRL + A
CTRL + B
CTRL + P
And got
DOWN: stateMask=0x0, keyCode=0x40000, character=0x0 '\0'
DOWN: stateMask=0x40000 CTRL, keyCode=0x0, character=0x1 ''
UP  : stateMask=0x40000 CTRL, keyCode=0x0, character=0x1 ''
DOWN: stateMask=0x40000 CTRL, keyCode=0x0, character=0x2 ''
UP  : stateMask=0x40000 CTRL, keyCode=0x0, character=0x2 ''
DOWN: stateMask=0x40000 CTRL, keyCode=0x0, character=0x10 '' UP  :
stateMask=0x40000 CTRL, keyCode=0x0, character=0x10 '' UP  :
stateMask=0x40000 CTRL, keyCode=0x40000, character=0x0 '\0'

If I press
ALT + A
ALT + B
ALT + P
I can see the character
DOWN: stateMask=0x0, keyCode=0x10000, character=0x0 '\0'
UP  : stateMask=0x10000 ALT, keyCode=0x0, character=0x61 'a'
UP  : stateMask=0x10000 ALT, keyCode=0x0, character=0x62 'b'
UP  : stateMask=0x10000 ALT, keyCode=0x0, character=0x70 'p'
UP  : stateMask=0x10000 ALT, keyCode=0x10000, character=0x0 '\0'

Moreover the javadoc and the code sais e.character is a char but
This: Integer.toHexString (e.character) works? Are char and int
interchangeable?
I have to do this to check if the cey combination is CTRL + A
If((e.character == (int) 'a' - 96) && (e.stateMask == SWT.ALT))
               // it's CTRL + a

Can anybody explain me why doesn't pressing CTRL + key work the same and
with ALT + key or SHIFT + KEY?

Thanks....

(Im working on winXP, but our target platform in pocketpc with windows.)


----- S N I P P E T -----
import org.eclipse.swt.*;
import org.eclipse.swt.widgets.*;

public class Main {

public static void main (String [] args) {
               Display display = new Display ();
               Shell shell = new Shell (display);

                Listener listener = new Listener() {
                                public void handleEvent(Event e) {
                                                 String string = e.type == SWT.KeyDown ? "DOWN" :
"UP  ";
                                                 string += ": stateMask=0x" +
Integer.toHexString(e.stateMask);
                                                 if ((e.stateMask & SWT.CTRL) != 0) string += "
CTRL";
                                                 if ((e.stateMask & SWT.ALT) != 0) string += "
ALT";
                                                 if ((e.stateMask & SWT.SHIFT) != 0) string += "
SHIFT";
                                                 if ((e.stateMask & SWT.COMMAND) != 0) string +=
" COMMAND";
                                                 string += ", keyCode=0x" + Integer.toHexString
(e.keyCode);
                                                 string += ", character=0x" + Integer.toHexString
(e.character);
                                                 switch (e.character) {
                                                                  case 0:                                   string += "
'\\0'"; break;
                                                                  case SWT.BS:                 string += " '\\b'";
break;
                                                                  case SWT.CR:                 string += " '\\r'";
break;
                                                                  case SWT.DEL:                 string += " DEL"; break;
                                                                  case SWT.ESC:                 string += " ESC"; break;
                                                                  case SWT.LF:                 string += " '\\n'";
break;
                                                                  case SWT.TAB:                 string += " '\\t'";
break;
                                                                  default:                                  string += " '" +
e.character +"'"; break;
                                                 }
                                                 System.out.println (string);
                                }
               };
               shell.addListener(SWT.KeyDown, listener);
               shell.addListener(SWT.KeyUp, listener);
               shell.setSize (200, 200);
               shell.open ();
               while (!shell.isDisposed ()) {
                                if (!display.readAndDispatch ()) display.sleep ();
               }
               display.dispose ();
}

}
_______________________________________________
platform-swt-dev mailing list
platform-swt-dev@xxxxxxxxxxx
http://dev.eclipse.org/mailman/listinfo/platform-swt-dev




Back to the top