October 26, 2020, 12:37:43 AM

Author Topic: Trying To Recognize KeyPress Like Enter..  (Read 2354 times)

Offline Hardcoal

  • Sr. Member
  • ****
  • Posts: 472
Trying To Recognize KeyPress Like Enter..
« on: May 31, 2018, 10:36:28 PM »
Hi. Im not expert with MaxGUI so thats why the naive question..

im trying to recognize when enter was pressed.. in this loop

   
Code: [Select]

Repeat

    WaitEvent()

Select CurrentEvent.id
Case EVENT_WINDOWCLOSE, EVENT_APPTERMINATE
rTextfield.setText defaultTxt
Exit
Case EVENT_GADGETACTION
If CurrentEvent.source = rOkButton Then     'OK
Exit
ElseIf CurrentEvent.source = rCancelButton  'Cancle
rTextfield.setText defaultTxt
InfoAnswer.CancledFlg = True
Exit
End If
Case EVENT_KEYDOWN
Print "#4"
End Select

Forever

i tried EVENT_KEYDOWN but it doesnt work..

how can i recognize a keypress.. ?

i should mention that im trying to recognize it will im using TextField. So what i want is that when i press Enter, The Textfield editing will end..

i also tried  PollEvent() instead of waitevent()

I think i recall now that i need to enable something on the code header.. like EnableInput or something..

ok i think i recall.. its called EnablePolledInput() .. but im not certain.. 
No it didnt work as well.. I dunno..

thanks
Go with the Flow

Offline Hardcoal

  • Sr. Member
  • ****
  • Posts: 472
Re: Trying To Recognize KeyPress Like Enter..
« Reply #1 on: June 02, 2018, 02:04:11 AM »
was is that hard of a request that no one has an answer to?
i really tried everything.. this crap should be simple..

maybe its because im using it unders xors3d that causes the not being able to read keyboard inputs possible..

I dont know anymore
Go with the Flow

Offline iWasAdam

  • Hero Member
  • *****
  • Posts: 1973
Re: Trying To Recognize KeyPress Like Enter..
« Reply #2 on: June 02, 2018, 05:03:45 AM »
While I can't help you with MaxGui itself. I do know a lot about the event system as I built my own gui system.

Here's the event code I used - it was rocket tested. There will be lots of stuff you wont have (like the calls), but it gives the core keyboard stuff for you to start with.
This is meant as the ONLY event system. Everything should be built from this core out:
Code: [Select]

Print ".PROGMAIN "+MilliSecs()
EnablePolledInput()
' EndSongTimer()
AppQueuePrev = 0

Print ".PROGMAIN start "+MilliSecs()
AppActive = True

If AppResize ActivateGadget AppCanvas

Local ignoredraw:Int = False
' repeat
' AppQueue = PollEvent()
' Until AppQueue <> 0

Print ".PROGMAIN queue "+MilliSecs()
ActivateWindow AppWindow
Print ".PROGMAIN while "+MilliSecs()

RedrawUI()


While Not AppQuit
WaitEvent()
ignoreDraw = AppRedrawingUI

Select EventID()
Case EVENT_APPTERMINATE, EVENT_WINDOWCLOSE
AppQuit = True

Case EVENT_MENUACTION
EventMenu(EventID(), EventData(), EventSource() )

Case EVENT_MOUSELEAVE
AppMouseIn = False
' Print "mouse OUT"
Case EVENT_MOUSEENTER
garbage.check()
AppMouseIn = True
' Print "mousein"

Case EVENT_KEYCHAR
' Print "event keychar data="+EventData()
Select EventData()
Case 167
controlKeyDown = CurrentEvent.mods & MODIFIER_CONTROL
shiftKeyDown = CurrentEvent.mods & MODIFIER_SHIFT
commandKeyDown = CurrentEvent.mods & MODIFIER_COMMAND
EventKeyPlusMinus(MX, MY, CurrentEvent.mods & MODIFIER_CONTROL, CurrentEvent.mods & MODIFIER_COMMAND, CurrentEvent.mods & MODIFIER_SHIFT, False )
End Select

Case EVENT_KEYUP
' Print "event keyup"
controlKeyDown = CurrentEvent.mods & MODIFIER_CONTROL
shiftKeyDown = CurrentEvent.mods & MODIFIER_SHIFT
commandKeyDown = CurrentEvent.mods & MODIFIER_COMMAND
EventKeyUp(MX, MY, EventData(), CurrentEvent.mods & MODIFIER_CONTROL, CurrentEvent.mods & MODIFIER_COMMAND, CurrentEvent.mods & MODIFIER_SHIFT )
If Not(controlKeyDown) Then
oldControlKeyDown = False
End If
OldKeyDown = -1
' EventKeyUp(EventData() )

Case EVENT_KEYREPEAT
' Print "event keyrepeat"
controlKeyDown = CurrentEvent.mods & MODIFIER_CONTROL
shiftKeyDown = CurrentEvent.mods & MODIFIER_SHIFT
commandKeyDown = CurrentEvent.mods & MODIFIER_COMMAND
EventKeyDown(MX, MY, EventData(), CurrentEvent.mods & MODIFIER_CONTROL, CurrentEvent.mods & MODIFIER_COMMAND, CurrentEvent.mods & MODIFIER_SHIFT, True )
' EventKeyDown( EventData(), True )

Case EVENT_KEYDOWN
' Print "event keydown"
controlKeyDown = CurrentEvent.mods & MODIFIER_CONTROL
If controlKeyDown Then
oldControlKeyDown = True
End If
shiftKeyDown = CurrentEvent.mods & MODIFIER_SHIFT
commandKeyDown = CurrentEvent.mods & MODIFIER_COMMAND
EventKeyDown(MX, MY, EventData(), CurrentEvent.mods & MODIFIER_CONTROL, CurrentEvent.mods & MODIFIER_COMMAND, CurrentEvent.mods & MODIFIER_SHIFT, False )
OldKeyDown = EventData()
' EventKeyDown( EventData(), False )

Case EVENT_MOUSEDOWN



Hopefully you will find something int there to give you an idea?

Offline Hardcoal

  • Sr. Member
  • ****
  • Posts: 472
Re: Trying To Recognize KeyPress Like Enter..
« Reply #3 on: June 02, 2018, 05:31:58 AM »
thanks for attempting to help.
ill check it out and let you know if it helped

Regards
Go with the Flow

Offline Henri

  • Sr. Member
  • ****
  • Posts: 263
Re: Trying To Recognize KeyPress Like Enter..
« Reply #4 on: June 02, 2018, 07:08:47 AM »
Hi hc,

textfields won't catch enter key by default.

I know three solutions to this:

   1. Hidden OK-button to catch enter key. (easy)
   2. Change texfield -> textarea and use SetGadgetFilter. (normal)
   3. Change default style of textfield to catch enter key (advanced)

For number 1 & 2 see this post http://www.mojolabs.nz/posts.php?topic=107784


-Henri
- Got 01100011 problems, but the bit ain't 00000001

Offline Hardcoal

  • Sr. Member
  • ****
  • Posts: 472
Re: Trying To Recognize KeyPress Like Enter..
« Reply #5 on: June 05, 2018, 03:41:33 AM »
ok thanks henry i made it work also thanks notadam..
Go with the Flow

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal