Ok, I see what you mean. It is currently not working under WINDOWS. I am working on that. The next release 1.23-22 should have improved EVENT command and EVENT?() function, which together should do the job.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
Anonymous
-
2018-08-06
Hi,
so is it working now? I cannot get this work on my android device. It is crucial function to me to create program which is doing something and I can interrupt it with a keypress. do you have example code please?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Here is something to try. It seems to work on Win32, even though I was mainly investigating some Android quirks having to do with rotating the Android device and getting the program to detect the changed screen parameters and redraw as well as quit on a touch. It does detect and report keypresses.
#!/usr/bin/xbasicProgramSined' Initialize global variablesClrScaleLeft,ScaleTop,ScaleRight,ScaleBottomClrScaleHM,ScaleHB,ScaleVM,ScaleVB'@FlushEvents@Main'@FlushEventsEndProcedureMain()LocalPrevLeft%,PrevTop%,PrevWidth%,PrevHeight%LocalCurrLeft%,CurrTop%,CurrWidth%,CurrHeight%LocalQuittingTime%,RedrawNeeded%LocalEventMask%,EventType%LocalKEvents%,MEvents%,WEvents%' ClsScreen28!1280x1024x24,no-oponAndroid?Get_ScreenSizePrevLeft%,PrevTop%,PrevWidth%,PrevHeight%PrintPrevLeft%,PrevTop%,PrevWidth%,PrevHeight%' All no-op on Android?OpenW1MoveW1,10,20SizeW1,800,480TitleW1,"Sined, Sealed, Delivered"ShowPagePause0.1' Initialize the event loopClrKEvents%,MEvents%,WEvents%ClrEventMask%,EventType%QuittingTime%=FalseRedrawNeeded%=True' Our very first event pump in X11 BASIC While(EventType%<>0)OrNotQuittingTime%' Looks like we need to poll for resizes due to device rotations ' or the on screen keyboard being summoned or dismissedGet_Geometry1,CurrLeft%,CurrTop%,CurrWidth%,CurrHeight%' Is the left, top coordinate ever not (0, 0) ?If(CurrWidth%<>PrevWidth%)Or(CurrHeight%<>PrevHeight%)ThenPrint"Geometry changed"PrevLeft%=CurrLeft%PrevTop%=CurrTop%PrevWidth%=CurrWidth%PrevHeight%=CurrHeight%RedrawNeeded%=True' Device rotations also appear to cause spurious kb events?' @FlushEvents' ClsEndIfIfRedrawNeeded%ThenPrint"Redrawing"@Redraw()RedrawNeeded%=FalseEndIf' Peek at any/all pending events, keyboard/mouse/windowEventMask%=1Or2Or4Or8Or0x40Or0x40000Or0x200000PrintHex$(EventMask%);" ";EventMask%=Event?(EventMask%)PrintHex$(EventMask%);" ";IfEventMask%Then' Fetch a pending eventEventEventType%!LotsoffunoptionaloutparameterscangoherePrintEventType%;" ";Else' No events are waitingEventType%=0EndIfSelectEventType%Case10,13' Window moved or resizedPrint"Window"IncWEvents%RedrawNeeded%=TrueCase2,3' Keyboard key down/upPrint"Keybd"IncKEvents%' Beware of spurious kb events on Android' QuittingTime% = TrueCase4,5,6' Mouse button down/up, movePrint"Mouse"IncMEvents%QuittingTime%=TrueDefault' No news is good newsPrint"Nada"EndSelectIf(EventType%=0)AndNotQuittingTime%ThenPause1EndIfWendPrintKEvents%;" key, ";MEvents%;" mouse, ";WEvents%;" window"ReturnProcedureRedraw()LocalLeft%,Top%,Width%,Height%LocalcX,cY,pX,pY,thetaOpenW1Get_Geometry1,Left%,Top%,Width%,Height%PrintLeft%,Top%,Width%-1,Height%-1' Sanity check coordinate systemColorColor_RGB(0,0,1,0.7)DrawLeft%,Top%To(Left%+Width%-1),(Top%+Height%-1)ShowPageColorColor_RGB(0,1,0,0.7)Draw(Left%+Width%-100),Top%ToLeft%,Top%DrawToLeft%,(Top%+Height%-1)DrawTo(Left%+Width%-1),(Top%+Height%-1)DrawTo(Left%+Width%-1),Top%ShowPage' Reject screen's reality and substitute our own@SetScale(-10,10,-2,2)' Set up our axesColorColor_RGB(1,1,1)@ScaleLine(-10,0,10,0)@ScaleLine(0,2,0,-2)ForcY=0ToScaleTopStep0.25@ScaleLine(-0.1,cY,0.1,cY)@ScaleLine(-0.1,-cY,0.1,-cY)NextcYForcY=0ToScaleTop@ScaleLine(-0.25,cY,0.25,cY)@ScaleLine(-0.25,-cY,0.25,-cY)NextcYForcX=0ToScaleRightStep(Pi/4)@ScaleLine(cX,0.025,cX,-0.025)@ScaleLine(-cX,0.025,-cX,-0.025)NextcXForcX=0ToScaleRightStep(Pi/2)@ScaleLine(cX,0.05,cX,-0.05)@ScaleLine(-cX,0.05,-cX,-0.05)NextcXForcX=0ToScaleRightStepPi@ScaleLine(cX,0.1,cX,-0.1)@ScaleLine(-cX,0.1,-cX,-0.1)NextcXShowPage' Plot f(x)ColorColor_RGB(1,0,0)ClrpX,pY,cX,cYpX=1e200Fortheta=ScaleLeftToScaleRightStep(Pi/100)cX=thetacY=@f(theta)If(ScaleLeft<=pX)And(pX<=ScaleRight)Then@ScaleLine(pX,pY,cX,cY)EndIfpX=cXpY=cYNextthetaShowPageReturnDefFnf(x)=(Sin(x)+(Cos(5*x)/2))ProcedureSetScale(NewLeft,NewRight,NewBottom,NewTop)LocalLeft%,Top%,Width%,Height%Get_Geometry1,Left%,Top%,Width%,Height%PrintLeft%,Top%,Width%-1,Height%-1ScaleLeft=NewLeftScaleTop=NewTopScaleRight=NewRightScaleBottom=NewBottomScaleHM=(Width%-1)/(NewRight-NewLeft)ScaleHB=Left%-((Width%-1)/(NewRight-NewLeft))*NewLeftScaleVM=(Height%-1)/(NewBottom-NewTop)ScaleVB=Top%-((Height%-1)/(NewBottom-NewTop))*NewTopPrintScaleLeft,ScaleRight,ScaleBottom,ScaleTopPrintScaleHM,ScaleHB,ScaleVM,ScaleVBReturnProcedureScaleLine(x0,y0,x1,y1)DrawScaleHM*x0+ScaleHB,ScaleVM*y0+ScaleVB\ToScaleHM*x1+ScaleHB,ScaleVM*y1+ScaleVBReturn' Android appears to allow events to accumulate between runsProcedureFlushEvents()LocalEventMask%,EventType%ClrEventMask%,EventType%Print"FlushEvents ";Repeat' Are any events clogging the queue?' Peek at any/all pending events, keyboard/mouse/windowEventMask%=1Or2Or4Or8Or0x40Or0x40000Or0x200000EventMask%=Event?(EventMask%)IfEventMask%Then' Catch and kill pending eventEventEventType%Else' No events are waitingEventType%=0EndIfPrintEventType%;" ";UntilEventType%=0Print""Return' Stolen from http://x11-basic.sourceforge.net/FAQ.htmlFunctionChrW$(Unicode%)IfUnicode%<0x80ThenReturnChr$(Unicode%)ElseIfUnicode%<0x2000ThenReturnChr$(0xc0Or((Unicode%Div64)And0x1f))\+Chr$(0x80Or(Unicode%And0x3f))ElseReturnChr$(0xe0Or((Unicode%Div(64*64))And0xf))\+Chr$(0x80Or((Unicode%Div64)And0x3f))\+Chr$(0x80Or(Unicode%And0x3f))EndIfEndFunction
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Is there a possibility to get information about pressed keys in a graphic window, without stop the programm until a key is pressed?
I am using the ms windows version of X11 basic.
Wait! Have you tried the EVENT?() function? It can tell you at least if an event is pending without waiting for it.
Ok, I see what you mean. It is currently not working under WINDOWS. I am working on that. The next release 1.23-22 should have improved EVENT command and EVENT?() function, which together should do the job.
Hi,
so is it working now? I cannot get this work on my android device. It is crucial function to me to create program which is doing something and I can interrupt it with a keypress. do you have example code please?
Here is something to try. It seems to work on Win32, even though I was mainly investigating some Android quirks having to do with rotating the Android device and getting the program to detect the changed screen parameters and redraw as well as quit on a touch. It does detect and report keypresses.