Jump to content

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

mouse kicks on the sreen edge


  • Please log in to reply
20 replies to this topic
Azevedo
  • Members
  • 179 posts
  • Last active: Nov 04 2015 04:37 PM
  • Joined: 07 Mar 2012
Hey dudes!

I was wondering if it is possible to trigger an action through mouse kicks on the sreen edge, similar gestures.
I thought of using a timer like SetTimer, watchmouse, 100 but it is not functional since it will uses cpu in vain most part of the time just to check mouse x and y.

is there a way to that?

(see, the idea is not gestures and all that... i need only "kicks on the sreen edge")

8-)

dylan904
  • Members
  • 706 posts
  • Last active: Nov 14 2016 06:17 PM
  • Joined: 18 Jan 2012
You aren't very clear as to what "action" you wish upon.

Azevedo
  • Members
  • 179 posts
  • Last active: Nov 04 2015 04:37 PM
  • Joined: 07 Mar 2012

You aren't very clear as to what "action" you wish upon.


Does the action really matters?
okay.. lets say....

msgbox hey, you hit the screen edge 2 times in less than 500ms


crystal clear now! :D

dylan904
  • Members
  • 706 posts
  • Last active: Nov 14 2016 06:17 PM
  • Joined: 18 Jan 2012
Okay, you would probably use something like this...
~LButton::

MouseGetPos, X, Y, Win

WinGetPos,,, W, H, A

If (X < 20 || Y < 15 || W - X < 20 || H - Y < 15)

   MsgBox You Clicked The Edge!

return


MilesAhead
  • Members
  • 578 posts
  • Last active: Feb 29 2016 05:15 PM
  • Joined: 21 Jan 2009
I think he's trying to detect that the mouse pointer went off an edge rather than using a click. When I saw "kick" at first I thought it was "click." I don't know how to constantly check it without running up the CPU. Seems like that's what Windows does when you pull the mouse past the Taskbar when it's set in AutoHide mode. Probably needs something a bit more responsive and low level to avoid dragging down system performance. Unless maybe there's a mouse hook for that edge test.

"Some people, when confronted with a problem, think I know, I'll use regular expressions.  Now they have two problems."

- Jamie Zawinski


dylan904
  • Members
  • 706 posts
  • Last active: Nov 14 2016 06:17 PM
  • Joined: 18 Jan 2012
Well what is the name of the window you would like to know when the mouse has left the edge then Barney Gumble, I mean Azevedo?

MasterFocus
  • Moderators
  • 4323 posts
  • Last active: Jan 28 2016 01:38 AM
  • Joined: 08 Apr 2009
Search for "mouse corner".

Related: this topic and nimda's snippet

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Antonio França -- git.io -- github.com -- ahk4.net -- sites.google.com -- ahkscript.org

Member of the AHK community since 08/Apr/2009. Moderator since mid-2012.


Azevedo
  • Members
  • 179 posts
  • Last active: Nov 04 2015 04:37 PM
  • Joined: 07 Mar 2012
Hey everybody!
Thanks for the answers.
Yes, by kick i mean: touch the mouse on the screen edges 2x quikly, not click event, move event.
Certainly windows doesnt keep querying x & y constanly using the cpu. it uses some hardware hook/event to get notified whenever the mouse changes x or y.
Afaik, there is no MOUSE MOVE HOOK on AHK, sadly.
No way i'll set the cpu to keep quering about x & y constantly on AHK.

But thanks everyone!

MilesAhead
  • Members
  • 578 posts
  • Last active: Feb 29 2016 05:15 PM
  • Joined: 21 Jan 2009
It could probably be done with some DllCall code
<!-- m -->http://stackoverflow... ... pplication<!-- m -->

But it would be easier if you could hit a key at the same time. Then just call MouseGetPos. Even back in Dos days there was a Dos interrupt that could be used to call user code on mouse events.

"Some people, when confronted with a problem, think I know, I'll use regular expressions.  Now they have two problems."

- Jamie Zawinski


rbrtryn
  • Members
  • 1177 posts
  • Last active: Sep 11 2013 08:04 PM
  • Joined: 22 Jun 2011
Looks like what you would need to do is register a TrackMouseEvent and then monitor for WM_MOUSEHOVER and WM_MOUSELEAVE events. That combined with a SendMessage involving WM_NCHITTEST should do the trick.

My Scripts are written for the latest released version of AutoHotkey.

