Jump to content



Photo

problem with hotkeyset & clipget


  • Please log in to reply
11 replies to this topic

#1 aurm

aurm

    Seeker

  • Active Members
  • 18 posts

Posted 07 May 2012 - 08:32 PM

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 :


Plain Text         
#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 ?





#2 Jerrif

Jerrif

    Seeker

  • Active Members
  • 6 posts

Posted 07 May 2012 - 09:01 PM

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


#3 aurm

aurm

    Seeker

  • Active Members
  • 18 posts

Posted 07 May 2012 - 09:39 PM

@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

#4 Jerrif

Jerrif

    Seeker

  • Active Members
  • 6 posts

Posted 07 May 2012 - 09:53 PM

Oh whoops, I must have misread your OP! ;)

I find that odd though, because the script works just fine for me. Even if I go copy -> paste -> copy -> paste, it seems to work as intended.

#5 aurm

aurm

    Seeker

  • Active Members
  • 18 posts

Posted 07 May 2012 - 10:46 PM

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

#6 aurm

aurm

    Seeker

  • Active Members
  • 18 posts

Posted 08 May 2012 - 09:28 PM

http://stackoverflow.com/questions/10505664/autoit-hotkeyset-not-working/10506053#10506053
didn't try it yet , but would help anyone who encountered the same problem

#7 aurm

aurm

    Seeker

  • Active Members
  • 18 posts

Posted 09 May 2012 - 05:26 PM

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, 09 May 2012 - 05:27 PM.


#8 PhoenixXL

PhoenixXL

    Be what you are, believe me its always the BEST...

  • Active Members
  • PipPipPipPipPipPip
  • 1,329 posts

Posted 12 May 2012 - 05:44 AM

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, 12 May 2012 - 05:50 AM.

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.

#9 PhoenixXL

PhoenixXL

    Be what you are, believe me its always the BEST...

  • Active Members
  • PipPipPipPipPipPip
  • 1,329 posts

Posted 12 May 2012 - 06:31 AM

Well Go TO This Forum I have Added the Same Function With the Help Of Variables......................Excluded the Ini Files..................
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.

#10 aurm

aurm

    Seeker

  • Active Members
  • 18 posts

Posted 13 May 2012 - 02:23 PM

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

#11 aurm

aurm

    Seeker

  • Active Members
  • 18 posts

Posted 13 May 2012 - 10:35 PM

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, 13 May 2012 - 11:05 PM.


#12 PhoenixXL

PhoenixXL

    Be what you are, believe me its always the BEST...

  • Active Members
  • PipPipPipPipPipPip
  • 1,329 posts

Posted 14 May 2012 - 05:50 AM

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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users