English Amiga Board


Go Back   English Amiga Board > Coders > Coders. Language > Coders. Blitz Basic

 
 
Thread Tools
Old 11 August 2019, 00:50   #1
AlfaRomeo
A1200 040 SAM440EP 667
 
AlfaRomeo's Avatar
 
Join Date: Jan 2008
Location: Lisbon / Portugal
Posts: 873
Handling keys in MUI

Hi guys, could someone help me in this?
There is any way MUI (in Blitz Basic) can react to keys pressed when entering text in a string gadget so MUI automatically ends the string gadget when "Enter" key is pressed?

something like:

; this code freezes application
Repeat
pass$=MUIGetString$(3)
Until RawStatus($44)


I imagine that, when entering text in string gadget the keys pressed still generating RawKey codes, so is a matter of capturing and test the key codes
AlfaRomeo is offline  
Old 11 August 2019, 11:35   #2
Daedalus
Registered User
 
Daedalus's Avatar
 
Join Date: Jun 2009
Location: Dublin, then Glasgow
Posts: 6,334
It really should be handled through the MUI class rather than by accessing the raw keys directly. There are MUI events you can set up for just such a thing. I can't remember the exact value, but if you check out the text gadget documentation in the MUI Autodocs, you should find the constant you need.
Daedalus is offline  
Old 11 August 2019, 22:34   #3
AlfaRomeo
A1200 040 SAM440EP 667
 
AlfaRomeo's Avatar
 
Join Date: Jan 2008
Location: Lisbon / Portugal
Posts: 873
Thanks Daedalus, I already checked some Mui docs but doesn´t found a valid result for my problem, the nearest result is through MUIWaitEvent.
I will continue searching until reach a good result for what I need
AlfaRomeo is offline  
Old 13 August 2019, 19:04   #4
AlfaRomeo
A1200 040 SAM440EP 667
 
AlfaRomeo's Avatar
 
Join Date: Jan 2008
Location: Lisbon / Portugal
Posts: 873
Does someone can tell me why, in the code posted, the variable pass$=MUIGetString$(3) only assumes the string typed in the string gadget during the next input event, in this case, it is when it runs the statement noRnd{} for the 2nd time
It´s a MUI bug?.. How to fix that?

Code:
optimize 7

#evButton=0
#myChoice=1
#RndButton=2
#StrButtonKey=3
#StrButtonRnd=4


; Set some application properties
MUIApplicationTitle "3ncrYptor"
MUIApplicationDescription "MUI encrypter/Decrypter program"

Statement CreateWin{}
Dim PageName$(2)

PageName$(0)="3ncrYpter"
PageName$(1)="d3crypt3r"

MUILabel 1,"Generate a random key?",#MUIO_Label_DoubleFrame
MUICycle 2,"Rnd key","Yes","No" : MUISet 2, #MUIA_ShowMe, 1
MUIString #StrButtonKey,"",20
MUIString #StrButtonRnd,"",20 : MUISet #StrButtonRnd, #MUIA_ShowMe, 1 MUISet #StrButtonRnd,#MUIA_Disabled,1
MUISimpleButton 0,"Load file to 3ncrYpt"
MUIHSpace 5,20 : MUIHSpace 12,20 : MUIVSpace 15,7 : MUIVSpace 16,20
MUILabel 13, "Your key code", #MUIO_Label_Centered 
MUISet 13,#MUIA_ShowMe,0
MUILabel 14, "Generated key code",#MUIO_Label_Centered
MUISet 14,#MUIA_ShowMe,1

MUIAddObjsHGroup 6,5,0,12
MUICreateHGroup 6

MUIAddObjsHGroup 7,1,#RndButton
MUICreateHGroup 7

MUIAddObjsHGroup 8,#StrButtonKey,#StrButtonRnd
MUICreateHGroup 8
MUISet 3,#MUIA_ShowMe, 0
;MUISet 4,#MUIA_ShowMe, 0

MUIAddObjsVGroup 9,7,15,13,14,8,16,6
MUICreateVGroup 9

MUIAddObjsPage 10,9
MUICreatePage 10,"3ncrYpt3r","d3crYpt3r"

MUICreateWindow 11,"crYpt3r","PAGE",10
MUIAddSubWindow 11

If MUICreateApplication <> True Then End

MUINotifyApp 11,#MUIA_Window_CloseRequest,1,-11
MUINotifyApp #RndButton,#MUIA_Cycle_Active,#MUIV_EveryTime,#myChoice
;MUINotifyApp #StrButtonKey,#MUI_EveryTime,

success=MUIOpenWindow(11)

End Statement


Statement rndKey{}
SHARED pass$
alpha$="ABCDEFGHIJKLMNOPQRSTYUVWXZabcdefghijklmnopqrstyuvwxz#/+=0123456789"

Dim s$(Len(alpha$))
Dim p$(20)

For x=0 To Len(alpha$)
  s$(x)=Mid$(alpha$,x,1)
Next

For i=0 To 19
  p$(i)=s$(Rnd(66))
  pass$=pass$+ p$(i)
Next

MUISet 3, #MUIA_ShowMe, 0
MUISet 13, #MUIA_ShowMe, 0
MUISet 4, #MUIA_ShowMe, 1 : MUISet 4, #MUIA_Disabled,1   ;Show rnd code, could'n be edited
MUISet 14, #MUIA_ShowMe, 1
MUISetString 4, pass$

End Statement


Statement noRnd{}
  SHARED pass$

  MUISet 4, #MUIA_ShowMe, 0
  MUISet 14, #MUIA_ShowMe, 0
  MUISet 3, #MUIA_ShowMe, 1
  MUISet 13, #MUIA_ShowMe, 1

  pass$=MUIGetString$(3)
  MUINotifyApp 3, #MUIA_String_Acknowledge, #MUIV_EveryTime, 3
                                                                                                                                                                                                                                                        
;  #MUIA_String_Acknowledge, 1
;  #MUIA_String_Contents
;  #MUIA_Textinput_RemainActive,1
;  MUISetString 3,pass$
;  MUIFreeObject 3

End Statement

success.l=0
myChoice.l=False
cy.l=0

WBStartup
FindScreen 0

CreateWin{}

Repeat
  ev.l=MUIWaitEvent
  Select ev
    Case #evButton
      ;MUISet 2, #MUIA_ShowMe, 1
    Case #myChoice
      cy=MUIGetCycle(2)
      If cy=1
        pass$=""
        rndKey{}
        NPrint pass$
      End If
      If cy=2
        pass$=""
        noRnd{}
        NPrint pass$
      End If
    End Select
Until ev=-11

MUICloseWindow 11

End
AlfaRomeo is offline  
Old 14 August 2019, 23:13   #5
Daedalus
Registered User
 
Daedalus's Avatar
 
Join Date: Jun 2009
Location: Dublin, then Glasgow
Posts: 6,334
Quote:
Originally Posted by AlfaRomeo View Post
Thanks Daedalus, I already checked some Mui docs but doesn´t found a valid result for my problem, the nearest result is through MUIWaitEvent.
I will continue searching until reach a good result for what I need
MUIWaitEvent (or MUIEvent if you want your code to loop when the GUI isn't being used) is exactly what you need. Your code in the last post looks sort of ok, but adding a notify in a function like that isn't really the way to do it, and might cause problems if you add it repeatedly.

You seem to have found it but the Autodocs for that attribute (and others) can be found here: MUIA_String_Acknowledge

So, something like this at the start of your code:
Code:
#myEventCode = 10

MUINotifyApp #myStringGadget, #MUIA_String_Acknowledge, #MUIV_EveryTime, #myEventCode
and then, you can detect that event with MUIWaitEvent:

Code:
Repeat
  ev.l = MUIWaitEvent
    Select ev
      Case #myEventCode
        Nprint "Enter pressed in my gadget"
    End Select
Until quit
Quote:
Originally Posted by AlfaRomeo View Post
Does someone can tell me why, in the code posted, the variable pass$=MUIGetString$(3) only assumes the string typed in the string gadget during the next input event, in this case, it is when it runs the statement noRnd{} for the 2nd time
It´s a MUI bug?.. How to fix that?
I'm not sure if the event being created after the read in the function could be the source of your problem with the string only being read at the second call, but it's worth trying anyway. I can't imagine it's a bug with MUI itself, but the Blitz MUI library does have a few bugs in it, especially in earlier versions. Still, I've used MUIGetString() in many programs and it appears to work as expected.
Daedalus is offline  
Old 17 August 2019, 23:54   #6
AlfaRomeo
A1200 040 SAM440EP 667
 
AlfaRomeo's Avatar
 
Join Date: Jan 2008
Location: Lisbon / Portugal
Posts: 873
Thanks for the help Daedalus

The problem is that, when the pass$=MUIGetString(3) is executed there is nothing yet in the string field and it doesn´t keep waiting for the input, so the execution leaves the statement noRnd{} with pass$="". Then, when the user clicks in the string field to type the text, the program already stays in MUIWaitEvent(), so the pass$ string variable only acquires whatever is typed in the string gadget when the next input event occurs.

I found a user with same problem:
https://forums.hollywood-mal.com/vie...140c5c442a7858
He solved the problem in C with a Wait(5)

I tried a Delay_() after the pass$=MUIGetString$(3) in Blitz Basic but it halts the program just allowing to write something in gadget string when delay_() is passed. Same with a loop with the pass$=MUIGetString$() inside.

I will try another approach to make the input in the string gadget field before, so when the MUIGetString$() is executed it will already have the string to be passed to pass$

Last edited by AlfaRomeo; 18 August 2019 at 11:26.
AlfaRomeo is offline  
Old 18 August 2019, 15:10   #7
AlfaRomeo
A1200 040 SAM440EP 667
 
AlfaRomeo's Avatar
 
Join Date: Jan 2008
Location: Lisbon / Portugal
Posts: 873
@Daedalus
With your help already fixed the text input in the string text:

Code:
  Repeat
    strEv.l=MUIWaitEvent
    pass$=MUIGetString$(3)
    MUINotifyApp 3, #MUIA_String_Acknowledge, #MUIV_EveryTime, #Evnt
  Until strEv=#Evnt
Thanks for your help
AlfaRomeo is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
Questions regarding INT2 interrupt handling Niklas support.Hardware 2 28 January 2019 08:09
Horizontal Group Has Content Partially Hidden in MUI v4, Not MUI v3.8a tygre support.Apps 6 29 February 2016 03:27
DOpus5 lister handling daxb Coders. Scripting 0 05 December 2015 15:55
Cookie handling alexh project.EAB 1 22 October 2007 21:52

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 12:07.

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.11325 seconds with 15 queries