AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

LAN Clipboard sharing

 
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
Terrapin



Joined: 15 Aug 2005
Posts: 107
Location: North Carolina

PostPosted: Sat Jan 07, 2006 11:21 am    Post subject: LAN Clipboard sharing Reply with quote

This really is some very simple code which does something I've been meaning to get around to, for my own use. Any feedback is appreciated. I have no idea whether there are already free utilities which serve this purpose. Thanks, Bob


Code:
;-  Uses ClipboardAll to save (theoretically) any type of valid clipboard
;- data to a shared folder on a local area network.  Any station on the
;- LAN may then retrieve the data to it's clipboard. 
;-
;-  I am finding it quite useful, mostly because I have two boxes connected,
;- and often tend to forget that I can't COPY on one and PASTE on the ohter.
;- Now, I can.
;-
;-  This works, but is very much incomplete.  Mainly, it should not be used
;- in this form on any LAN where security is an issue.
;
;-  And, the main exception to types of data, are actual files.  I have moved
;- raw image data, etc. 
;
;  01/07/2006

#SingleInstance force
Main:
If FileExist("netclip.ini")
   IniRead, FilePath, netclip.ini, Main, filepath
Else
{
   FilePath := ChooseFolder()
   If ! FilePath
   {
      MsgBox, Unexpected Error
      ExitApp
   }
   IniWrite,% FilePath, netclip.ini, Main, filepath
   MsgBox, Thank You.
}
return


^+9::
fileappend, %ClipBoardAll%, %FilePath%\tmp.clip
SoundMsg( ErrorLevel )
return

^+0::
FileRead, Clipboard, *c %FilePath%\tmp.clip
SoundMsg( ErrorLevel )
return


