pro wmkkey_event,event
;
;
common wmkkey_blk, key
widget_control, get_uvalue=etop, event.top  ; get instance
widget_control, get_uvalue=uvalue, event.id ; get instance
;print, 'help, etop: '
;help, etop
;if n_elements(str) eq 0 then etopstr=''
if n_elements(mkkey) eq 0 then mkkey = 0    ; false
;
if (n_elements(uvalue) eq 0) then uvalue=''
event_name=tag_names(event,/structure_name)
event_name=strmid(event_name,7,strlen(event_name))
;print,event_name ;****
;
notdone=1
case (event_name) of
   "BUTTON": begin
      sizeuv=size(uvalue)
      case (sizeuv(2)) of 
         8:begin            ; its a key button
         widget_control, get_uvalue=puv, uvalue.butpar
         case(uvalue.type) of
           1:begin          ;simple ' '=' ' operation
;       print,'uvalue from event.id '
;       help, uvalue,/st
;       print,'puv from uvalue.butpar '
;       help, puv, /st
;       stop,'ck uvalue.value
           puv.output=puv.key + uvalue.value
;          print, 'Setting Sea key value: ', puv.output
           widget_control, set_Uvalue=puv, uvalue.butpar    ;sav uv
           widget_control, set_value=uvalue.uvalue, puv.mtptr   ;upd val
         end
           2:begin
           print, 'type = 2 ...what to do?'
         end
           3:begin
           print, 'Clearing Sea key value for: ', puv.key
;       print,'uvalue from event.id '
;       help, uvalue,/st
;       print,'puv from uvalue.butpar '
;       help, puv, /st
           puv.output = ''      ;set to null
           widget_control, set_uvalue=puv, uvalue.butpar    ;save
           widget_control, set_value=uvalue.value, puv.mtptr    ;clr text
           etop.curstr = getcurstr(etop.keyptrs)    ;update curstr var
           widget_control, set_uvalue=etop, event.top   ;save curstr
           widget_control, set_value=etop.curstr, etop.curkeyt  ;upd dsply
         end
           else: print,'incorrect type....'
             endcase
;        print, 'PUV = ', puv
;       stop, 'stop--ck etop.keyptrs and call to getcurstr:'
         etop.curstr = GetCurStr(etop.keyptrs)  ;get current string
         widget_control, set_value=etop.curstr, etop.curkeyt;update display
         widget_control, set_uvalue=etop, event.top     ;save to uvalue
;             stop, 'ck uvalue and puv for item and val or output'
       endcase          ;end its a key button
    else: $
         case(uvalue) of
        "SAVKEY": begin
;                  print, 'Saving curstr: ', etop.curstr
               mkkey = 1        ;true key is made
               etop.lststr = etop.curstr    ;save last str
               widget_control, set_uvalue=etop, event.top
               widget_control, get_uvalue=svdlst, etop.keylstt
               IF (N_ELEMENTS(svdlst) eq 0) THEN BEGIN  ;undefined
             svdlst = etop.curstr
             widget_control, set_uvalue=svdlst, etop.keylstt
             fillstr = string(replicate(32b,60))    ;filler
             fillstr = replicate(fillstr,3)
             widget_control, set_value=[svdlst,fillstr], etop.keylstt
               ENDIF ELSE BEGIN
             svdlst = [svdlst, etop.curstr] ;add to list
             widget_control, set_uvalue=svdlst, etop.keylstt
             IF (N_ELEMENTS(svdlst) lt 4) THEN BEGIN
               fillstr = string(replicate(32b,60))  ;filler
               fillstr = replicate(fillstr,3)
               widget_control, set_value=[svdlst,fillstr], etop.keylstt          
             ENDIF ELSE BEGIN
               fillstr = string(replicate(32b,60))  ;filler
               svdlst = [svdlst,fillstr]
               widget_control, set_value=svdlst, etop.keylstt            
             ENDELSE
               ENDELSE
              endcase   
        "CLRKEY": begin         ;clear current key
                etop.curstr = ''
            widget_control, set_uvalue=etop, event.top
                    widget_control, set_value=etop.curstr, etop.curkeyt;update display
            Clrkeys, etop.keyptrs   ;clear puv.output & text dsply
        ;clear puv.output,and text display
              end
            "DONE":begin
;       return Saved key list and destroy widget:
;       print,'Current Key = ',etop.curstr
        WIDGET_control, get_uvalue=svdlst, etop.keylstt
        nlst = N_ELEMENTS(svdlst)   ;size of list 
        IF (nlst ne 0) THEN BEGIN   ;nlst define 
         IF (etop.curstr ne svdlst(nlst-1) ) THEN BEGIN
          svdlst = [svdlst, etop.curstr]    ;forgot to save
          widget_control, set_uvalue=svdlst, etop.keylstt
         ENDIF
         fillstr = string(replicate(32b,60))
         svdlst = svdlst(where(svdlst ne fillstr))
         key = svdlst               ;pass back list
         Print, 'Your Saved Keys are in VARIABLE "key": '
         HELP, key
        ENDIF ELSE BEGIN        ;if defined do above
         IF (N_elements(etop.curstr) ne 0) THEN BEGIN
          key = etop.curstr
         ENDIF
        ENDELSE
         widget_control, event.top, /destroy
             endcase
            "STOP":begin        ;pause and return to IDL 
;       print,'Current Key = ',etop.curstr
        WIDGET_control, get_uvalue=svdlst, etop.keylstt
        nlst = N_ELEMENTS(svdlst)   ;size of list 
;       print,'Number of saved keys', nlst
        IF (nlst ne 0) THEN BEGIN   ;nlst defined
;            print,'Last saved key = ', svdlst(nlst-1)
;   stop,'stop to ck curstr and last saved'
         IF (etop.curstr ne svdlst(nlst-1) ) THEN BEGIN
          svdlst = [svdlst, etop.curstr]    ;forgot to save
          widget_control, set_value=svdlst, etop.keylstt
          widget_control, set_uvalue=svdlst, etop.keylstt
         ENDIF
         fillstr = string(replicate(32b,60))
         svdlst = svdlst(where(svdlst ne fillstr))
         key = svdlst               ;pass back list
         Print, 'Your Saved Keys are in VARIABLE "key": '
         HELP, key
        ENDIF ELSE BEGIN        ;if defined do above
         IF (N_elements(etop.curstr) ne 0) THEN BEGIN
          svdlst = etop.curstr
          widget_control, set_uvalue=svdlst, etop.keylstt
          fillstr = string(replicate(32b,60))   ;filler
          fillstr = replicate(fillstr,3)
          widget_control, set_value=[svdlst,fillstr], etop.keylstt
          key = etop.curstr
         ENDIF
        ENDELSE
        retall
        endcase
        else:print,uvalue
         endcase
      endcase
   endcase
"SLIDER":begin
   endcase
"LIST":begin
         stop,'stop a list widget click (type .con to continue)'
   endcase
"TEXT":begin
   endcase
else:
endcase

return
end