AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Basic Beginner's Questions. [solved 3/5] [NeedHelp]
Goto page 1, 2  Next
 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
antihack



Joined: 03 Nov 2009
Posts: 10

PostPosted: Tue Nov 03, 2009 6:58 pm    Post subject: Basic Beginner's Questions. [solved 3/5] [NeedHelp] Reply with quote

I've tough that it can be a nice way for me to learn and for others to find answers on some basic questions.

If you are new, while reading this post, you should learn a bit about scripting from reading the questions and analyzing code.

Since now I will make it in the way:

  • Question/Problem not solved.
  • Question/Problem party fixed.
  • Question/Problem with solution included in codes.



Table of Contents

  • Question 1: How can I make my script starting from click on button START and stop after button STOP?
  • Question 2: How can I have multiple buttons START/STOP with same titles but with different functions in same GUI?
  • Question 3: How can I run two different functions from one GUI, to send different informations to same application at one time.
  • Question 4: How can I move my application/script to tray while pressing on close 'X' button from GUI?
  • Question 5: How to detect, if animated cursor changed in application?


Thanks to: Leef_me, wooly_sammoth, Z_Gecko


Here are examples of code that will be edited each time when we solve a problem.

1st Code:
Code:

#SingleInstance, off
#SingleInstance, off
Gui, Add, GroupBox, x6 y7 w460 h80 , Hotkeys
Gui, Add, Text, x16 y27 w70 h20 , Select Hotkey:
Gui, Add, DropDownList, x96 y27 w70 h180 vH, F1|F2|A||B|C|D|E|F
; 'vH' Assigns selected value to variable %H%.
Gui, Add, Text, x176 y27 w90 h20 , Select Timing [ms]:
Gui, Add, ComboBox, x276 y27 w60 h180 vT, 1000||2000|3000|4000|5000
; 'vT' Assigns selected value to variable %T%.
Gui, Add, Button, gStart1 x346 y27 w50 h20, Start
Gui, Add, Button, gStop1 x406 y27 w50 h20, Stop
; Now we added so called g_label to the buttons.
; In this case its "gStart1/gStart2" and similar.
; It will let us to have many buttons with same titles but assigned to different functions.
; Note, if you assigned some g-labels, then bottom in the code you must definie the function.
; Example: 'gStart1' have 'Start1:'. If there wont be function assigned, program will close.
; To find out what buttons do, read below, the functions assigned to them.
Gui, Add, Text, x16 y57 w70 h20 , Select Hotkey:
Gui, Add, DropDownList, x96 y57 w70 h180 v2H, F1|F2|A|B||C|D|E|F|
Gui, Add, Text, x176 y57 w90 h20 , Select Timing [ms]:
Gui, Add, ComboBox, x276 y57 w60 h180 v2T, 1000|2000||3000|4000|5000
Gui, Add, Button, gStart2 x346 y57 w50 h20, Start
Gui, Add, Button, gStop2 x406 y57 w50 h20, Stop
Gui, Show, x243 y144 h99 w477, Sample
;Following code will let our application hide to tray by double clicking the tray icon or when clicking the X 'close' button:
Menu, Tray, NoStandard
Menu, Tray, add, Hide|Show, Hide_Show_Win
Menu, Tray, add, Exit, Exit_Win
Menu, Tray, Default, Hide|Show
Main_Window := WinExist("A")
Return

;############# Minimize to Tray #############

Hide_Show_Win:
IfWinExist, ahk_id %Main_Window%
Gui, Hide
else
Gui, Show
Return

; While selecting EXIT from Tray Icon Menu, application will be closed.
Exit_Win:
ExitApp
Return

; While pressing X button, application will be minimized to Tray Icon:
GuiClose:
Gui, Submit
Menu, Tray, Icon
return

;############# Buttons & Functions #############

;Here is the part of gStart1:

Start1:
Gui, Submit, Nohide
; To save the values from ComboBox and DropDownList in to memory.
SetTitleMatchMode 3
; To specify that only exact name of application will be count.
WinGet, note, ID, Bez tytułu - Notatnik
; To assign Notepad's ID with our variable 'note'.
; PS: I'm Polish, so in my language: Bez tytułu - Notatnik = Untitled - Notepad
IfWinNotActive, ahk_id %note%
WinActivate, ahk_id %note%
; Activating application assigned in previous line.
loop
{
ControlSend,, {%H%}, ahk_id %note%
; Will send a value:key specified in form DropDownList (H) to Bez Tytułu - Notatnik %note%.
Sleep, %T%
; Will sleep (delay) previous function with amount of millisecions specified in ComboBox as %T%.
if (T < 0 )
; Gives an option to break the key sending function (connected to ButtonStop).
Break
}
Return


