AutoHotkey Community

It is currently May 27th, 2012, 7:44 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: LAN Clipboard sharing
PostPosted: January 7th, 2006, 12:21 pm 
Offline

Joined: August 15th, 2005, 7:15 am
Posts: 107
Location: North Carolina
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. :)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 7th, 2006, 4:40 pm 
Offline

Joined: January 31st, 2005, 9:50 am
Posts: 3910
Location: Bremen, Germany
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
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 7th, 2006, 5:58 pm 
Offline

Joined: August 15th, 2005, 7:15 am
Posts: 107
Location: North Carolina
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... :oops:

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. :)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 11th, 2006, 9:21 am 
looks real nice..
I wanted to do some thing like that but lack on knowlege and time :P

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..?


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: September 25th, 2006, 4:40 pm 
Offline

Joined: December 14th, 2005, 3:08 pm
Posts: 219
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 September 26th, 2006, 10:14 am, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 26th, 2006, 3:50 am 
Offline

Joined: August 15th, 2005, 7:15 am
Posts: 107
Location: North Carolina
@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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 4th, 2010, 11:03 am 
Offline

Joined: June 11th, 2005, 9:34 am
Posts: 264
Location: England ish
For this, I usually use synergy

http://synergy2.sourceforge.net/

does copy stuff across, except images and files..

_________________
::
I Have Spoken
::


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: nothing and 11 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