Re: [BLACKBOX] Program freezes when window loses focus

From: [at]} <Bob>
Date: Tue, 29 Mar 2011 22:35:46 +0100

----boundary-LibPST-iamunique-1989349348_-_-
Content-type: text/plain

The principles behind ReadKey are in complete opposition to the principles
that Oberon (& BB) operate on. Oberon and BB operate on an event-driven
model in which the code that we write is expected to provide handlers that
the event loop calls in response to an event. In this sense they are always
'waiting for' a keystroke or similar event. In other words, it's
asynchronous, like an interrupt handler. You should not be writing code to
read directly from the keyboard.

The ReadKey procedure is based on a synchronous model and is a relic from
the days of Dos, Unix etc.

It's worth looking at the way the Oberon event loop is coded. You can see it
in at least 2 of the Wirth (& Reiser) books. When I first read it it gave me
an enormous insight into the way event-driven systems work - more than I got
from endless hours of trying to figure the way Windows does it.

B


> -----Original Message-----
> From: BlackBox [mailto:BLACKBOX{([at]})nowhere.xy
> Couture
> Sent: 29 March 2011 21:26
> To: BLACKBOX{([at]})nowhere.xy
> Subject: Re: [BLACKBOX] Program freezes when window loses focus
>
> At 06:42 PM 3/28/2011, Stephen Troy wrote:
> >Thanks, Rex, but it seems as though the application is really, really
> freezing, and it doesn't seem to respond to anything, up to and
> including a sledgehammer.
>
>
> Yes, I know. At this point I'm trying to understand it myself.
> This shows my profound ignorance of Windows programming, but beyond
> that, I'm trying to find a ReadKey method that works. With just the
> line
>
> REPEAT UNTIL ORD(XYplane.ReadKey()) #0
>
> the display freezes solid if you change focus with the mouse, but it
> still reponds to the keystroke if you <Alt><Tab> through windows.
>
> With
>
> REPEAT
> ProcessMessages
> UNTIL ORD(k.ReadKey()) # 0;
>
> ReadKey is unresponsive, and there are bizarre, unpredictable effects
> on the BB GUI. (Complete program below)
>
> Does BB have any simple, unfailing procedure to read input
> directly from the keyboard? Evidently XYplane.ReadKey doesn't work.
> There has to be something.
>
> Rex Couture
>
>
> MODULE TestReadKey; (* Not working *)
> IMPORT k:=XYplane,StdLog, Win:= WinApi;
>
> PROCEDURE ProcessMessages;
> VAR msg: Win.MSG; res: INTEGER;
> BEGIN
> WHILE Win.PeekMessage(msg, 0, 0, 0, Win.PM_REMOVE) # 0 DO
> res := Win.TranslateMessage(msg);
> res := Win.DispatchMessageA(msg)
> END
> END ProcessMessages;
>
> PROCEDURE P*;
> VAR c: CHAR;
> BEGIN
> REPEAT
> ProcessMessages
> UNTIL ORD(k.ReadKey()) # 0;
> StdLog.Ln;
> StdLog.String( 'If you see this, it works');
> END P;
> END TestReadKey.
>
>
> ----
> To unsubscribe, send a message with body "SIGNOFF BLACKBOX" to
> LISTSERV{([at]})nowhere.xy


----
To unsubscribe, send a message with body "SIGNOFF BLACKBOX" to LISTSERV{([at]})nowhere.xy----boundary-LibPST-iamunique-1989349348_-_-
Content-type: application/rtf
Content-transfer-encoding: base64
Content-Disposition: attachment; filename="rtf-body.rtf"
e1xydGYxXGFuc2lcYW5zaWNwZzEyNTJcZnJvbXRleHQgXGRlZmYwe1xmb250dGJsDQp7XGYwXGZz
d2lzcyBBcmlhbDt9DQp7XGYxXGZtb2Rlcm4gQ291cmllciBOZXc7fQ0Ke1xmMlxmbmlsXGZjaGFy
c2V0MiBTeW1ib2w7fQ0Ke1xmM1xmbW9kZXJuXGZjaGFyc2V0MCBDb3VyaWVyIE5ldzt9fQ0Ke1xj
b2xvcnRibFxyZWQwXGdyZWVuMFxibHVlMDtccmVkMFxncmVlbjBcYmx1ZTI1NTt9DQpcdWMxXHBh
cmRccGxhaW5cZGVmdGFiMzYwIFxmMFxmczIwIFRoZSBwcmluY2lwbGVzIGJlaGluZCBSZWFkS2V5
IGFyZSBpbiBjb21wbGV0ZSBvcHBvc2l0aW9uIHRvIHRoZSBwcmluY2lwbGVzXHBhcg0KdGhhdCBP
YmVyb24gKCYgQkIpIG9wZXJhdGUgb24uIE9iZXJvbiBhbmQgQkIgb3BlcmF0ZSBvbiBhbiBldmVu
dC1kcml2ZW5ccGFyDQptb2RlbCBpbiB3aGljaCB0aGUgY29kZSB0aGF0IHdlIHdyaXRlIGlzIGV4
cGVjdGVkIHRvIHByb3ZpZG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unique-1989349348_-_---
Received on Tue Mar 29 2011 - 23:35:46 UTC

This archive was generated by hypermail 2.3.0 : Thu Sep 26 2013 - 06:30:16 UTC