Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

what is the keycode of ALT

64 views
Skip to first unread message

andandgui isler

unread,
Jun 11, 2010, 2:33:25 PM6/11/10
to
i want to type the keycode of ALT key to matlab by using java but i don't find the keycode. Also i don't find the bracet or question mark keycode ?

Where i can find them

Matt Fig

unread,
Jun 11, 2010, 2:59:05 PM6/11/10
to
java.awt.event.KeyEvent.VK_ALT

Walter Roberson

unread,
Jun 11, 2010, 3:22:52 PM6/11/10
to
andandgui isler wrote:
> i want to type the keycode of ALT key to matlab by using java but i
> don't find the keycode.

Keycodes depend upon the keyboard you are using.

If you are using a Microsoft Windows Logo certified keyboard, then the
keyboard will emit Scan Code 2 compatible codes, but the keyboard driver will
convert those into Scan Code 1 codes which is what is used by the OS.

ALT pressed in conjunction with a key will have a different key code than ALT
by itself. Left ALT and Right ALT have different key codes. Pressing a
character has a different key code than releasing the character.

The following is valid only for PS/2 scan codes; USB keyboards use different
scan codes.

Below, 0x followed by a pair of characters indicates the what follows is
hexadecimal; e.g., 0x0D would be decimal 13

Left Alt:
Scan Code 2: press = 0x11, release = 0xF0 0x11
Scan Code 1: press = 0x38, release = 0xB8

Right Alt:
Scan Code 2: press = 0xE0 0x11, release = 0xE0 0xF0 0x11
Scan Code 1: press = 0xE0 0x38, release = 0xE0 0xB8


> Also i don't find the bracet or question mark
> keycode ?
> Where i can find them