;Here is the part of gStop1:

Stop1:
T = -1
; When used, changes the value of %T% to negative (less than zero) what cause end of the loop.
Return


;Here is the part of gStart2:

Start2:
Gui, Submit, Nohide
SetTitleMatchMode 3
WinGet, note2, ID, Bez tytułu - Notatnik
IfWinNotActive, ahk_id %note2%
WinActivate, ahk_id %note2%
loop
{
ControlSend,, {%2H%}, ahk_id %note2%
Sleep, %2T%
if (2T < 0 )
Break
}
Return


;Here is the part of gStop2:

Stop2:
2T = -1
Return


2nd Code:
Code:

#SingleInstance, off
Gui, Font, s8, Verdana
Gui, Add, GroupBox, x6 y7 w460 h80 , Mouse
Gui, Add, Text, x16 y27 w120 h20 , Select Timing [ms]:
Gui, Add, ComboBox, x136 y27 w100 h180 vT, 1000|2000|3000|4000|5000||
Gui, Add, Button, x246 y27 w100 h20 , Start
Gui, Add, Button, x356 y27 w100 h20 , Stop
Gui, Add, Button, x356 y57 w100 h20 , Exit
Gui, Show, x194 y258 h102 w477, Sample
Return

ButtonStart:
Gui, Submit, Nohide
SetTitleMatchMode, 3
WinGet, note, ID, Bez tytułu - Notatnik
IfWinNotActive, ahk_id %note%
WinActivate, ahk_id %note%
loop
{
; Are 2 types of cursors, both known for AutoHotkey as 'unknown'.
; Lets say there is 1, standard arrow, while moving on specified target changes to 2.
; I have no idea how works the DLLCall or if Autohotkey can detect if
; from cursor changed from unknown1 to unknown2.
MouseMove, 512, 384
if (Cursor changed) then
Click, 512, 384
sleep %T%
MouseMove, 530, 400
if (Cursor changed) then
Click, 530, 400
if (T < 0)
Break
}

ButtonStop:
T = -1
Return

ButtonExit:
GuiClose:
ExitApp


Currently working on:
- Question 2: Problem with functions assigned to different buttons with same labels.
- Question 3: Can't find easy way to minimize to tray (remove from task bar)
- Question 4: Cannot find a solution to check if cursor changed after mouse move. Note, cursors there are not standard ones - are image based.


[Moved from General Chat forum. ~jaco0646]
_________________
Follow your dreams!


Last edited by antihack on Wed Nov 11, 2009 12:57 pm; edited 29 times in total
Back to top
View user's profile Send private message
Leef_me



Joined: 08 Apr 2009
Posts: 1158
Location: San Diego, California

PostPosted: Wed Nov 04, 2009 12:30 am    Post subject: Reply with quote

Here is a simple start/stop routine with loop. The loop is controlled by a variable that means run or not.
I chose to use your timing variable since it is illogical to have a negative delay.

I don't think it is very complex and you can adapt its ideas to your own script.
I used F1 and F2 hotkeys for testing, but you can use "ButtonStart:" just as easily.
Code:
f1::
InputBox, Timing,,Number of milliseconds between each click:

loop
{
send, 1

if (Timing < 0) break
   break
Sleep, %Timing%
}
Return


f2::
Timing = -1
return

esc::      ; in case of emergency hit escape
exitapp

/* working area for send to send keypresses.

11111111111111111111111111111111111111111111111111111111111






*/
Back to top
View user's profile Send private message
antihack



Joined: 03 Nov 2009
Posts: 10

PostPosted: Wed Nov 04, 2009 4:54 pm    Post subject: Reply with quote

Hello Leef_me

Thank you for your reply.
Sadly it was not working.
For example this way:

Code:

ButtonStart:
SetTitleMatchMode 3
WinGet, SomeApp, ID, SomeApp
WinActivate ahk_id %SomeApp%
T = 5000
loop
{
SetKeyDelay, T
ControlSend,, {F5}, ahk_id %SomeApp%
if (T < 0 ) Break
Break
}
Return

ButtonStop:
T = -1
Return


When I pressed STOP on Gui, nothing happened.
I'm trying to understnad, the idea with negative something was nice at first moment but sadly it did not worked or maybe I used it wrongly.
I'm just a beginner..
_________________
Follow your dreams!
Back to top
View user's profile Send private message
Leef_me



Joined: 08 Apr 2009
Posts: 1158
Location: San Diego, California

PostPosted: Wed Nov 04, 2009 6:44 pm    Post subject: Reply with quote