Need a secure, accessible place to backup your stuff? Use Dropbox!


Azevedo
  • Members
  • 179 posts
  • Last active: Nov 04 2015 04:37 PM
  • Joined: 07 Mar 2012
hmm those seems to fit!

any sample with AHK? (forgive my newbieness)

thanks!

G. Sperotto
  • Members
  • 539 posts
  • Last active: Jun 20 2015 04:54 PM
  • Joined: 12 Dec 2011
Hi Azevedo.

É sempre bom ver mais uns brazucas por aqui :wink:

You can do that without a hook by using OnMessage() and MouseGetPos.

The code bellow does it with 4 1-pixel-thin windows. The called function simply gets the current mouse position and displays it in a message box. It does so only when the borders of the screen are touched. The XAddresses and YAddresses can be mathematically compared to retrieve which border was "kicked". Also, to get an idea on how to implement time checks, see A_TickCount.

Gui 2: +AlwaysOnTop -Caption
Gui 2: Color, 0x000000
WidthOfGui1 := A_ScreenWidth - 1
Gui 2: Show, w1 h%A_ScreenHeight% x%WidthOfGui1% y0
Gui 2: +Owner

Gui 3: +AlwaysOnTop -Caption
Gui 3: Color, 0x000000
Gui 3: Show, w1 h%A_ScreenHeight% x0 y0
Gui 3: +Owner

Gui 4: +AlwaysOnTop -Caption
Gui 4: Color, 0x000000
Gui 4: Show, w%A_ScreenWidth% h1 x0 y0
Gui 4: +Owner

Gui 5: +AlwaysOnTop -Caption
Gui 5: Color, 0x000000
HeightOfGui4 := A_ScreenHeight - 1
Gui 5: Show, w%A_ScreenWidth% h1 x0 y%HeightOfGui4%
Gui 5: +Owner

Onmessage(0x200, "Shout")

return

Shout(wParam, lParam)
{
	CoordMode, Mouse, Screen
	MouseGetPos, XAddress, YAddress
	msgbox % "XAddress: " XAddress "`n" "YAddress: " YAddress
}

:O I'm actually surprised no one thought about doing it like this because it is a pretty straightforward idea coming from the example on the youtube AhkTuts video series


Best wishes.

"What is a suitable automation? Whatever saves your day for the greater matters."
Barcoder - Create QR Codes and other Barcodes using only Autohotkey !!


MilesAhead
  • Members
  • 578 posts
  • Last active: Feb 29 2016 05:15 PM
  • Joined: 21 Jan 2009
G. Sperotto that works nicely. Only thing for use by others it should have a mechanism to recover from work area change(the user moves the Taskbar.) As it is now it works on all 4 edges. But if I move Taskbar to the top it stops reacting on that edge. Evidently Taskbar stay on top trumps Gui AlwaysOnTop. :)

I have a getworkarea function but I haven't used multiple guis and am not accustomed to moving them around.

edit: those who autohide taskbar may not care. But it would be nice to periodically check the work area for change and accommodate for those who don't use autohide. I have this preliminary code.

