selecting text in 'edit' style uicontrol


I have a problem that I hope someone can help me solve.  

I have created a GUI which contains an editable text style
uiControl which allows the user to type in a password, but
replaces the text being typed into the uiControl with
asterisks.  (I borrowed the idea from Jeremy Smith's login.m
file on MATLAB's File Exchange web page.)  I use the
uiControl's 'KeyPressFcn' property to capture and replace
the last key pressed by the user as they type in the
password.  If the user types a backspace, I act accordingly
by removing the last character in the string of characters
entered thus far.

Here is the problem:  if the user uses the mouse to
highlight text in this edit box and then hits backspace,
they expect the highlighted text to be deleted.  Is there a
way for me to know when the user has selected (highlighted)
some text in an editable text uiControl?

Here is a snippet of my KeyPressFcn:


   password = get(src,'userData');
   key = get(fig,'currentKey');
   switch key
      case 'backspace'
         password = password(1:end-1); % delete last char 

          password = [password get(fig,'currentCharacter')];


Thank you,

Michelle Kline
mkline (15)
6/3/2008 5:46:01 PM
comp.soft-sys.matlab 211266 articles. 25 followers. lunamoonmoon (257) is leader. Post Follow

1 Replies

Similar Articles

[PageSpeed] 50

I have done this kind of thing before.  I have always set
the callback to the edit function as close(gcf) if it is
simply a password dialog box. That along with adding a line
in the keypressfcn that ignores a carriage return.  Then the
user simply has to press return to close the password dialog
and any attempt to click on the edit box closes the dialog.  
spamanon (2437)
6/4/2008 2:23:01 AM