set function doesn't work

4 visualizaciones (últimos 30 días)
francisco
francisco el 28 de Sept. de 2014
Comentada: Joseph Cheng el 29 de Sept. de 2014
Hello, Im using this code to get the pressed key of my keyboard, returning the value of the key in the variable h, but doesn't work, and occurs this error:
%h=set(gcf,'keypressfcn','get(gcbf,''currentkey'')');
One or more output arguments not assigned during call to "set".
Error in Untitled3 (line 2) h=set(gcf,'keypressfcn','get(gcbf,''currentkey'')');
What is wrong with the code? Help me please

Respuesta aceptada

Joseph Cheng
Joseph Cheng el 28 de Sept. de 2014
What you can do is this.
hfig = figure;
% set(hfig,'KeyPressFcn',@(hobject,event) set(hobject,'UserData',event))
set(hfig,'KeyPressFcn',@(hobject,event) disp(event))
get(hfig,'UserData')
The commented out portion is what you'd do to save the event data. Choose which one you want to save. Say you just care about the character and not the key then you would set the hobject.Userdata with event.Character. The one i didn't comment out was to just show what data is available.
  2 comentarios
francisco
francisco el 28 de Sept. de 2014
Thanks, but i don't understand what are you saying, my english is not very good.
I need to have the character in variable h for use it in other program,How can i do it? Its something like this
function h = Untitled3
hfig = figure;
%set(hfig,'KeyPressFcn',@(hobject,event) set(hobject,'UserData',event))
set(hfig,'KeyPressFcn',@(hobject,event) disp(event));
get(hfig,'UserData');
end
Joseph Cheng
Joseph Cheng el 29 de Sept. de 2014
Okay, I showed only an example since I do not know your implementation. So another very simple implementation, with a function created like below
function h = Untitled
h = figure;
set(h,'KeyPressFcn',@(hobject,event) set(hobject,'UserData',event))
end
where I run it with
h = Untitled
i can retrieve the pressed key using
get(h,'UserData')
from the command line. While the figure is active and you press any key go back to the command line and you'll see that the h has been updated with the new key pressed.

Iniciar sesión para comentar.

Más respuestas (2)

dpb
dpb el 28 de Sept. de 2014
You've got a *set* instead of a *get*. I don't know about the operation, per se, but use
h=get(gcf,'keypressfcn','get(gcbf,''currentkey'')');
as at least first shot...
  1 comentario
francisco
francisco el 28 de Sept. de 2014
Thank you, but doesn't work. Show this:
Error using get Too many input arguments.
Error in Untitled3 (line 2) h=get(gcf,'keypressfcn','get(gcbf,''currentkey'')');

Iniciar sesión para comentar.


Image Analyst
Image Analyst el 28 de Sept. de 2014
Where is that code? Is it in the keypress callback function? Are you using GUIDE, or struggling to wire it up on your own from scratch? In the callback function for keypress, can't you just do
theKey = get(gcf, 'currentKey');
or something like that? (I've never actually done it so I'm just guessing at the correct property to ask for.)

Categorías

Más información sobre Entering Commands en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by