Jump to content

[HELP] Simple problem, hard to solve


Recommended Posts

Hello guys, since this is my first post i'd first like to introduce myself (if anyone cares). I've only recently started using AutoIt, and although i have a long experience with console programming in C++, i have a hard time with a very simple program.

I want my program to wait for a hotkey (implemented and working), however my main function isn't working correctly.

I will show you my code so you can understand my problem easier.

NOTE: Please don't laugh or yell at me for the code, i've been improvising a lot, this is my first project in AutoIt, and yes, i've used the Help file in AutoIt and Search button in forum.

WinWaitActive("Editor 2010 10.2.0d93362")
HotKeySet("{F2}", "Start")
HotKeySet("{ESC}", "Terminate")
Dim $int=0;
While 1
    Sleep(100)
WEnd
Func Start()
  Dim $i
  For $i = 1 to 17 Step +1
    $int=0;
    Send("{RIGHT}")
    Send("{RIGHT}")
    Send("+{LEFT}")
    Sleep(1000)
    Send("^c")
    Send("{BS}")
    $int = ClipGet()
    $int = $int + 2
    ClipPut($int)
    Send("^v")
    Send("{TAB}")
  Next
EndFunc

Func Terminate()
    Exit 0
EndFunc

What i want my main function (Start) to do after a hotkey has been pressed, is to copy a two-digit number, a variable gets the number's value from clipboard, it increases the value for 2, puts the changed variable to clipboard, pastes it, and presses tab for the next number.

