Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

[function] SelectArea()


  • Please log in to reply
8 replies to this topic
Learning one
  • Members
  • 1483 posts
  • Last active: Jan 02 2016 02:30 PM
  • Joined: 04 Apr 2009

WARNING: This is old thread. It is continued here.

 

This method was presented before but here is my version. See also: LetUserSelectRect
License: In my opinion, this code isn't capable to be protected by nobodies copyright - so it can be used freely. In case it's under my copyright, I declare it public domain.

Function

SelectArea(Options="") { ; by Learning one
/*
Returns selected area. Return example: 22|13|243|543
Options: (White space separated)
- c color. Default: Blue.
- t transparency. Default: 50.
- g GUI number. Default: 99.
- m CoordMode. Default: s. s = Screen, r = Relative
*/
CoordMode, Mouse, Screen
MouseGetPos, MX, MY
CoordMode, Mouse, Relative
MouseGetPos, rMX, rMY
CoordMode, Mouse, Screen
loop, parse, Options, %A_Space%
{
Field := A_LoopField
FirstChar := SubStr(Field,1,1)
if FirstChar contains c,t,g,m
{
StringTrimLeft, Field, Field, 1
%FirstChar% := Field
}
}
c := (c = "") ? "Blue" : c, t := (t = "") ? "50" : t, g := (g = "") ? "99" : g , m := (m = "") ? "s" : m
Gui %g%: Destroy
Gui %g%: +AlwaysOnTop -caption +Border +ToolWindow +LastFound
WinSet, Transparent, %t%
Gui %g%: Color, %c%
Hotkey := RegExReplace(A_ThisHotkey,"^(\w* & |\W*)")
While, (GetKeyState(Hotkey, "p"))
{
Sleep, 10
MouseGetPos, MXend, MYend
w := abs(MX - MXend), h := abs(MY - MYend)
X := (MX < MXend) ? MX : MXend
Y := (MY < MYend) ? MY : MYend
Gui %g%: Show, x%X% y%Y% w%w% h%h% NA
}
Gui %g%: Destroy
if m = s ; Screen
{
MouseGetPos, MXend, MYend
If ( MX > MXend )
temp := MX, MX := MXend, MXend := temp
If ( MY > MYend )
temp := MY, MY := MYend, MYend := temp
Return MX "|" MY "|" MXend "|" MYend
}
else ; Relative
{
CoordMode, Mouse, Relative
MouseGetPos, rMXend, rMYend
If ( rMX > rMXend )
temp := rMX, rMX := rMXend, rMXend := temp
If ( rMY > rMYend )
temp := rMY, rMY := rMYend, rMYend := temp
Return rMX "|" rMY "|" rMXend "|" rMYend
}
}

Examples:
Rbutton::MsgBox,,, % SelectArea(), 1.5
Mbutton::MsgBox,,, % SelectArea("cLime t100 g55 mr"), 1.5


guest3456
  • Guests
  • Last active:
  • Joined: --
thank you for this

majkinetor
  • Moderators
  • 4512 posts
  • Last active: Jul 29 2016 12:40 AM
  • Joined: 24 May 2006

License: In my opinion, this code isn't capable to be protected by nobodies copyright - so it can be used freely.

You can consider Unlicensed copyright.

IMO, the best one out there.
Posted Image

Learning one
  • Members
  • 1483 posts
  • Last active: Jan 02 2016 02:30 PM
  • Joined: 04 Apr 2009
First post edited - I explicitly "unlicensed" myself :D (in case that code is under my copyright)

majkinetor
  • Moderators
  • 4512 posts
  • Last active: Jul 29 2016 12:40 AM
  • Joined: 24 May 2006

This method was presented before, but nobody created function so I did.


There is also LetUserSelectRect.
Posted Image

Learning one
  • Members
  • 1483 posts
  • Last active: Jan 02 2016 02:30 PM
  • Joined: 04 Apr 2009
For everybody's reference, link included in first post

guest3456
  • Guests
  • Last active:
  • Joined: --
can you explain the regex?

...
	Hotkey := RegExReplace(A_ThisHotkey,"^(\w* & |\W)")
	While, (GetKeyState(Hotkey, "p"))
	{



guest3456
  • Guests
  • Last active:
  • Joined: --

can you explain the regex?

...
	Hotkey := RegExReplace(A_ThisHotkey,"^(\w* & |\W)")
	While, (GetKeyState(Hotkey, "p"))
	{


i guess the idea is to remove modifiers? but this wont work:

^!f2::
   msgbox, % RegExReplace(A_ThisHotkey,"^(\w* & |\W)") 
return

i know nothing about RegEx but to remove all modifiers at the start of the string, what about this?

^!f2::
   msgbox, % RegExReplace(A_ThisHotkey,"^(\W*)") 
return


Learning one
  • Members
  • 1483 posts
  • Last active: Jan 02 2016 02:30 PM
  • Joined: 04 Apr 2009

Can you explain the regex? ... I guess the idea is to remove modifiers?

Yes, my intention was to remove:
- modifiers or
- first key in two key combination hotkeys where & stands between them.

^!f2 hotkey doesn't work as intended indeed because there are 2 not word characters. Thanks for report. Here is the RegEx fix:
Hotkey := RegExReplace(A_ThisHotkey,"^(\w* & |\W[color=red]*[/color])")
I updated first post.