( is shift-9, and in Scan Code 2, shift needs to be sent as an individual
code. Which code depends upon which shift. The release events for the 9 and
the shift are sent separately in Scan Code 2, according to which one is
released first. The scheme differs for Scan Code 1 (used internally, possibly
what you have to generate): a code for the shift still has to be sent, but
when the second key is pressed, a sequence of codes has to be sent, and when
one of the two keys is released, a sequence of codes has to be sent that
differs according to which of the two is released first, essentially signally
which of the keys is still pressed. This all gets messy so I'll point you to
the documentation:

http://download.microsoft.com/download/1/6/1/161ba512-40e2-4cc9-843a-923143f3456c/scancode.doc

andandgui isler

unread,
Jun 11, 2010, 10:16:04 PM6/11/10
to
Thanks for replies..
now i have the problem with
question mark
and some special characters like Ö Ü

how can i press them using MATLAB.. i write code of other keys but i cant find these keys code or any alternative method to press them.
what should i do

Walter Roberson

unread,
Jun 12, 2010, 12:30:08 AM6/12/10
to
andandgui isler wrote:

question mark is shift / and so follows similar rules to what I
described before with respect to ( .

Ö Ü need modifier keys to enter.

In terms of the java sequences Matt hinted at:

http://java.sun.com/j2se/1.4.2/docs/api/java/awt/event/KeyEvent.html

( is VK_LEFT_PARENTHESIS
) is VK_RIGHT_PARENTHESIS
Ö seems to be VK_DEAD_ABOVEDOT VK_O
Ü seems to be VK_DEAD_ABOVEDOT VK_U

"Not all characters have a keycode associated with them. For example,
there is no keycode for the question mark because there is no keyboard
for which it appears on the primary layer."

and that implies that question-mark is VK_SHIFT VK_SLASH

And remember to generate the appropriate VK_KEYPRESSED and
VK_KEYRELEASED events (I guess... I don't know what would happen if you
just entered one of the VK_* without a VK_KEYPRESSED )

andandgui isler

unread,
Jun 12, 2010, 7:46:02 AM6/12/10
to
Walter Roberson <robe...@hushmail.com> wrote in message <l3EQn.76020$HG1....@newsfe21.iad>...

Thanks for your attention Walter Roberson.

The problem still countinues. When i type the code below :

import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.KeyEvent;
keyboard=Robot;
>> keyboard.keyPress(KeyEvent.VK_DEAD_ABOVEDOT VK_O);
??? keyboard.keyPress(KeyEvent.VK_DEAD_ABOVEDOT VK_O);
|
Error: Unexpected MATLAB expression.

gives this error and also

>> keyboard.keyPress(KeyEvent.VK_SHIFT VK_SLASH)
??? keyboard.keyPress(KeyEvent.VK_SHIFT VK_SLASH)
|
Error: Unexpected MATLAB expression.

Walter Roberson

unread,
Jun 12, 2010, 11:13:04 AM6/12/10
to
andandgui isler wrote:

> import java.awt.AWTException; import java.awt.Robot; import
> java.awt.event.KeyEvent; keyboard=Robot;
>>> keyboard.keyPress(KeyEvent.VK_DEAD_ABOVEDOT VK_O);
> ??? keyboard.keyPress(KeyEvent.VK_DEAD_ABOVEDOT VK_O);
> |
> Error: Unexpected MATLAB expression.

keyboard.keyPress.KeyEvent.VK_DEAD_ABOVEDOT;
keyboard.keyPress.KeyEvent.VK_O;

The KeyEvent method takes only a single keycode.

us

unread,
Jun 12, 2010, 11:37:05 AM6/12/10
to
Walter Roberson <robe...@hushmail.com> wrote in message <4uNQn.37429$rU6....@newsfe10.iad>...

this is the wrong syntax, though...
it should read

import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.KeyEvent;

kbd=Robot; % <- don't use KEYBOARD as a var...
kbd.keyPress(KeyEvent.VK_DEAD_ABOVEDOT); % <- see below...
kbd.keyPress(KeyEvent.VK_O); % <- this works...
% however, this does NOT always work...
kbd.keyPress(KeyEvent.VK_DEAD_ABOVEDOT);
%{
??? Java exception occurred:
java.lang.IllegalArgumentException: Invalid key code
at sun.awt.windows.WRobotPeer.keyPress(Native Method)
at java.awt.Robot.keyPress(Unknown Source)
%}

us

andandgui isler

unread,
Jun 12, 2010, 10:15:22 PM6/12/10
to
Thanks for your attention Walter Roberson and us
i'm using MATLAB R2009b but when i type given code below by yours, it still gives me error.

import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.KeyEvent;
kbd=Robot;

kbd.keyPress(KeyEvent.VK_DEAD_ABOVEDOT);


??? Java exception occurred:
java.lang.IllegalArgumentException: Invalid key code

at sun.awt.windows.WRobotPeer.keyPress(Native Method)

at java.awt.Robot.keyPress(Unknown Source)


kbd.keyPress(KeyEvent.VK_O);
>> o


kbd.keyPress(KeyEvent.VK_O) works but,
kbd.keyPress(KeyEvent.VK_DEAD_ABOVEDOT) doen't work on my computer

us

unread,
Jun 12, 2010, 10:41:05 PM6/12/10
to
"andandgui isler" <bosisl...@hotmail.com> wrote in message <hv1evp$dh8$1...@fred.mathworks.com>...

well, yes...
that's EXACTLY what i said in my reply: this solution does not work...

us

Walter Roberson

unread,
Jun 12, 2010, 11:22:32 PM6/12/10
to
andandgui isler wrote:

>
> kbd.keyPress(KeyEvent.VK_O) works but,
> kbd.keyPress(KeyEvent.VK_DEAD_ABOVEDOT) doen't work on my computer

http://www.w3.org/2002/09/tests/KeyEventDemo.java

is a demo that will show you key presses and releases, so you could use
that to query what any particular key sequence becomes.

us

unread,
Jun 13, 2010, 7:29:04 AM6/13/10
to
Walter Roberson <robe...@hushmail.com> wrote in message <Z9YQn.141488$0M5....@newsfe07.iad>...

as i said: this approach does not work from within genuine ML (at least in wintel envs)...
just look at my replies...

us

Walter Roberson

unread,
Jun 13, 2010, 8:56:16 PM6/13/10
to

That isn't immediately clear, as the demo might show a completely
different key sequence; or plausibly if run until Matlab, the demo would
show the key sequences that Matlab wants.

For example, plausibly the demo would show the VK_DEAD_ABOVEDOT *after*
the vowel -- since, after all, Matlab did not complain that
VK_DEAD_ABOVEDOT was an invalid field or method.

us

unread,
Jun 13, 2010, 9:05:07 PM6/13/10
to
Walter Roberson <robe...@hushmail.com> wrote in message <Q6fRn.30436$yx.2...@newsfe13.iad>...

yes it does, walter
look in my replies above to see the error message it pukes...

us

Walter Roberson

unread,
Jun 14, 2010, 12:52:12 PM6/14/10
to

Looking around, it appears that this is a common Java Robot problem not
specific to Matlab. The discussion I found at
https://bugs.eclipse.org/bugs/show_bug.cgi?format=multiple&id=280562
hints that the work-around is to code each key press literally, such as
VK_CONTROL VK_RIGHT_ALT VK_SHIFT VK_QUOTE VK_O
and then the release events for those in the opposite order. (I do not
have a PC available to test the exact key sequence with.)

By the way: the discussions above show the problem being debugged by use
of the exact demo that I pointed to...

0 new messages