ChooseFolder()   
{
   If filepath
      return, %filepath%
   MsgBox, 4131, NetClip Setup,
   (
Initialization file not found.`n
This file tells NetClip which shared folder to use for
passing clipboard data.`n
This must be the same folder, on the same computer, for
any installation on the network which is to be allowed to
store and retrieve data.`n
To pass data from one station to another, copy the data
to the clipboard, then press 'Ctrl-('.  The receiving
station may then retrieve the data to it's clipboard by
pressing 'Ctrl-)'.`n
Would you like to select a folder now?
Otherwise, NetClip will close.`n
   )
   IfMsgBox, No
      ExitApp
   IfMsgBox, Cancel
      ExitApp
   
   FileSelectFolder, filepath, *C:\Documents and Settings\All Users\Documents, 1,
   
   If filepath
   {
      StringRight, lastchar, filepath, 1
      If lastchar = \
         StringTrimRight, filepath, filepath, 1
return, %filepath%
   }
   Else
   {
      If ! ChooseFolder()
      {
         MsgBox, 4144, , Exiting..., 3
         ExitApp
      }
      Else
         return, %filepath%
   }   
}   

SoundMsg( status )
{
If status
   SoundPlay, *16
Else
   SoundPlay, *64
return
}

_________________
When it comes to Binary, there are 10 types of people. Those who get it and those who don't. Smile
Back to top
View user's profile Send private message
toralf



Joined: 31 Jan 2005
Posts: 3910
Location: Bremen, Germany

PostPosted: Sat Jan 07, 2006 3:40 pm    Post subject: Reply with quote

I like the idea. I may use it as well.
I modified it to my style, since your code had some unneccessary lines
- Main:
- to check for an ini file is not need, you can read the key and check the key.
- the first if in the ChooseFolder function will never be true, since the filepath variable is not global and will not be set anyway, since the the functions is only called when the filepath doesn't exist.
- I prefer to use IfMsgBox for the options selected
- If the user doesn't select a correct folder the first time I like to exit the script instead of going recursivly deeper.
I hope you don't mind this critic.
Code:
#SingleInstance force
IniRead, FilePath, netclip.ini, Main, filepath
If (FilePath <> "ERROR" or FileExist(FilePath) = "")
    FilePath := ChooseFolder()
If FileExist(FilePath)
    IniWrite, %FilePath%, netclip.ini, Main, filepath
Else
  {
    MsgBox, You didn't selected`nor the Ini-file didn't contain`nan existing folder.`nScript will exit.
    ExitApp
  }
return

ChooseFolder()   
 {
   MsgBox, 4131, NetClip Setup,
     (LTrim
        Initialization file not found.`n
        This file tells NetClip which shared folder to use for
        passing clipboard data.`n
        This must be the same folder, on the same computer, for
        any installation on the network which is to be allowed to
        store and retrieve data.`n
        To pass data from one station to another, copy the data
        to the clipboard, then press 'Ctrl-('.  The receiving
        station may then retrieve the data to it's clipboard by
        pressing 'Ctrl-)'.`n
        Would you like to select a folder now?
        Otherwise, NetClip will close.`n
     )
   IfMsgBox, Yes
       FileSelectFolder, filepath, *C:\Documents and Settings\All Users\Documents, 1,
   StringRight, lastchar, filepath, 1
   If lastchar = \
       StringTrimRight, filepath, filepath, 1
   Return, %filepath%
 }   

^+9::
  fileappend, %ClipBoardAll%, %FilePath%\tmp.clip
  SoundMsg( ErrorLevel )
return

^+0::
  FileRead, Clipboard, *c %FilePath%\tmp.clip
  SoundMsg( ErrorLevel )
return

SoundMsg( status )
  {
    If status
       SoundPlay, *16
    Else
       SoundPlay, *64
    return
  }

_________________
Ciao
toralf
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Terrapin



Joined: 15 Aug 2005
Posts: 107
Location: North Carolina

PostPosted: Sat Jan 07, 2006 4:58 pm    Post subject: Reply with quote

toralf wrote:
I like the idea. I may use it as well.
........
I hope you don't mind this critic.


Thanks Toralf. I meant to thank both you and Chris on thehelp system comments as well, but it got later and later... Embarassed

And I don't mind constructive criticism at all. I have been programming on and off for years, but the only real class I ever took was plain old C many years ago. My coding isn't elegant, and I keep switching styles, in spite of trying to get a set style.

Yes, I did know that there was part of the code which never executes, but I didn't notice that first 'if filepath' mistake. I wondered too, about the recursion and whether using it (potentially endlessly) is poor practice.

I guess the real reason I like to check for the existence of the ini file, is simply that it seems to me to make the intent clearer in the code.

I wasn't quite sure what you meant with the IfMsgBox, because I do use that. Ahh, I see you reversed the logic. Probably makes more sense.

The 'Unexpected Error' is more a failsafe than anything, it should never occur, of course.

I wish I knew more about dealing with the network and sharing and privileges, as to how to do it programitcally, but that is not that important. I need to emphasize to whomever may use it, that both the computer and folder used for the clipboard data file must be the same. I would like to set some options as well, such as automatically saving the clipboard each time it changes, deleting the tmp file once it is of no more use, etc. I know I had a bunch of things I wanted to add.

Thanks again!

Bob
_________________
When it comes to Binary, there are 10 types of people. Those who get it and those who don't. Smile
Back to top
View user's profile Send private message
Guest






PostPosted: Wed Jan 11, 2006 8:21 am    Post subject: Reply with quote

looks real nice..
I wanted to do some thing like that but lack on knowlege and time Razz

however, theres a program That i found usefull :
http://synergy2.sourceforge.net/index.html

its servers the purpose that you a can controll 2 pc's with 1 mouse and kb.
also allows clipbord sharing.
havn't used it yet cuz i only got 1 pc ATM, howeve lots of people liked it.

but perhaps you could write some thing like that as well? which would get Mouse pos and save em in the ini..?
Back to top
quatermass



Joined: 14 Dec 2005
Posts: 216

PostPosted: Mon Sep 25, 2006 3:40 pm    Post subject: Reply with quote

I find this script keeps on not finding the netclip.ini file.

I've placed both the script and the compiled version and the netclip.ini into a directory called c:\extras

But on each time I run the script or the compiled version it keeps asking me to create a new netclip.ini

Perhaps because the script has an error?

Code:

If (FilePath <> "ERROR" or FileExist(FilePath) = "")
 


should be

Code:

If (FilePath = "ERROR" or FileExist(FilePath) = "")



One tip I can make is on making the share hidden.

if you add a $ to the end of a share name its invisible.

ie \\server\clipshare$

So you can manually set this up easily enough.

Remember to set the security permissions of this network share to only the people concerned. ie remove the everyone permission!
_________________
Stuart Halliday


Last edited by quatermass on Tue Sep 26, 2006 9:14 am; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website
Terrapin



Joined: 15 Aug 2005
Posts: 107
Location: North Carolina

PostPosted: Tue Sep 26, 2006 2:50 am    Post subject: Reply with quote

@quatermass:

Good practices for a shared network. I am not that network savvy... I only have my two boxes connected.

@Guest:

Synergy ... I have tried it actually, and find it amazing. But I have a KVM switch also. (Hardware) And, it is far beyond my capabilities.

..and to anyone who cares... I did a similar thing to control winamp without activating the KVM switch, but have no idea where it is now. Just create an empty folder with the name of the key you want to press, and have the client side monitor it, then send %foldername%.

Bob
Back to top
View user's profile Send private message
TheLeO



Joined: 11 Jun 2005
Posts: 264
Location: England ish

PostPosted: Sun Apr 04, 2010 10:03 am    Post subject: Reply with quote

For this, I usually use synergy

http://synergy2.sourceforge.net/

does copy stuff across, except images and files..
_________________
::
I Have Spoken
::
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group