Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Buttons as images
#1
Is there a possibility to check if the mouse is in a specific region
and do a action/start a macro if it clicks there?

I thaugt about a variable named rect.a or something similiar, where the coordinates of the button are saved.
Another variable should change if the button was clicked.

Code:
Copy      Help
int Rect.a
int Rect.b
int Action

if (Rect.a & ifk((1)))
    Action = 1
if (Rect.b & ifk((1)))
    Action = 2
I tried to arrange that for hours, but it seems that i did it completeley wrong so i want to start from zero again.
I searched in the forum too, but ive found nothing similiar.

Maybe someone can teach me a bit in complex if statements.
From other Programming Languages i know this way:

Code:
Copy      Help
if (Fu != 0 & Bar == 1 | Fubar >= 20) {
       Blop = 10,
       Fubar -=10
}
## if Fu is not 0 and Bar is 10 or fubar greater or same as 20,
## Blop is ten and Fubar is value - 10
#2
Macro Macro1449
Trigger F12     Help - how to add the trigger to the macro
Code:
Copy      Help
;define 2 rectangles for testing: one at top-left corner, and another at right from it, both 20x20
RECT ra rb
ra.left=0; ra.top=0; ra.right=20; ra.bottom=20
rb=ra; OffsetRect &rb 20 0

;get mouse coordinates
POINT p
xm p

;test
int Action
if PtInRect(&ra p.x p.y)
,Action=1
else if PtInRect(&rb p.x p.y)
,Action=2

;result
out Action
#3
Macro Macro1417
Code:
Copy      Help
if Fu != 0 and Bar == 1 or Fubar >= 20
,Blop = 10,
,Fubar -=10

;if Fu is not 0 and Bar is 10 or fubar greater or same as 20,
;Blop is ten and Fubar is value - 10
#4
Thanks again Gintaras!

Sometimes its so easy that i just cant believe that i failed. :lol:
#5
Sorry for doublepost.
Your Code works very well, but now i tried to add the ifk to it, and it errors
"unexpected identifier."
Code:
Copy      Help
;test
int Action
if PtInRect(&ra p.x p.y) and ifk((1))
,Action=1
,else
,,Action=0
else if PtInRect(&rb p.x p.y) and ifk((1))
,Action=2
,else
,,Action=0
,
But in the QM Help it says that ifk((1)) stands for Mouse left button?
Did i misunderstood something or has the code changed?
#6
Yes but ifk is not function. It can be used only like if.

Macro Macro1424
Code:
Copy      Help
int leftPressed
ifk((1)) leftPressed=1

if PtInRect(&ra p.x p.y) and leftPressed

or

Code:
Copy      Help
;test
ifk (1)
,int Action
,if PtInRect(&ra p.x p.y)
,,Action=1
,else if PtInRect(&rb p.x p.y)
,,Action=2

or

Macro Macro1431
Code:
Copy      Help
;test
int Action
if PtInRect(&ra p.x p.y) and RealGetKeyState(1)
,Action=1
else if PtInRect(&rb p.x p.y) and RealGetKeyState(1)
,Action=2
else
,Action=0


Forum Jump:


Users browsing this thread: 1 Guest(s)