Please review my modifications to your script, noting the comments.
Then try it this way
Code:

ButtonStart:
SetTitleMatchMode 3
WinGet, SomeApp, ID, SomeApp
WinActivate ahk_id %SomeApp%
T = 5000
loop
{
;--SetKeyDelay, T; <------this is not the proper way to add delay for this loop

ControlSend,, {F5}, ahk_id %SomeApp%
 if (T < 0 ) ; break ;<---------this break does absolutely nothing
Break
Sleep, %T% ; <--------- this is the proper way to delay the loop
}
Return

ButtonStop:
T = -1
Return
Back to top
View user's profile Send private message
antihack



Joined: 03 Nov 2009
Posts: 10

PostPosted: Sat Nov 07, 2009 9:28 am    Post subject: Reply with quote

Hello again!

Thanks for your help Leef_me. I finally understood that SetKeyDelay was not an option to make it working as I wanted. Replaced by Sleep works well.

I've changed a bit the first post, to make it more flexible and find out solutions faster.

If anyone could help, please check 1st post.
_________________
Follow your dreams!
Back to top
View user's profile Send private message
wooly_sammoth



Joined: 12 May 2009
Posts: 178
Location: Gloucester UK

PostPosted: Sat Nov 07, 2009 12:33 pm    Post subject: Reply with quote

Morning AntiHack,

Thank you for working so hard on your questions. It makes it much easier to understand what you are looking for.

With regards your 2nd Question: How can I have multiple buttons START/STOP with different functions in same GUI and to start/stop them in same time without breaking each other?

The way to have multiple buttons with the same name is to specify a different gLabel for each button so that they can operate different subroutines.

for example:
Code:
Gui, Add, Button, gBut1, Start
Gui, Add, Button, gBut2, Start
Gui, Show
Return

But1:
MsgBox, 1
Return

But2:
MsgBox, 2
Return


The code above will create a small GUI with two buttons both called Start. Pressing the first will generate a MsgBox which says 1. Pressing the second will result in a MsgBox which says 2.

Hope that helps
Back to top
View user's profile Send private message
Leef_me



Joined: 08 Apr 2009
Posts: 1158
Location: San Diego, California

PostPosted: Sat Nov 07, 2009 6:14 pm    Post subject: Reply with quote

Quote:
Question 3: Can't find easy way to minimize to tray (remove from task bar)

GuiSize: Launched when the window is resized, minimized, maximized, or restored.
http://www.autohotkey.com/docs/commands/Gui.htm#GuiSize

thread:: Simple minimize to tray
http://www.autohotkey.com/forum/viewtopic.php?t=35472&highlight=minimize+tray

for other application windows: Minimize Window to Tray Menu
http://www.autohotkey.com/docs/scripts/MinimizeToTrayMenu.htm

You will have to review and decide what you want to use.

I agree with wooly_sammoth statement about organization & questions.

btw, the above with 'docs' are the same as in the helpfile.
They are the first two results when you use "minimize" at the >search< tab in the helpfile

The other link is to the section of the forum called Scripts & Functions.
It was not so easy to find using forum search Crying or Very sad

Idea I relied on google to help, note the parameters in the google search box when you follow this link
http://www.google.com/search?q=site%3Aautohotkey.com+%2B%22minimize+to+tray%22&hl=en&sa=2
Back to top
View user's profile Send private message
antihack



Joined: 03 Nov 2009
Posts: 10

PostPosted: Sun Nov 08, 2009 1:44 pm    Post subject: Reply with quote

Hello wooly_sammoth!

Thank you for the help.
Those g_labels are working fine, but I found another difficulty.
When I run function 1 to send letter A to the application and then while starting function 2 to send B, the first function get stopped. To continue I have to stop 2nd and run again the 1st. How I can start both function and make them working at same time (sending A and B to application in same time).
_________________
Follow your dreams!
Back to top
View user's profile Send private message
Z_Gecko
Guest





PostPosted: Sun Nov 08, 2009 2:01 pm    Post subject: Reply with quote

i donīt want to be rude, but
this topic is not "Useful for beginners." It is just a bunch of questions you currently have.
They are neither well presented nor is there any good documentation on how you solved your problems.
So please change the topics title, to not draw away the attention from the topics that are really usefull for beginners.
Back to top
antihack



Joined: 03 Nov 2009
Posts: 10

PostPosted: Sun Nov 08, 2009 2:13 pm    Post subject: Reply with quote

