{"id":179,"date":"2007-05-12T16:42:05","date_gmt":"2007-05-12T14:42:05","guid":{"rendered":" http:\/\/www.nsonic.de\/blog\/2007\/05\/general-stop-a-loop-with-alts-but-ignore-any-other-user-action\/"},"modified":"2007-05-12T16:42:07","modified_gmt":"2007-05-12T14:42:07","slug":"general-stop-a-loop-with-alts-but-ignore-any-other-user-action","status":"publish","type":"post","link":"https:\/\/www.nsonic.de\/blog\/2007\/05\/general-stop-a-loop-with-alts-but-ignore-any-other-user-action\/","title":{"rendered":"General: Stop a Loop with ALT+S but ignore any other User action"},"content":{"rendered":"<p>Sanford Aranoff wrote:<br \/>\n<em>> I would like to prevent any user action during the loop except for a<br \/>\n> menu Alt S, which would stop the loop.<br \/>\n> Considering your comment, what would you suggest?<br \/>\n<\/em><\/p>\n<p>Its 1:00 AM now and this is as close as I get for the moment.<br \/>\nThere is one thing bugging me. Its not working completely as<br \/>\nyou&#8217;ve asked. For the moment it will stop when Alt+S is pressed,<br \/>\nbut it will not fire your menu. This is handled differently (other<br \/>\nmessage) and can&#8217;t remember at the moment which.<\/p>\n<p>The emergency solution will let the user think that his<br \/>\nkeyboard is becoming bad and he\/she will try to press<br \/>\nAlt+S again (a little harder) and then it will be handled<br \/>\nnormal again since the loop is stopped <\/p>\n<p>Hope this help you on the way.<br \/>\n&#8211; Pieter<br \/>\n<!--more--><br \/>\n[code lang=&#8221;delphi&#8221;]{&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;}<br \/>\n{ Params  :  = The time in msec. program flow will be&#8217;suspended&#8217;.<br \/>\n{ Returns : none.<br \/>\n{ Descript: Wait for about  msec.<br \/>\n{&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;}<br \/>\nprocedure Delay(DelayTime: word);<br \/>\nvar<br \/>\n  StopTime  : TDateTime;<br \/>\n  Sec       : word;<br \/>\n  Msec      : word;<br \/>\n  OkPassIt  : boolean;<br \/>\n  Msg       : TMsg;<br \/>\nbegin<br \/>\n  if DelayTime < 2 then Exit;\n\n  Sec  := DelayTime div 1000;\n  MSec := DelayTime mod 1000;\n\n  StopTime := Now + EncodeTime( 0, 0, Sec, MSec );\n  repeat\n    OkPassIt := False;\n    if PeekMessage(Msg, 0, 0, 0, PM_NOREMOVE) then\n      with Msg do\n        case Message of\n          WM_LBUTTONDOWN,\n          WM_MBUTTONDOWN,\n          WM_RBUTTONDOWN,\n          WM_KEYFIRST..WM_KEYLAST:\n              if (Message = WM_SYSKEYDOWN) and (wParam = 83) then  {Alt+S}\n              begin\n                StopTime := Now;  \/\/ Emergency solution\n                OkPassIt := True;\n              end;\n       else\n         OkPassIt := True;\n       end;\n\n    if OkPassIt then\n      Application.HandleMessage\n    else\n      PeekMessage(Msg, 0, 0, 0, PM_REMOVE); \/\/ Eat it\n   until (Now > StopTime);<br \/>\nend;<\/p>\n<p>[\/code]<br \/>\n&#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211;<\/p>\n<p>Next SendMessages does work on my PC and &#8216;presses&#8217; the<br \/>\nAlt+S outside the loop. I&#8217;ve got these codes by watching<br \/>\nWinSight32 (from Delphi). If this doen&#8217;t work for you, you<br \/>\nmight be better of in the b.p.d.winapi for the question &#8220;how<br \/>\nto press the Alt+S (menu) key from code&#8221;.<br \/>\nAlso do a search at www.deja.com maybe somebody else<br \/>\ndid solve your problem before.<\/p>\n<p>HTH<br \/>\n&#8211; Pieter<\/p>\n<p>[code lang=&#8221;delphi&#8221;]procedure Delay(DelayTime: word);<br \/>\nvar<br \/>\n  StopTime  : TDateTime;<br \/>\n  Sec       : word;<br \/>\n  Msec      : word;<br \/>\n  AltS      : boolean;<br \/>\n  OkPassIt  : boolean;<br \/>\n  Msg       : TMsg;<br \/>\nbegin<br \/>\n  Sec  := DelayTime div 1000;<br \/>\n  MSec := DelayTime mod 1000;<\/p>\n<p>  AltS := False;<br \/>\n  StopTime := Now + EncodeTime( 0, 0, Sec, MSec );<br \/>\n  repeat<br \/>\n    OkPassIt := False;<br \/>\n    if PeekMessage(Msg, 0, 0, 0, PM_NOREMOVE) then<br \/>\n      with Msg do<br \/>\n        case Message of<br \/>\n          WM_LBUTTONDOWN,<br \/>\n          WM_MBUTTONDOWN,<br \/>\n          WM_RBUTTONDOWN,<br \/>\n          WM_KEYFIRST..WM_KEYLAST:<br \/>\n              if (Message = WM_SYSKEYDOWN) and (wParam = 83) then  {Alt+S}<br \/>\n                AltS := True;<br \/>\n       else<br \/>\n         OkPassIt := True;<br \/>\n       end;<\/p>\n<p>    if OkPassIt then<br \/>\n      Application.HandleMessage<br \/>\n    else<br \/>\n      PeekMessage(Msg, 0, 0, 0, PM_REMOVE); \/\/ Eat it<br \/>\n  until (Now > StopTime) or AltS;<\/p>\n<p>  if AltS then<br \/>\n  begin<br \/>\n    SendMessage(Application.Handle, WM_SYSKEYDOWN, $12, $20380001); \/\/ alt<br \/>\nkey<br \/>\n    SendMessage(Application.Handle, WM_SYSKEYDOWN, $53, $201F0001); \/\/ + S<br \/>\n    SendMessage(Application.Handle, WM_SYSCHAR,    $73, $201F0001); \/\/<br \/>\ngenerated by dispatch<br \/>\n    SendMessage(Application.Handle, WM_SYSKEYUP,   $53, $F01F0001); \/\/ S up<br \/>\n    SendMessage(Application.Handle, WM_KEYUP,      $12, $F0380001); \/\/ aalt<br \/>\nup<br \/>\n  end;<br \/>\nend;<br \/>\n[\/code]<br \/>\n&#8211; &#8211; &#8211; &#8211; &#8211; &#8211;<\/p>\n<p>One other message  you might want to &#8216;eat&#8217; is&#8230;<br \/>\n  WM_LBUTTONDBLCLK,<\/p>\n<p>[tags]Delphi, Misc[\/tags]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Sanford Aranoff wrote: > I would like to prevent any user action during the loop except for a > menu Alt S, which&hellip;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":""},"categories":[11],"tags":[75,107],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p71Tml-2T","_links":{"self":[{"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/posts\/179"}],"collection":[{"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/comments?post=179"}],"version-history":[{"count":0,"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/posts\/179\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/media?parent=179"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/categories?post=179"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/tags?post=179"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}