Jump to content

problem with hotkeyset & clipget


Recommended Posts

Hi everyone , I'm trying to make some kind of simple clipboard controller , where the user could have several items copied to the clipboard when using a hotkey (Ctrl+Shift+Q) , instead of only one item when using Ctrl+C , and would be able to paste them all at once (Ctrl+Shift+W) , or paste any of the first 10 items directly (Ctrl+Shift+1...9), another option is to clear the clipboard (Ctrl+Shift+'-').

The problem is that it works fine until I paste once and try to copy again : nothing is added to the clipboard.

I'm trying to figure it out , but couldn't find a reason for this..

here is the code :

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <array.au3>


Global $clipBoard[50]=[""]
Global $counter = 0

HotKeySet("^+q","addToClipboard")
HotKeySet("^+-","emptyAll")
HotKeySet("^+w","getAll")
HotKeySet("^+1","get1")
HotKeySet("^+2","get2")
HotKeySet("^+3","get3")
HotKeySet("^+4","get4")
HotKeySet("^+5","get5")
HotKeySet("^+6","get6")
HotKeySet("^+7","get7")
HotKeySet("^+8","get8")
HotKeySet("^+9","get9")

$hGUI = GuiCreate("Clipboard Controller", 100, 100,Default,Default,$WS_SIZEBOX)
GUISetState()

Func addToClipboard()
Send ("^c")
    $copied = ClipGet()
$clipBoard[Mod($counter,50)] = $copied
$counter +=1
EndFunc

Func getByIndex($i)
$statement = $clipBoard[$i]
ClipPut($statement)
Send("^v")
EndFunc

Func getAll()
$statement =""
For $i In $clipBoard
If $i <> "" Then
$statement &= $i & @CRLF
EndIf
Next
ClipPut($statement)
Send("^v")
EndFunc

Func emptyAll()
For $i=0 To 49
$clipBoard[$i]=""
Next
ClipPut("")
EndFunc


Func get1()
getByIndex(0)
EndFunc

Func get2()
getByIndex(1)
EndFunc

Func get3()
getByIndex(2)
EndFunc

Func get4()
getByIndex(3)
EndFunc

Func get5()
getByIndex(4)
EndFunc

Func get6()
getByIndex(5)
EndFunc

Func get7()
getByIndex(6)
EndFunc

Func get8()
getByIndex(7)
EndFunc

Func get9()
getByIndex(8)
EndFunc

While 1
Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
EndSwitch
WEnd

any ideas/help ?

Link to comment
Share on other sites

The problem is that it works fine until I paste once and try to copy again : nothing is added to the clipboard.

The selection is still added to the clipboard, it's just placed after the previous last entry.

I think you just need to add $counter = 0 to the emptyAll() function

Func emptyAll()
For $i=0 To 49
$clipBoard[$i]=""
Next
ClipPut("")
$counter =0
EndFunc
Link to comment
Share on other sites

@jerrif , thanks for the reply , but I think that the problem isn't in emptyAll() , when I tried to display a messagebox with the value of copied statement the result was an empty window which is weird to me, and the problem described didn't include an emptyAll action , I just copy and paste without getting to the emptyAll() part

Link to comment
Share on other sites

np ;)

could it be related to the windows platform ? since I'm using 64-bit version ? but I still don't see any dependency on the windows platform that might cause this problem

Link to comment
Share on other sites

here is the new addToClipboard() , which didn't work too ;)

but I believe this is the more correct than the previous one , since it handles the duration of pressing the keys

Func addToClipboard()

HotKeySet("^+q") ; This unregisters the key from this function , in case the keys were pressed for a long time
    While _IsPressed("11") Or _IsPressed("10")  Or _IsPressed("51"); Wait until  the ctrl and the Shift and the Q keys are unpressed
        Sleep(50)
    WEnd
Send ("^c")
    $copied = ClipGet()
$clipBoard[Mod($counter,50)] = $copied
$counter +=1
HotKeySet("^+q","addToClipboard")
EndFunc

hopefully someone would help find the bug

Edited by aurm
Link to comment
Share on other sites

Im not getting it Why have You made an Array of 50 .......................??

n

Maybe

The Statement

$clipBoard[Mod($counter,50)] = $copied

is Formatted Incorrectly

it should be

$clipBoard[Mod(50,$counter)] = $copied

(I guess so....)

I wasnt Able to Try it out coz im having WIN7 n Autoit is Crashing.........

for More Help add a FOR loop on top of your code like this

For $i=0 To 50
ConsoleWrite('$i:'&$i&@TAB&'Value:'&Mod(50,$i)&@CR)
Next

And Check It out what Exactly Happens....

Edited by PhoenixXL

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Link to comment
Share on other sites

Well Go TO I have Added the Same Function With the Help Of Variables......................Excluded the Ini Files..................

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Link to comment
Share on other sites

PhoenixXL

thnx for the reply , about the ' Mod 50 ' thing : first I intended to make a program that holds large amounts of data to be pasted instead of only one text item , so I made the array of size 50 to hold amounts of data as big as possible , and once the user has exceeded the 50-items conditions the program shall overwrite the data from the beginning , for example when counter reachs 51 , then 51 % 50 = 1 , so it would overwrite the first element of the array

About the error , after several copies and pastes , I found that the program didn't copy some text , instead it saved empty strings ,and for debugging I used MsgBox to show me the value of array[index] after each copy operations and it resulted in- many times - empty strings

I read your code you referred to above , but for the honesty I didn't understand some parts of it ; as I am very new to Autoit , and I hope I would find the bug in my code since its driving me crazy

Link to comment
Share on other sites

Now I believe the problem is in clipput() and clipget() or how I use them , is there any problem that sets the text in clipboard to an empty string ?

if I use Send() and send the statement as an input it works fine instead of clipput() then send("^v")

any idea ?

UPDATE : hope this is the end of the problem , I found another way to set/get data from clipboard , functions : _ClipBoard_SetData () & _ClipBoard_GetData() , after trying them it worked well ;)

will come later isA to assure whether its finally correct or not

Edited by aurm
Link to comment
Share on other sites

Sounds good That U after All Figured How to DO..................

if I use Send() and send the statement as an input it works fine instead of clipput() then send("^v")

any idea ?

Send function sends individual Alphabets Numbers or Symbols and then the Next...............

So for Longer Strings it will take Time to Send .....................

Meanwhile If U change the Active Window the Rest part of the String would not be send to the required window................

So my recommendation is to Use ClipPut and Use Send('^v')

Fact : I have Already Experienced the Send Problem............

Regards

Phoenix XL

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...