Jump to content

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

LAN Clipboard sharing


  • Please log in to reply
7 replies to this topic
Terrapin
  • Members
  • 107 posts
  • Last active: Feb 06 2007 03:38 PM
  • Joined: 15 Aug 2005
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


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

toralf
  • Moderators
  • 4035 posts
  • Last active: Aug 20 2014 04:23 PM
  • Joined: 31 Jan 2005
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.
#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
 
I use the latest AHK version (1.1.15+)
Please ask questions in forum on ahkscript.org. Why?
For online reference please use these Docs.

Terrapin
  • Members
  • 107 posts
  • Last active: Feb 06 2007 03:38 PM
  • Joined: 15 Aug 2005

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

  • Guests
  • Last active:
  • Joined: --
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.sour....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..?

quatermass
  • Members
  • 220 posts
  • Last active: Dec 16 2013 09:00 PM
  • Joined: 14 Dec 2005
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?

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

should be

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

Terrapin
  • Members
  • 107 posts
  • Last active: Feb 06 2007 03:38 PM
  • Joined: 15 Aug 2005
@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

TheLeO
  • Members
  • 264 posts
  • Last active: Jan 02 2012 01:51 AM
  • Joined: 11 Jun 2005
For this, I usually use synergy

http://synergy2.sourceforge.net/

does copy stuff across, except images and files..
::
I Have Spoken
::

Scoox
  • Members
  • 194 posts
  • Last active: Jun 09 2017 03:34 AM
  • Joined: 28 Nov 2010

For this, I usually use synergy

http://synergy2.sourceforge.net/

does copy stuff across, except images and files..

 

Current version of Synergy copies images via the clipboard seamlessly. The latest versions can also drag and drop files across, although last time I checked this was somewhat buggy.


RegJump() - Jump to registry path in Regedit

HoverScroll() - HoverScroll() - Scroll controls without focus