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

(keyboard) input without pressing enter

1,234 views
Skip to first unread message

jay vaughan

unread,
Apr 22, 2008, 12:13:01 PM4/22/08
to
Anyone know if there is a way to use input so that a single
keystroke is returned without having to press enter?

I have keyboard control with keystrokes in a GUI I wrote
using keypressFCN but was hoping that there is a simpler way
to do this kind of thing.

Now I have:

key = input('k to go forward, j to go back','s');

but the user has to press the letter and then enter.


Thanks!
J

Walter Roberson

unread,
Apr 22, 2008, 3:44:03 PM4/22/08
to
In article <ful2qd$a4p$1...@fred.mathworks.com>,

>Now I have:

Doing in using keypressFCN -is- the easy way.

If you want single character I/O from the keyboard, you would
need to go in to the Java level (speculating), or you would need
to use an ActiveX control or mex routine, or you would need to use
a serial object. If this all doesn't sound portable, it's because it
isn't: what you might perhaps do if you have the Matlab desktop running
is different than if the desktop and jvm are turned off and you
are working over a unix pty or serial port.

And you need to consider: is 'shift' a keystroke? Is 'control'? What
'keystrokes' are involved if the user holds down a key to the point
where autorepeat would normally be triggered?


If you just want two options, such as forward and back, you
might want to consider using the figure buttondownfcn; if
you examine the selectionstate property, you can figure out which mouse
button was pressed.
--
"There are some ideas so wrong that only a very intelligent person
could believe in them." -- George Orwell

Jos

unread,
Apr 22, 2008, 5:13:01 PM4/22/08
to
robe...@ibd.nrc-cnrc.gc.ca (Walter Roberson) wrote in
message <fulf63$8$1...@canopus.cc.umanitoba.ca>...

My GETKEY function may offer a solution. It can catch all
keystrokes, including shift, ctrl, etc. See
http://www.mathworks.com/matlabcentral/fileexchange/loadFile
.do?objectId=7465&objectType=FILE

(beware of line wraps)

hth
Jos

jay vaughan

unread,
Apr 22, 2008, 6:31:02 PM4/22/08
to
Hi Jos,

the getkey function is a nice solution to my problem. It
worked perfectly. Thanks!


J

0 new messages