Mastodon

General: Stop a Loop with ALT+S but ignore any other User action

Sanford Aranoff wrote:
> I would like to prevent any user action during the loop except for a
> menu Alt S, which would stop the loop.
> Considering your comment, what would you suggest?

Its 1:00 AM now and this is as close as I get for the moment.
There is one thing bugging me. Its not working completely as
you’ve asked. For the moment it will stop when Alt+S is pressed,
but it will not fire your menu. This is handled differently (other
message) and can’t remember at the moment which.

The emergency solution will let the user think that his
keyboard is becoming bad and he/she will try to press
Alt+S again (a little harder) and then it will be handled
normal again since the loop is stopped

Hope this help you on the way.
– Pieter

[code lang=”delphi”]{——————————————————————————}
{ Params : = The time in msec. program flow will be’suspended’.
{ Returns : none.
{ Descript: Wait for about msec.
{——————————————————————————}
procedure Delay(DelayTime: word);
var
StopTime : TDateTime;
Sec : word;
Msec : word;
OkPassIt : boolean;
Msg : TMsg;
begin
if DelayTime < 2 then Exit; Sec := DelayTime div 1000; MSec := DelayTime mod 1000; StopTime := Now + EncodeTime( 0, 0, Sec, MSec ); repeat OkPassIt := False; if PeekMessage(Msg, 0, 0, 0, PM_NOREMOVE) then with Msg do case Message of WM_LBUTTONDOWN, WM_MBUTTONDOWN, WM_RBUTTONDOWN, WM_KEYFIRST..WM_KEYLAST: if (Message = WM_SYSKEYDOWN) and (wParam = 83) then {Alt+S} begin StopTime := Now; // Emergency solution OkPassIt := True; end; else OkPassIt := True; end; if OkPassIt then Application.HandleMessage else PeekMessage(Msg, 0, 0, 0, PM_REMOVE); // Eat it until (Now > StopTime);
end;

[/code]
– – – – – – – – – – –

Next SendMessages does work on my PC and ‘presses’ the
Alt+S outside the loop. I’ve got these codes by watching
WinSight32 (from Delphi). If this doen’t work for you, you
might be better of in the b.p.d.winapi for the question “how
to press the Alt+S (menu) key from code”.
Also do a search at www.deja.com maybe somebody else
did solve your problem before.

HTH
– Pieter

[code lang=”delphi”]procedure Delay(DelayTime: word);
var
StopTime : TDateTime;
Sec : word;
Msec : word;
AltS : boolean;
OkPassIt : boolean;
Msg : TMsg;
begin
Sec := DelayTime div 1000;
MSec := DelayTime mod 1000;

AltS := False;
StopTime := Now + EncodeTime( 0, 0, Sec, MSec );
repeat
OkPassIt := False;
if PeekMessage(Msg, 0, 0, 0, PM_NOREMOVE) then
with Msg do
case Message of
WM_LBUTTONDOWN,
WM_MBUTTONDOWN,
WM_RBUTTONDOWN,
WM_KEYFIRST..WM_KEYLAST:
if (Message = WM_SYSKEYDOWN) and (wParam = 83) then {Alt+S}
AltS := True;
else
OkPassIt := True;
end;

if OkPassIt then
Application.HandleMessage
else
PeekMessage(Msg, 0, 0, 0, PM_REMOVE); // Eat it
until (Now > StopTime) or AltS;

if AltS then
begin
SendMessage(Application.Handle, WM_SYSKEYDOWN, $12, $20380001); // alt
key
SendMessage(Application.Handle, WM_SYSKEYDOWN, $53, $201F0001); // + S
SendMessage(Application.Handle, WM_SYSCHAR, $73, $201F0001); //
generated by dispatch
SendMessage(Application.Handle, WM_SYSKEYUP, $53, $F01F0001); // S up
SendMessage(Application.Handle, WM_KEYUP, $12, $F0380001); // aalt
up
end;
end;
[/code]
– – – – – –

One other message you might want to ‘eat’ is…
WM_LBUTTONDBLCLK,

[tags]Delphi, Misc[/tags]

0 Kommentare zu “General: Stop a Loop with ALT+S but ignore any other User action

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht.