AutoHotkey Community

It is currently May 27th, 2012, 6:58 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 7 posts ] 
Author Message
PostPosted: March 6th, 2006, 7:52 pm 
hello,

It is possible to detect mouse click on specified windows areas like windows' caption?

I try to implement in AHK custom menu that I call "Windows Context" - it behaves similar to native Windows' SysMenu (Restore, Move, Size, Minimize, etc), but have more custom items like Make Topmost, Change Priority, Kill Process, Hide, etc.

At this time I have use PowerPro, which can hook pressing any mouse button on different windows' areas (caption, minimize or close buttons, etc). But unfortunatelly PowerPro lacks ability to build custom GUIs with standard Windows' controls (like combo boxes, list views, sliders, radio buttons, etc.). It offers only simple GUIs called "bars" and few input boxes.

And another question:
If I want to add in AHK shortcut, whitch should work only in specified window (by exename or window class name) then the only way to do this is using "IF WINACTIVE <target window>" block after defining shortcut?


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: March 6th, 2006, 8:03 pm 
Offline

Joined: August 24th, 2005, 5:17 pm
Posts: 1237
It's not currently possible to replace the right-click menu on a window in that fashion. If you have a middle mouse button then you could easily modify my script here to show a menu (instead of closing the window as it currently does):

http://www.autohotkey.com/forum/viewtopic.php?p=50920

And to make hotkeys sensitive to which window is active, use the #IfWinActive command (see the manual for how to use it).


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 6th, 2006, 8:26 pm 
Offline

Joined: September 25th, 2005, 4:31 pm
Posts: 610
Try this:

Code:
~MButton::
   CoordMode, Mouse, Screen
   MouseGetPos, m_x, m_y, m_hw_target

   ; WM_NCHITTEST
   SendMessage, 0x84,, ( m_y << 16 )|m_x,, ahk_id %m_hw_target%
   
   if ( m_hw_target = WinExist( "Untitled - Notepad" ) )
   {
      if ( ErrorLevel = 2 )          ; HTCAPTION
         text = caption
      else if ( ErrorLevel = 3 )      ; HTSYSMENU
         text = system menu
      else if ( ErrorLevel = 8 )      ; HTMINBUTTON
         text = minimize button
      else if ( ErrorLevel = 9 )      ; HTMAXBUTTON
         text = maximize button
      else if ( ErrorLevel = 20 )      ; HTCLOSE
         text = close button
      else if ( ErrorLevel = 21 )      ; HTHELP
         text = help button
      
      if ErrorLevel in 2,3,8,9,20,21
         MsgBox, Hello, Notepad's %text%!
   }
return


or (hold the right mouse button for greater than 300 ms)

Code:
RightButton?double_click@threshold = 200
RightButton?hold@threshold := RightButton?double_click@threshold+100
return

RButton::
    if ( A_TickCount-RightButton?double_click@threshold < RightButton@mark )    ; double-click detected
    {
        SetTimer, timer_RightButton, off

        MsgBox, right-button double-click detected
        return
    }

    RightButton@mark := A_TickCount

    MouseGetPos, m_x1, m_y1
    SetTimer, timer_RightButton, 10
return

timer_RightButton:
    if ( A_TickCount-RightButton@mark >= RightButton?hold@threshold )           ; hold detected
    {
        SetTimer, timer_RightButton, off

      CoordMode, Mouse, Screen
      MouseGetPos, m_x, m_y, m_hw_target
   
      ; WM_NCHITTEST
      SendMessage, 0x84,, ( m_y << 16 )|m_x,, ahk_id %m_hw_target%
      
      if ( m_hw_target = WinExist( "Untitled - Notepad" ) )
      {
         if ( ErrorLevel = 2 )          ; HTCAPTION
            text = caption
         else if ( ErrorLevel = 3 )      ; HTSYSMENU
            text = system menu
         else if ( ErrorLevel = 8 )      ; HTMINBUTTON
            text = minimize button
         else if ( ErrorLevel = 9 )      ; HTMAXBUTTON
            text = maximize button
         else if ( ErrorLevel = 20 )      ; HTCLOSE
            text = close button
         else if ( ErrorLevel = 21 )      ; HTHELP
            text = help button
         
         if ErrorLevel in 2,3,8,9,20,21
            MsgBox, Hello, Notepad's %text%!
      }
    }
    else if ( A_TickCount-RightButton@mark >= RightButton?double_click@threshold
                and !GetKeyState( "RButton", "P" ) )                            ; single-click detected
    {
        SetTimer, timer_RightButton, off

        Send, {RButton}
    }
    else
    {
        MouseGetPos, m_x2, m_y2

        if ( m_x1 "," m_y1 != m_x2 "," m_y2 )                                   ; drag detected
        {
            SetTimer, timer_RightButton, off

            Send, {RButton down}
           
            KeyWait, RButton
           
            Send, {RButton up}
        }
    }
return


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 7th, 2006, 12:06 am 
Great, thanks a lot.


Report this post
Top
  
Reply with quote  
PostPosted: June 28th, 2006, 3:43 am 
Offline

Joined: June 8th, 2006, 2:52 am
Posts: 89
Location: Northern Ohio - USA
This thread is coming closest (so far in my lengthy search) to what I am trying to do.

