Help with hotkeys while macro is running.
Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: Help with hotkeys while macro is running.
PostPosted: Sat Nov 01, 2008 9:31 pm 
Offline
Newbie

Joined: Sat Nov 01, 2008 8:43 pm
Posts: 8
Hello Support Team,

I have a screenshot tool that I have coded in teraterm. I am using a macro to loop to determine the presence of a USB stick. After looking to see if a USB stick is there, I want to do a check for a keyboard press to take a screenshot. Where I am stuck is that I do not seem to be able to interrupt the loop to take a screenshot by pressing a key. At first, I wanted to use separate macros to take and download screenshots, but I have found that I can only run one macro at a time (and I can only have one connection for what I am doing). I thought that I could use a user defined key to cause the macro to branch to the take screenshot code, take a screenshot, and return to the loop, but I do not see that kind of functionality. I don't want to have to enter a string or start another macro when I use a user defined key. Teraterm comes with an application to display the keycode when a key is pressed. Is a teraterm macro able to look for a keypress/keycode like that and send the response to the system variable 'result'? I am a software tester, and I need to take a screenshot fast when I see a bug. I am hoping to have my macros be more interactive. If there is a better way, I am open to suggestions.

Best regards,
Ron


Top
 Profile E-mail  
 
 Post subject: Re: Help with hotkeys while macro is running.
PostPosted: Mon Nov 03, 2008 10:25 am 
Offline
Guru

Joined: Wed Jan 25, 2006 10:28 pm
Posts: 630
Location: Denver, Colorado, USA
I don't see why you could not run more than one macro at a time. A macro does not need to make a connection to run.


Top
 Profile  
 
 Post subject: Re: Help with hotkeys while macro is running.
PostPosted: Tue Nov 04, 2008 12:22 am 
Offline
Newbie

Joined: Sat Nov 01, 2008 8:43 pm
Posts: 8
I am not able to run two macros at the same time. I have two macros that run from a user defined key. Each macro will run by itself, but I can not run two macros at the same time. Running two different macros was the first thing that I tried. I am using a COM port connection. I thought that Boris had said that two macros can not be run simultaneously on the same connection in a previous post to another user. I really would appreciate a solution for my problem.

Thanks,
Ron


Top
 Profile E-mail  
 
 Post subject: Re: Help with hotkeys while macro is running.
PostPosted: Tue Nov 04, 2008 12:15 pm 
Offline
Guru

Joined: Wed Jan 25, 2006 10:28 pm
Posts: 630
Location: Denver, Colorado, USA
True, you can not run two TeraTERM sessions on the same com port (at least not without using com0com), but you don't need to be connected to anything to do a screen shot. How are you attempting to do the screen shot? Post code, that would help.


Top
 Profile  
 
 Post subject: Re: Help with hotkeys while macro is running.
PostPosted: Thu Nov 06, 2008 10:41 pm 
Offline
Newbie

Joined: Sat Nov 01, 2008 8:43 pm
Posts: 8
My situation is that I have to connect to an outside operating system (QNX) using the COM port. The screenshot is taken by QNX. I am using teraterm to pass the command to take the screenshot as a string. When QNX receives the string, the screenshot is taken. If teraterm is not communicating with QNX, there is no screenshot. My macro is looping to receive a line of text declaring that a USB stick was added or removed. I can then set the desired file path for the screenshot. My problem is that I am unable to jump to a subroutine when a key is pressed. If I can do that, then I can take my screenshot and return to the loop looking for USB addition or removal. Here's the code:

  1. ;******************************************************************************
  2. ; Ron's Macro for Tera Term
  3. ; Purpose: Detect presence of USB, set file path for copy of screenshot, take screenshot, and download screenshot from host.
  4. ; Environment: teraterm language
  5. ; Created: Tuesday, Sept. 30, 2008
  6. ; Modified: Thursday, NOV. 6, 2008
  7. ; Author: Ronald
  8. ;******************************************************************************
  9.  
  10. ;START HERE
  11. ;******************************************************************************
  12. ;Initialize connection
  13. connect '/C=1' ;Connect unlinked macro to host via COM port. ********* Make script to automatically detect and set connection **********
  14. result = 0 ;Set system variable result to 0 to enter the do while loop.
  15.  
  16. USB_There = 0 ;Set flag to 0 if USB is not there. Set flag to 1 if USB is there.
  17.  
  18. ;Initialize file path for screenshot copy
  19. Default_Path = "/mnt/media/HBPhotos/" ;Set the default file path for screenshot copy. Changing the default path here changes it everywhere.
  20. Building_Path = "/mnt/" ; Set the building path for string sprintf function.
  21. Destination_Path = "/HBPhotos/" ;Set the destination path for screenshot to be copied to.
  22. Path = Default_Path ;Set the default file path for screenshot copy into host.
  23. sendln "mkdir " Path ;Make destiation directory for copy of screenshot to host.
  24.  
  25. ;Initialize screen shot command parameters
  26. Sshot = "echo s-shot 0 " ;Set the command to take screenshot.
  27. Devwhat = " > /dev/" ;Set the dev branch to receive the screenshot command.
  28. ;******************************************************************************
  29. ;MAIN FUNCTION
  30.  
  31. do while result = 0 ;Repeatedly search for a new line from the host and evaluate the new line for desired command.
  32.  
  33. recvln ;Receive a line from the host. The received line is loaded into 'inputstr'.
  34.  
  35. strmatch inputstr 'ADD_USB_MSD_/mnt/umass\d{1,4}t\d{1,4}' ;Search received string for USB insertion.
  36.  
  37. if result > 0 call ADD_USB ;Evaluate received string for correct match. If string matches, then call the ADD_USB subroutine
  38.  
  39. strmatch inputstr 'REM_USB_MSD_/mnt/umass\d{1,4}t\d{1,4}' ;Search received string for USB removal.
  40.  
  41. if result > 0 call REM_USB ;Evaluate received string for correct match. If string matches, then call the REM_USB subroutine
  42.  
  43. ;SEARCH KEYSTROKE FOR SCREENSHOT HERE
  44.  
  45. ;SEARCH KEYSTROKE FOR PHOTODUMP HERE
  46.  
  47. ;SEARCH FOR KEYSTROKE TO QUIT MACRO
  48.  
  49.  
  50. loop
  51.  
  52. end
  53. ;******************************************************************************
  54. :ADD_USB
  55.  
  56. strcopy matchstr 18 14 Proper_USB_Title ;Search the received string for proper USB title for use in file path to copy screenshot.
  57.  
  58. sprintf "%s%s%s" Building_Path Proper_USB_Title Destination_Path ;Make the file path for screenshot copy.
  59.  
  60. Path = inputstr ;Copy the output from sprintf command to Path.
  61.  
  62. sendln "mkdir " Path ;Make the directory for the screenshot to be copied to on the USB drive.
  63.  
  64. USB_There = 1 ;Set flag to 1 because USB is there.
  65.  
  66. return
  67. ;******************************************************************************
  68. :REM_USB
  69.  
  70. Path = Default_Path ;Set Path to the default file path for screenshot copy into host.
  71.  
  72. USB_There = 0 ;Set flag to 0 because USB is not there.
  73.  
  74. return
  75. ;******************************************************************************
  76. :Take_Screenshot
  77.  
  78. getdate Filename "%y%m%d-%H%M%S.png" ;Input date information into Filename
  79.  
  80. sendln Sshot Path Filename Devwhat ;Enter command into host to take screenshot.
  81.  
  82. return
  83. ;******************************************************************************
  84. :Photo_Dump
  85.  
  86. if USB_There = 0 return ;Return from Photo_Dump subroutine if USB is not there.
  87.  
  88. enablekeyb 0 ;Disable terminal keyboard input
  89.  
  90. sendln "cp " Default_Path "*.png " Path ;Enter command to copy photos to the USB
  91.  
  92. sendln "rm " Default_Path "*.png" ;remove photos from the radio
  93.  
  94. enablekeyb 1 ;Enable the keyboard before ending the program
  95.  
  96. return


Top
 Profile E-mail  
 
 Post subject: Re: Help with hotkeys while macro is running.
PostPosted: Mon Nov 10, 2008 1:55 pm 
Offline
Guru

Joined: Wed Jan 25, 2006 10:28 pm
Posts: 630
Location: Denver, Colorado, USA
I think you can do what you want by programming a macro to create a certain file (like C:\tmp.txt for example). Program a function key to execute this macro.