Z_Gecko wrote:
i donīt want to be rude, but
this topic is not "Useful for beginners." It is just a bunch of questions you currently have.
They are neither well presented nor is there any good documentation on how you solved your problems.
So please change the topics title, to not draw away the attention from the topics that are really usefull for beginners.


I will change the topic title, as you want.
I disagree. Sure those are my questions, but at most of them, there is no documentation in the Autohotkey manual. I basically search everything in that manual, then I go outside and ask. My questions are beginner's questions at all. By reading the program code, you can find out from comments what and where have been used. It's not a tutorial for beginners but a topic with few questions and answers provided.

PS: If you see it's not well presented, show how it should be then.
_________________
Follow your dreams!
Back to top
View user's profile Send private message
antihack



Joined: 03 Nov 2009
Posts: 10

PostPosted: Sun Nov 08, 2009 2:22 pm    Post subject: Reply with quote

Leef_me wrote:
Quote:
Question 3: Can't find easy way to minimize to tray (remove from task bar)


Hi there!

I've found a script that minimize the application to tray while it's run.
Then double click on tray icon shows or hides the application.
It's partly done. What I miss is pressing minimize button (top right corner) doesn't move application to tray.
_________________
Follow your dreams!
Back to top
View user's profile Send private message
Z_Gecko
Guest





PostPosted: Sun Nov 08, 2009 2:24 pm    Post subject: Reply with quote

Quote:
It's not a tutorial for beginners
But thatīs what i thought when i read your previous title. So thank you very much for changing it.
If you have god ideas how the ahk help-file could be improved, iīm shure everyone would be happy, if you post the specific ideas of improvement (I suspect Wish List would be the right place). Happy coding.
Back to top
Z_Gecko
Guest





PostPosted: Sun Nov 08, 2009 3:03 pm    Post subject: Reply with quote

about Q4: the MinToTray-Script you found is made for NON-AHK-windows.
for AHK-GUIs you only need to combine the matching GUI and Menu comands, like:
Code:
#NoTrayIcon
Menu, Tray, NoStandard
Menu, Tray, add, Show, ShowWin
Menu, Tray, Default, Show
Gui, Show, w300 h300
return

GuiClose:
Gui, Submit
Menu, Tray, Icon
return

ShowWin:
Gui, Show
Menu, Tray, NoIcon
return
Back to top
Leef_me



Joined: 08 Apr 2009
Posts: 1158
Location: San Diego, California

PostPosted: Sun Nov 08, 2009 3:21 pm    Post subject: Reply with quote

Quote:
I've found a script that minimize the application to tray while it's run. . . . . It's partly done. What I miss is pressing minimize button (top right corner) doesn't move application to tray.


You don't specify where you found the minimize to tray code...
Please review the first two links again, I believe in the 2nd thread you'll find DHMH's code does both the 'detect request for minimize' and the 'change to system tray icon' functions. In the first link is the info about a [b]built-in subroutine name "GuiSize: ". If you include that label in you script it will be called when various buttons areclic by user. Here are the two links again.

GuiSize: Launched when the window is resized, minimized, maximized, or restored.
http://www.autohotkey.com/docs/commands/Gui.htm#GuiSize

thread:: Simple minimize to tray
http://www.autohotkey.com/forum/viewtopic.php?t=35472&highlight=minimize+tray
Back to top
View user's profile Send private message
antihack



Joined: 03 Nov 2009
Posts: 10

PostPosted: Tue Nov 10, 2009 7:54 pm    Post subject: Reply with quote

Greetings!

I've updated a bit the code. Used partly the scripts for minimize, but assigned it to the X icon from window commands. I think it's more flexible, cause sometimes people maybe would like to have the application on task bar so pressing "_" (minimize) will put application there. Pressing X (close) will move to tray. Selecting "Exit" from tray icon menu or pressing "Exit" button (not added to gui atm) will close application.


Guys. I would like to focus on the question 3 and 5.

Is there a way to detect, if cursor changed after mouse moved in specified area?

For example, if I move cursor to hyper link it changes in to hand shape.
Then when I move it out of hyper link, it changes to normal arrow.

I've found only a function A_Cursor

The type of mouse cursor currently being displayed. It will be one of the following words: AppStarting, Arrow, Cross, Help, IBeam, Icon, No, Size, SizeAll, SizeNESW, SizeNS, SizeNWSE, SizeWE, UpArrow, Wait, Unknown.

The hand-shaped cursors (pointing and grabbing) are classified as Unknown.


The last line. If I have an application that has different cursors than the standard win ones, the function A_Cursor gives a result as unknown.
Is there a way to identify in any way even those unknown cursors?

Because I would like to assign different functions to the recognized different mouse cursors.
_________________
Follow your dreams!
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group