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.
:::basic#!/usr/bin/xbasicProgramSined' Initialize global variables Clr ScaleLeft, ScaleTop, ScaleRight, ScaleBottom Clr ScaleHM, ScaleHB, ScaleVM, ScaleVB '@FlushEvents@Main'@FlushEventsEndProcedure Main() Local PrevLeft%, PrevTop%, PrevWidth%, PrevHeight% Local CurrLeft%, CurrTop%, CurrWidth%, CurrHeight% Local QuittingTime%, RedrawNeeded% Local EventMask%, EventType% Local KEvents%, MEvents%, WEvents% 'ClsScreen28 ! 1280x1024x24, no-oponAndroid?
Get_ScreenSizePrevLeft%, PrevTop%, PrevWidth%, PrevHeight%
PrintPrevLeft%, PrevTop%, PrevWidth%, PrevHeight%
' All no-op on Android? OpenW 1 MoveW 1, 10, 20 SizeW 1, 800, 480 TitleW 1, "Sined, Sealed, Delivered" ShowPage Pause 0.1 'InitializetheeventloopClrKEvents%, MEvents%, WEvents%
ClrEventMask%, EventType%
QuittingTime% = FalseRedrawNeeded% = True' Our very first event pump in X11 BASIC While (EventType% <> 0) Or Not QuittingTime% 'Lookslikeweneedtopollforresizesduetodevicerotations' or the on screen keyboard being summoned or dismissed Get_Geometry 1, CurrLeft%, CurrTop%, CurrWidth%, CurrHeight% 'Istheleft, topcoordinateevernot (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' Cls EndIf If RedrawNeeded% Then Print "Redrawing" @Redraw() RedrawNeeded% = False EndIf 'Peekatany/allpendingevents, keyboard/mouse/windowEventMask% = 1Or2Or4Or8Or0x40Or0x40000Or0x200000PrintHex$(EventMask%); " ";
EventMask% = Event?(EventMask%)
PrintHex$(EventMask%); " ";
IfEventMask% Then' Fetch a pending event Event EventType% ! Lots of fun optional out parameters can go here Print EventType%; " "; Else 'NoeventsarewaitingEventType% = 0EndIfSelectEventType%
Case10, 13' Window moved or resized Print "Window" Inc WEvents% RedrawNeeded% = True Case 2, 3 'Keyboardkeydown/upPrint"Keybd"IncKEvents%
' Beware of spurious kb events on Android 'QuittingTime% = TrueCase4, 5, 6' Mouse button down/up, move Print "Mouse" Inc MEvents% QuittingTime% = True Default 'NonewsisgoodnewsPrint"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 system Color Color_RGB(0, 0, 1, 0.7) Draw Left%, Top% To (Left% + Width% - 1), (Top% + Height% - 1) ShowPage Color Color_RGB(0, 1, 0, 0.7) Draw (Left% + Width% - 100), Top% To Left%, Top% Draw To Left%, (Top% + Height% - 1) Draw To (Left% + Width% - 1), (Top% + Height% - 1) Draw To (Left% + Width% - 1), Top% ShowPage 'Rejectscreen'srealityandsubstituteourown@SetScale(-10, 10, -2, 2)
' Set up our axes Color Color_RGB(1, 1, 1) @ScaleLine(-10, 0, 10, 0) @ScaleLine(0, 2, 0, -2) For cY = 0 To ScaleTop Step 0.25 @ScaleLine(-0.1, cY, 0.1, cY) @ScaleLine(-0.1, -cY, 0.1, -cY) Next cY For cY = 0 To ScaleTop @ScaleLine(-0.25, cY, 0.25, cY) @ScaleLine(-0.25, -cY, 0.25, -cY) Next cY For cX = 0 To ScaleRight Step (Pi / 4) @ScaleLine(cX, 0.025, cX, -0.025) @ScaleLine(-cX, 0.025, -cX, -0.025) Next cX For cX = 0 To ScaleRight Step (Pi / 2) @ScaleLine(cX, 0.05, cX, -0.05) @ScaleLine(-cX, 0.05, -cX, -0.05) Next cX For cX = 0 To ScaleRight Step Pi @ScaleLine(cX, 0.1, cX, -0.1) @ScaleLine(-cX, 0.1, -cX, -0.1) Next cX ShowPage 'Plotf(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 runsProcedure FlushEvents() Local EventMask%, EventType% Clr EventMask%, EventType% Print "FlushEvents "; Repeat 'Areanyeventscloggingthequeue?
' Peek at any/all pending events, keyboard/mouse/window EventMask% = 1 Or 2 Or 4 Or 8 Or 0x40 Or 0x40000 Or 0x200000 EventMask% = Event?(EventMask%) If EventMask% Then 'CatchandkillpendingeventEventEventType%
Else' No events are waiting EventType% = 0 EndIf Print EventType%; " "; Until EventType% = 0 Print ""Return'Stolenfromhttp://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.