Then, in the loop in your main macro, look for this certain file to exist. If it does, then send your commands to do a "screen shot" (not a real windows screen shot, evidently, and this is where the confusion arose) and then delete the file and continue the loop.


Top
 Profile  
 
 Post subject: Re: Help with hotkeys while macro is running.
PostPosted: Tue Jan 06, 2009 7:57 pm 
Offline
Newbie

Joined: Sat Nov 01, 2008 8:43 pm
Posts: 8
Hello Ishmael,

Using the existence of a file works great. I am able to make Teraterm do what I want it to do witout window focus now. I had to use AutoHotkey to bypass Windows' hotkey behavior. As far as I can tell, AutoHotkey is not able to create a text file. I am using AutoHotkey to copy a text file that serves as a flag for Teraterm. The findfirst command is working well for me. Here are my Teraterm and AutoHotkey codes respectively:

;MAIN FUNCTION

sendln "mkdir " Path ;Make destiation directory for copy of screenshot to host.

Call Check_USB ;Call the Check_USB subrouteine to test presence of USB.

result = 0 ;Set system variable result to 0 to enter the do while loop.

do while result = 0 ;Repeatedly search for a new line from the host and evaluate the new line for desired command.

recvln ;Receive a line from the host. The received line is loaded into 'inputstr'.

strmatch inputstr 'ADD_USB_MSD_/mnt/umass\d{1,4}t\d{1,4}' ;Search received string for USB insertion.

if result > 0 call ADD_USB ;Evaluate received string for correct match. If string matches, then call the ADD_USB subroutine.

strmatch inputstr 'REM_USB_MSD_/mnt/umass\d{1,4}t\d{1,4}' ;Search received string for USB removal.

if result > 0 call REM_USB ;Evaluate received string for correct match. If string matches, then call the REM_USB subroutine.

findfirst dirhandle 'HBscreen*.txt' foundscreen ;Search for screen function flag.

if result = 1 call Screen ;If flag contains screenshot message, then call the screenshot subroutine.

findfirst dirhandle 'HBscope*.txt' foundscope ;Search for scope function flag.

if result = 1 call Scope ;If flag contains scopeset message, then call the scopeset subroutine.

findfirst dirhandle 'HBsystem*.txt' foundsystem ;Search for system function flag.

if result = 1 call System ;If flag contains system message, then call the system subroutine.

findclose dirhandle ;Close the directory handle from findfirst command.

loop

end


;Ron's Auto Hot Key function for teraterm

F1:: FileCopy, C:\Program Files\AutoHotkey\HB\HBscreen1.txt , C:\Program Files\teraterm\

F2:: FileCopy, C:\Program Files\AutoHotkey\HB\HBscreen2.txt , C:\Program Files\teraterm\

F3:: FileCopy, C:\Program Files\AutoHotkey\HB\HBscreen3.txt , C:\Program Files\teraterm\

F4:: FileCopy, C:\Program Files\AutoHotkey\HB\HBscreen4.txt , C:\Program Files\teraterm\

F5:: FileCopy, C:\Program Files\AutoHotkey\HB\HBscope1.txt , C:\Program Files\teraterm\

F6:: FileCopy, C:\Program Files\AutoHotkey\HB\HBscope2.txt , C:\Program Files\teraterm\

F7:: FileCopy, C:\Program Files\AutoHotkey\HB\HBscope3.txt , C:\Program Files\teraterm\

F8:: FileCopy, C:\Program Files\AutoHotkey\HB\HBscopeCLR.txt , C:\Program Files\teraterm\

F9:: FileCopy, C:\Program Files\AutoHotkey\HB\HBsystem1.txt , C:\Program Files\teraterm\

F10:: FileCopy, C:\Program Files\AutoHotkey\HB\HBsystem2.txt , C:\Program Files\teraterm\

F11:: FileCopy, C:\Program Files\AutoHotkey\HB\HBsystem3.txt , C:\Program Files\teraterm\

F12:: FileCopy, C:\Program Files\AutoHotkey\HB\HBsystemquit.txt , C:\Program Files\teraterm\


Top
 Profile E-mail  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group