edit2: (one would think it better to get notification of work area change. I tried it in another app and it doesn't work. I also saw MSDN articles where it didn't work as documented. Screen res change notification worked fine. But work area change notification was useless.. that's why the polling approach. )

L1 := 0, L2 := 0, T1 := 0, T2 := 0, R1 := 0, R2 := 0, B1 := 0, B2 := 0
_GetWorkArea(L2,T2,R2,B2)
L1 := L2, T1 := T2, R1 := R2, B1 := B2

; your code that creates and shows the guis here should use work are info
; then poll however often for work area change .. 10 seconds to try it
SetTimer,WorkAea,10000
Onmessage(0x200, "Shout")
return

WorkAea:
  _GetWorkArea(L2,T2,R2,B2)
  if (L1 != L2)
    ; Taskbar moved to left edge .. move gui
  else if (T1 != T2)
    ; Taskbar moved to top ...
  else if (R1 != R2)
    ; Taskbar moved to right edge ...
  else if (B1 != B2)
    ; Taskbar moved to bottom
; copy work area info to check for change next
; timer trigger
  L1 := L2, T1 := T2, R1 := R2, B1 := B2
; set it back to long polling period
; presumably if you get an edge hit you would
; shorten the polling for one go to fix it during the
; time the user is kicking it if unresponsive on one edge.. maybe 1/4 sec.
  SetTimer,WorkAea,10000
return


_GetWorkArea(ByRef left, ByRef top, ByRef right, ByRef bottom)
{
  VarSetCapacity(work_area,16,0)
  success := DllCall( "SystemParametersInfo", "uint", 0x30, "uint", 0, "uint", &work_area, "uint", 0 )
  if success =
  {
    return 0
  }
  left := NumGet(work_area,0)
  top := NumGet(work_area,4)
  Right := NumGet(work_area,8)
  Bottom := NumGet(work_area,12)
  return 1
}

Shout(wParam, lParam)
{
   ; do shout code then check for work area change
   SetTimer,WorkAea,250
}

"Some people, when confronted with a problem, think I know, I'll use regular expressions.  Now they have two problems."

- Jamie Zawinski


MilesAhead
  • Members
  • 578 posts
  • Last active: Feb 29 2016 05:15 PM
  • Joined: 21 Jan 2009
On second thought Reload allows a less complicated accommodation. Just check work area like every 3 seconds. Or you could put a key trigger in if the user wants to manually notify the program of change.

Something like this works even out of Scite

#SingleInstance force
L1 := 0, L2 := 0, T1 := 0, T2 := 0, R1 := 0, R2 := 0, B1 := 0, B2 := 0
_GetWorkArea(L2,T2,R2,B2)
L1 := L2, T1 := T2, R1 := R2, B1 := B2

Gui 2: +AlwaysOnTop -Caption
Gui 2: Color, 0x000000
WidthOfGui1 := A_ScreenWidth - 1
Gui 2: Show, w1 h%A_ScreenHeight% x%WidthOfGui1% y0
Gui 2: +Owner

Gui 3: +AlwaysOnTop -Caption
Gui 3: Color, 0x000000
Gui 3: Show, w1 h%A_ScreenHeight% x0 y0
Gui 3: +Owner

Gui 4: +AlwaysOnTop -Caption
Gui 4: Color, 0x000000
Gui 4: Show, w%A_ScreenWidth% h1 x0 y0
Gui 4: +Owner

Gui 5: +AlwaysOnTop -Caption
Gui 5: Color, 0x000000
HeightOfGui4 := A_ScreenHeight - 1
Gui 5: Show, w%A_ScreenWidth% h1 x0 y%HeightOfGui4%
Gui 5: +Owner
SetTimer,WorkAea,3000
Onmessage(0x200, "Shout")
return

WorkAea:
  _GetWorkArea(L2,T2,R2,B2)
  if (L1 != L2) or (T1 != T2) or (R1 != R2) or (B1 != B2)
    Reload
return

Shout(wParam, lParam)
{
   CoordMode, Mouse, Screen
   MouseGetPos, Xaddress, Yaddress
   
  If (Xaddress = 0)
   MsgBox, 8256, , You Kicked Left Edge
  else if (Yaddress = 0)
    MsgBox, 8256, , You Kicked Top Edge
  else if (Xaddress = A_ScreenWidth - 1)
    MsgBox, 8256, , You Kicked Right Edge
  else if ( Yaddress = A_ScreenHeight - 1)
    MsgBox, 8256, , You Kicked Bottom Edge
}

_GetWorkArea(ByRef left, ByRef top, ByRef right, ByRef bottom)
{
  VarSetCapacity(work_area,16,0)
  success := DllCall( "SystemParametersInfo", "uint", 0x30, "uint", 0, "uint", &work_area, "uint", 0 )
  if success =
  {
    return 0
  }
  left := NumGet(work_area,0)
  top := NumGet(work_area,4)
  Right := NumGet(work_area,8)
  Bottom := NumGet(work_area,12)
  return 1
}

"Some people, when confronted with a problem, think I know, I'll use regular expressions.  Now they have two problems."

- Jamie Zawinski


G. Sperotto
  • Members
  • 539 posts
  • Last active: Jun 20 2015 04:54 PM
  • Joined: 12 Dec 2011
Very nice MilesAhead. I had not actually considered the possibility of a workarea change. The script was supposed to be only an example, but it does look better now :)


I was wondering if it is possible to trigger an action through mouse kicks on the sreen edge, similar gestures.


Have you checked Shirubadappuru's MouseGestureL?

Just in case you are interested in triggering actions with mouse movements.

"What is a suitable automation? Whatever saves your day for the greater matters."
Barcoder - Create QR Codes and other Barcodes using only Autohotkey !!