Now, the problem is: When i made the function Start only (it wasn't a function then, it was in main), this very same code worked perfectly.

However, when i implemented Hotkeys and While loop in main (so the program will wait for hotkey indefinately) and put the main code into a function Start, the hotkey and while part work flawlessly, however, the function start pastes the same copied number, it doesn't increase by 2.

I don't know what the problem could be, i haven't changed the code in (func Start()) and it worked without problems before i implemented hotkey.

Anyone can help?

Link to comment
Share on other sites

You have put a Send("^c") in there which will clear the Clipboard content?

No.

Send("{RIGHT}")

Send("{RIGHT}")

Send("+{LEFT}")

With these lines before the Send("^c"), i highlight the number (Shift + left arrow) and then i copy it to clipboard.

The problem is that it copies well, but doesn't change the value of variable, it pastes the same copied number.

Link to comment
Share on other sites

  • Developers

No.

Send("{RIGHT}")

Send("{RIGHT}")

Send("+{LEFT}")

With these lines before the Send("^c"), i highlight the number (Shift + left arrow) and then i copy it to clipboard.

The problem is that it copies well, but doesn't change the value of variable, it pastes the same copied number.

That will only select the last character which is the TAB?

I am testing with this script:

Run("notepad.exe")
HotKeySet("{F2}", "Start")
HotKeySet("{ESC}", "Terminate")
Dim $int=0;
While 1
    Sleep(100)
WEnd
Func Start()
  Dim $i
  For $i = 1 to 17 Step +1
    $int=0;
    Send("{RIGHT}")
    Send("{RIGHT}")
    Send("+{LEFT}")
    Sleep(1000)
    Send("^c")
    Send("{BS}")
    $int = ClipGet()
    ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $int = ' & $int & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console
    $int = $int + 2
    ClipPut($int)
    WinActivate("[CLASS:Notepad]", "")
    Send("^v")
    Send("{TAB}")
  Next
EndFunc

Func Terminate()
    Exit 0
EndFunc
Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

That will only select the last character which is the TAB?

No.

I'm not using Notepad, i want to fast edit data in an Editor for a game.

When i press Tab in that Editor it moves from one to other number (imagine the same thing when registering at a forum, after inputing password you press tab and automatically it moves to the confirm password line), the highlight/copy/paste thing is working excellent, please stop searching for errors there.

The problem is that it doesn't add 2 to the value, it copy/pastes the same number, as if it skips that line completely.

Maybe i'm handling the variable incorrect, i don't know.....

Link to comment
Share on other sites

  • Developers

No.

I'm not using Notepad, i want to fast edit data in an Editor for a game.

When i press Tab in that Editor it moves from one to other number (imagine the same thing when registering at a forum, after inputing password you press tab and automatically it moves to the confirm password line), the highlight/copy/paste thing is working excellent, please stop searching for errors there.

The problem is that it doesn't add 2 to the value, it copy/pastes the same number, as if it skips that line completely.

Maybe i'm handling the variable incorrect, i don't know.....

Well.... its simple: You either post something we can test with to help you or you are out on you own.

Add debug lines in your code and start debugging why you have problems as I did in my posted example.

Jos

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Well, i undertand you, i didn't ask to be spoonfed, just wanted a more experienced programmer to check whether i have obvious flaws in the code or if i'm handling the variable incorrectly since this is just my first project.

Thanks anyways, and i'll try debugging.

Link to comment
Share on other sites

Well, i undertand you, i didn't ask to be spoonfed, just wanted a more experienced programmer to check whether i have obvious flaws in the code or if i'm handling the variable incorrectly since this is just my first project.

Thanks anyways, and i'll try debugging.

hello IgorChete,

I started off with:

AutoItSetOption("MustDeclareVars", 1)

Run("notepad.exe")

WinWaitActive("[CLASS:Notepad]", "")

Sleep(2000)

instead of:

WinWaitActive("Editor 2010 10.2.0d93362")

Then I tried this:

HotKeySet("{F2}", "Start")

HotKeySet("{ESC}", "Terminate")

Dim $int = 0;

While 1

Sleep(100)

WEnd

Func Start()

Dim $i

For $i = 1 To 17 Step +1

$int = 0;

Send("{RIGHT}")

Send("{RIGHT}")

Send("{SHIFTDOWN}{LEFT}{LEFT}{SHIFTUP}") ; Changed

Sleep(1000)

Send("^c")

Send("{END}") ; Changed

$int = ClipGet()

$int = $int + 2

ClipPut($int)

Send("{TAB}") ; Changed

Send("^v")

Next

EndFunc ;==>Start

Func Terminate()

Exit 0

EndFunc ;==>Terminate

Link to comment
Share on other sites

Hello guys, since this is my first post i'd first like to introduce myself (if anyone cares). I've only recently started using AutoIt, and although i have a long experience with console programming in C++, i have a hard time with a very simple program.

I want my program to wait for a hotkey (implemented and working), however my main function isn't working correctly.

I will show you my code so you can understand my problem easier.

NOTE: Please don't laugh or yell at me for the code, i've been improvising a lot, this is my first project in AutoIt, and yes, i've used the Help file in AutoIt and Search button in forum.

WinWaitActive("Editor 2010 10.2.0d93362")
HotKeySet("{F2}", "Start")
HotKeySet("{ESC}", "Terminate")
Dim $int=0;
While 1
    Sleep(100)
WEnd
Func Start()
  Dim $i
  For $i = 1 to 17 Step +1
    $int=0;
    Send("{RIGHT}")
    Send("{RIGHT}")
    Send("+{LEFT}")
    Sleep(1000)
    Send("^c")
    Send("{BS}")
    $int = ClipGet()
    $int = $int + 2
    ClipPut($int)
    Send("^v")
    Send("{TAB}")
  Next
EndFunc

Func Terminate()
    Exit 0
EndFunc

What i want my main function (Start) to do after a hotkey has been pressed, is to copy a two-digit number, a variable gets the number's value from clipboard, it increases the value for 2, puts the changed variable to clipboard, pastes it, and presses tab for the next number.

Now, the problem is: When i made the function Start only (it wasn't a function then, it was in main), this very same code worked perfectly.

However, when i implemented Hotkeys and While loop in main (so the program will wait for hotkey indefinately) and put the main code into a function Start, the hotkey and while part work flawlessly, however, the function start pastes the same copied number, it doesn't increase by 2.

I don't know what the problem could be, i haven't changed the code in (func Start()) and it worked without problems before i implemented hotkey.

Anyone can help?

Hello IgorChete,

I started off with:

AutoItSetOption("MustDeclareVars", 1)

Run("notepad.exe")

WinWaitActive("[CLASS:Notepad]", "")

Sleep(2000)

instead of:

WinWaitActive("Editor 2010 10.2.0d93362")

Then I tried this, worked for me.

HotKeySet("{F2}", "Start")

HotKeySet("{ESC}", "Terminate")

Dim $int = 0;

While 1

Sleep(100)

WEnd

Func Start()

Dim $i

For $i = 1 To 17 Step +1

$int = 0;

Send("{RIGHT}")

Send("{RIGHT}")

Send("{SHIFTDOWN}{LEFT}{LEFT}{SHIFTUP}") ; Changed

Sleep(1000)

Send("^c")

Send("{END}") ; Changed

$int = ClipGet()

$int = $int + 2

ClipPut($int)

Send("{TAB}") ; Changed

Send("^v")

Next

EndFunc ;==>Start

Func Terminate()

Exit 0

EndFunc ;==>Terminate

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