I'm working on a script that renames folders based upon the current name of the folder. What it does is change a numeric date stamp (part of the folder name) that I have been using, such as 062706 (for June 27, 2006) to my newer format 06_0627. ( When you have a lot of folders beginning with different date codes, this works better when Windows sorts the folders by name. It makes them fall into groups by year, then by month and day).

I have the script so it does the renaming very nicely on a single folder. Now I want to step back and script the operation to start selecting the next folder name down the list and run the same script. Once I get that accomplished, I can set it up to do a large number of folder names in sequence, without my intervention. But I haven't yet found a way to tell the mouse to right-click the next folder name after the script has moved down to it and highlighted it.

I am using the Send, {Down} command at the end of my current script, and it drops the blue highlight down to the next folder name. But if I press the hotkey for the script again, it renames the folder I just came from, because the mouse is still focused there. I guess I need a "focus the mouse where the highlighted text is" command.

Any suggestions?

Here is the script I am using so far:

Code:
;      RECEIPT DATE CHANGER SCRIPT
;
;   This script will, when applied to highlighted text,
;   change my older date format i.e. 010206 (Jan 2nd, 2006) to my new format i.e. 06_0102
;
^0::                ;Set this script's hotkey to CTRL+0

Clipboard =            ;Clear the Clipboard
Sleep, 500            ;wait 0.5 second

;   This next section deals strictly with Folder navigation! Although the script works in a text document, it is ;   

designed for use in renaming Paperport record folders and files.
;   MANUALLY HIGHLIGHT THE FIRST FOLDER NAME IN THE TREE
; +++++++++++++++++++++++++++++++++++++++++++++++   
   MouseClick, Right         ;Right-Click the current highlighted folder name
   Sleep, 1000
   Send, {Up}{Up}            ;select the Rename submenu item - Counting down from the top, Rename
                  ;can get relocated depending upon menu additions by installed programs
                  ;but the last 2 in the last are all standard Windows XP items, so I
                  ;counted up from the bottom instead.
   Sleep, 1000
   Send, {Enter}            ;activate selected Rename option
   Sleep, 1000
;++++++++++++++++++++++++++++++++++++++++++++++++
{
   Send, ^C            ;Copy the highlighted text to the clipboard
   
   OLD_DATE = %Clipboard%        ;Save the copied text into the variable named OLD_DATE

   StringLeft, WORK_ZONE, OLD_DATE, 6   ;place the first 6 chars. of the OLD_DATE var. into
                  ;a new variable named WORK_ZONE

   StringRight, YEAR, WORK_ZONE, 2      ;Place the last 2 char of WORK_ZONE into
                  ;a new variable named YEAR

   StringLeft, DAY_MON, OLD_DATE, 4   ;place the first 4 char. of the OLD_DATE var, into
                  ;a new variable named DAY_MO

   NEW_DATE = %YEAR%_%DAY_MON%      ;compile the new date string by adding YEAR, an underscore char.,      

                  ;and DAY_MON

   StringTrimLeft, CUTOFF, OLD_DATE, 6   ;trim the first 6 char. (the old format date) from OLD_DATE

   Converted = %NEW_DATE%%CUTOFF%      ;the new var. Converted now holds the NEW_DATE plus the remaining
                  ;Characters from the original highlighted text


   Clipboard = %Converted%         ;load the clipboard with the contents of the var. Converted

   Sleep, 500            ;0.5 sec. delay
   Send, ^V            ;Paste the clipboard content back to replace the originally
                  ;higlighted text.
   Send, {Enter}            ;Finish renaming
   Sleep, 1000
   Send, {Down}            ;Move down and highlight the next folder in the viewed tree
   SoundBeep,1500, 150
   
}
Return

_________________
Zoandar - new user - still learning.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 28th, 2006, 9:40 am 
Offline

Joined: December 27th, 2005, 1:46 pm
Posts: 6837
Location: France (near Paris)
Uh? Do you know you have a FileMove command, which can also be used to rename files and folders? It will be probably much more faster and reliable.
BTW, there are also lot of good renaming freeware utilities, but it is less fun this way (but faster to get them working...).

Oh, if you really want to go your way, sending F2 will avoid you using the context menu... It often works on most applications too. WinMenuSelectItem may help too.

_________________
Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 28th, 2006, 8:16 pm 
Offline

Joined: June 8th, 2006, 2:52 am
Posts: 89
Location: Northern Ohio - USA
Thanks! I'll look into the FileMove command. One of the hard parts about trying to find a command is that, unless it catches my eye, or I read every single description of each command in sequence (not likely) I will miss the fact that some of these commands have alot of capabilities that are not readily revealed in their name.

Another user had already turned me on to the F2 command whle I was waiting for a reply to this post. The problem I am having now with using F2 is that I can't get my accursed/beloved Paperport (PPT) program's folder view to recognize the

Code:
 Send, {Down}

command to get the next folder selected. I am backing off and going to try writing the script to do what I want in Windows Explorer. Once I get that figured out, I'll tackle PPT' folder view (much similar to Windows Explorer) again.

_________________
Zoandar - new user - still learning.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: migz99, sjc1000 and 71 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group