Solved

Get out of a routine being executed!

Posted on 2004-04-25
11
191 Views
Last Modified: 2012-05-04
Assume that I have a routine below:

// Global variable
var EscapeKey : boolean; // Whether the escape key is being
                                     // pressed or not

procedure TForm1.Image1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  .........
  If EscapeKey = true then
  begin
    Some Code;
  end;
  ......  
end;

I tried to write Some Code that releases the mouse being down when user presses Escape key without physically release the left mouse button by hand. However, I can't do this.

Anyone here know how to do this, please help me!

Bri


0
Comment
Question by:brimountain
  • 4
  • 3
  • 3
  • +1
11 Comments
 
LVL 6

Accepted Solution

by:
bpana earned 50 total points
ID: 10911367
try

Mouse_Event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);

Bogdan
0
 
LVL 17

Expert Comment

by:mokule
ID: 10911379
I don't quite understand what do You mean by release mouse.

But in any case You sould do it rather here

procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if Key = VK_ESCAPE then
    begin
// Your code
    end;
end;

Set
 Form1.KeyPreview := True;
0
 
LVL 6

Expert Comment

by:bpana
ID: 10911410
use it in OnMouseMove:

if ssLeft in Shift then
begin
  Mouse_Event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
end;

Bogdan
0
 

Author Comment

by:brimountain
ID: 10911620
Hi Bpana

Your answer is nearly what's I need.  What I actually want is that:

While I am holding the left mouse button down, I press the Escape key (still keep holding the left mouse button down). It functions exactly as I physically release my index fingure holding down the left mouse button.  

Brimountain
0
 
LVL 17

Expert Comment

by:mokule
ID: 10911706
But You must be aware that MouseUp will be fired once more when the left mouse button will be really released

procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if Key = VK_ESCAPE then
    begin
    Mouse_Event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
    end;
end;
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 6

Expert Comment

by:bpana
ID: 10912080
hi,

on the OnKeyDown event:

  if Key = VK_ESCAPE then
    if csLButtonDown in Button1.ControlState then
      Mouse_Event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);

Bogdan
0
 
LVL 6

Expert Comment

by:bpana
ID: 10912095
change Button1 with (Sender as TControl)

if Key = VK_ESCAPE then
  if csLButtonDown in (Sender as TControl).ControlState then
    Mouse_Event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);

Bogdan
0
 
LVL 3

Expert Comment

by:MikProg
ID: 10916574
You need to
  SetCaptureControl(nil);
or
  Mouse.Capture:=0;
I.E.
  if Key = VK_ESCAPE then
    SetCaptureControl(nil);
This cancels mouse capture mode -> Mouse events will be sended to control where mouse cursor moved.
0
 

Author Comment

by:brimountain
ID: 10917573
Thank you so much, but i am pretty busy nowadays. I'll try your comments when free and get back soon.
0
 

Author Comment

by:brimountain
ID: 10944256
Sorry, but none of your solution fully answers my question.

Could you please open Paint pgrogram (Start/All programs/Accessories/Paint) then click on the Pecil icon on the left hand side toolbar then draw something and press Escape key while still hold the left mouse button down to see how it works? I want the solution like that.

Bri
0
 
LVL 17

Expert Comment

by:mokule
ID: 10944532
You've got such a solution from me.:)

This is the line.
// Your code
There are no other possibilities. You must undo all changes done during the operation.
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now