Jump to content

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

question about program flow (ahk and c++)


  • Please log in to reply
5 replies to this topic
place
  • Members
  • 34 posts
  • Last active: Oct 02 2014 04:43 AM
  • Joined: 18 Jan 2011

so in AHK i can white something like this



x = 1

while( x = 1 )
{
  send, Hello{ENTER}
  sleep, 500
}

g::Send, {ENTER}HOTKEY{ENTER}

and while it is sending 'Hello' ever half second i can still press 'g' and my hotkey will do its thing and send 'HOTKEY'

 

where as in c++, while i can create a global hotkey with 

RegisterHotKey(NULL, 1, MOD_ALT |MOD_NOREPEAT, 'b');    //windows api
 which would make a ALT+B hotkey for example. but in order to respond to this i have to create a while(1){...} loop to search for when the hotkey gets pressed and so i can't do anything else because my program is stuck in a loop.

 

also with AHK i can have multiple loops or while things going at the same time for example 

x=1

g::
{
While(x=1)
 {
  send, {ENTER}HOTKEY{ENTER}
 }
}
return

h::
{
While(x=1)
 {
  send, {ENTER}HOTKEY2{ENTER}
 }
}
return


 

 

 

 

 

but in c++ once i am in a loop nothing else can happen until i am out.

i assume there is a way to get the same functionality in c++ as i can with AHK.
can anyone help me with this or help me understand

 

 



VxE
  • Moderators
  • 3622 posts
  • Last active: Dec 24 2015 02:21 AM
  • Joined: 07 Oct 2006
What you want is called multi-threading. AHK only simulates multiple threads (see http://www.autohotke...isc/Threads.htm).

C++ certainly supports multiple threads, but you have to learn how to use them first.

place
  • Members
  • 34 posts
  • Last active: Oct 02 2014 04:43 AM
  • Joined: 18 Jan 2011

ok i kinda thought that's what i'd have to do in c++. is there anyway to 'simulate' them like AHK does?



nnnik
  • Members
  • 1625 posts
  • Last active: Jan 24 2019 02:19 PM
  • Joined: 28 Jul 2012

You dont have to simulate them.

You can use it directly because it is supported directly. 


Visit the new forum ahkscript.org.

http://ahkscript.org


place
  • Members
  • 34 posts
  • Last active: Oct 02 2014 04:43 AM
  • Joined: 18 Jan 2011

thanks for the help guys. explains a lot.



RHCP
  • Members
  • 1228 posts
  • Last active: Apr 08 2017 06:17 PM
  • Joined: 29 May 2006

Also, AHK can use a low level mouse/keyboard hook to monitor the hotkeys. 

This effectively causes windows to send every key press (via a callback function) to the AHK script allowing it to determine what to do. Generally hook hotkeys are better than the windows registerHotkeys.