AutoHotkey Community

It is currently May 27th, 2012, 1:06 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 20 posts ]  Go to page Previous  1, 2
Author Message
 Post subject:
PostPosted: July 4th, 2008, 10:19 pm 
Hi there. This script is almost exactly what I was looking for, with the exception that it handles copy/paste a little differently than linux (I admit it, I'm trying to make windows just a little more friendly when I have to use it...)

Normally on a linux system there are essentially two clipboard: the board for mouse selected text, and the one for ctrl-x/c/v. That way, you can ctrl-c something, highlight text, and ctrl-v to paste what you ctrl-c's earlier in its place.

So, I've added that functionality to the code. This if my first time scripting for AHK, so if you see a better way to handle it, please let me know.

Cheers!

Code:
CoordMode Mouse, Screen

~LButton::   
If A_PriorHotkey = %A_ThisHotkey%
{
   If A_TimeSincePriorHotkey < 300 ; 300 ms to double click, adjust if needed
   {
      tempClipBoard := ClipBoardAll      ; save old clipboard
      ClipBoard =
      Send ^c                    ; selection -> clipboard
     mmClip := ClipBoard        ; store selection in custom clipboard
     Clipboard :=tempClipBoard  ; restore clipboard for ctl-c and ctl-v
   }
   else
   {
      MouseGetPos x0, y0            ; save start mouse position
      Loop
      {
        Sleep 20                    ; yield time to others
        GetKeyState keystate, LButton
        IfEqual keystate, U, {
          MouseGetPos x, y          ; position when button released
          break
        }
      }
   if (x-x0 > 5 or x-x0 < -5 or y-y0 > 5 or y-y0 < -5)
   {                             ; mouse has moved
      tempClipBoard := ClipBoardAll      ; save old clipboard
      ClipBoard =
      Send ^c                    ; selection -> clipboard
     mmClip := ClipBoard        ; store selection in custom clipboard
     Clipboard :=tempClipBoard  ; restore clipboard for ctl-c and ctl-v
   }
   return
   }
}

~Mbutton::
   tempClipBoard := Clipboard   ;temporarily store clipboard
   Clipboard := mmClip          ;restore selection into clipboard
   Send, ^v                     ;Paste via middle mouse click
   Clipboard := tempClipBoard   ;restore original clipboard
return


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: July 4th, 2008, 10:36 pm 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
I am sure some people will like your solution. The problem with it is that it changes globally the function of middle-click, double-click, triple-click... Because Windows does not define the corresponding actions, programs assign their own functions for multi-clicks, like selecting word / sentence / paragraph / section / document, or opening / closing tabs. They will not work as before. This is why I suggested using key combinations, which are left unused in most applications.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 5th, 2008, 3:41 am 
I have no particular argument with what you're saying at all. When I play games, for example, I disable the script so that it doesn't interrupt the game on accident. It seems, however, that for the common things that I do in Windows, the script is incredibly nice because I don't have to remember that things are different when I'm in Windows--I can just get things done.

The problem with keyboard shortcuts is that instead making it so I don't have to think about the particulars of the OS, it actually increases the amount of things I have to think about by adding new shortcuts that I will unlikely use anywhere else. (I've removed the multi-clicking issues, so only the middle click is being compromised now...)

So, in the end, it depends on what you need. I mean, if you need the functionality and don't mind turning the script off at certain times, then it's probably for you. If you use programs that map the middle click pretty constantly (I can honestly only think of games here) then you probably either want to forgo the script entirely, or assign those shortcuts.

I'm posting my updated script here, that removes the double-click hassles. You'll have to drag-select to copy, but nothing else strange happens now. Use or not, whatever works for you. This works for me.

Code:
CoordMode Mouse, Screen

~LButton::   
   MouseGetPos x0, y0            ; save start mouse position
   Loop
   {
     Sleep 20                    ; yield time to others
     GetKeyState keystate, LButton
     IfEqual keystate, U, {
       MouseGetPos x, y          ; position when button released
       break
     }
   }
   if (x-x0 > 5 or x-x0 < -5 or y-y0 > 5 or y-y0 < -5)
   {                             ; mouse has moved
      tempClipBoard := ClipBoardAll      ; save old clipboard
      ClipBoard =
      Send ^c                    ; selection -> clipboard
     mmClip := ClipBoard        ; store selection in custom clipboard
     Clipboard :=tempClipBoard  ; restore clipboard for ctl-c and ctl-v
   }
   return



~Mbutton::
   tempClipBoard := Clipboard   ;temporarily store clipboard
   Clipboard := mmClip          ;restore selection into clipboard
   Send, ^v                     ;Paste via middle mouse click
   Clipboard := tempClipBoard   ;restore original clipboard
return


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: July 11th, 2008, 9:27 am 
Offline

Joined: February 22nd, 2007, 11:32 am
Posts: 7
tristion I'm using your script now and I like it alot.

One problem for me though. Everytime I move a file the path ends up at the clipboard. Is there a way around that?

cheers
/michael


Report this post
Top
 Profile  
Reply with quote  
 Post subject: problem in GVIM
PostPosted: February 27th, 2010, 8:48 am 
The code is great, but I found a problem: when I use GVIM and select some texts with mouse, the selection is cancelled because of a "copy" command, any solution for that? I want to keep my selection in GVIM... Thank you


Report this post
Top
  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 20 posts ]  Go to page Previous  1, 2

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bon, sks, Yahoo [Bot] and 21 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