Jump to content

Recommended Posts

When ever you hover your mouse over a native function, user defined function, or an AutoItObject method then you will see the calltip for that function. 

Click "Like This" if you found this useful!

To use this just place the following lua file in the "...AutoIt3SciTELUA" directory. 

MouseHoverCalltips.zip

downloads:216

After you have done that then open SciTE and click 'Options' --> 'Open Lua Startup Script' and paste this line after the other lines (may require administrative rights):

LoadLuaFile("MouseHoverCallTips.lua")

Updates and changes:

[09/25/2014] Rewritten using the official AutoItGoToDefinition.lua!  Now all function and object method calltips are presented!  Most exciting update yet!

Edit: forgot to mention that this only works for those who have the latest AutoIt3 beta installed.

Edit 2: Now works for functions marked Volatile.  Also works on first open.

Edit3: Non-Volatile functions work too now again.

Edit4: Should finally work now!

[06/10/2014]  Calltips for AutoItObject methods should be a lot less error prone and much faster!

Edit: Fixed an issue with AutoItObject methods.

08/06/2013: OK.  Fixed the unexpected bugs. Damned bugs.  Now you should be able to create your AutoItObjects and then hover over their method names and properties for calltips!  For instance $oObject.MyProperty.MyMethod()  Hover over MyProperty to see what is stored there and over MyMethod to see the calltip for that function.

08/05/2013: Now you can view the function calltips for your AutoItObject Com methods and also see the value stored in your AIO COM properties!  Also fixed some inconsistencies in the code and improved other aspects etc.

08/04/2013: Added AutoItObject COM Functions!   Here are a couple of files to test the latest update: Test Files.

03/18/2013: Function "table_contains" added.

03/17/2013: Untested bug fix as reported by Sunaj.

03/02/2013: Bug fix as reported by Sunaj where the function that extracted the name of an include from a line would not work if there was not a space after "#include".

11/04/2012: I fixed it again.

10/26/2012: I breath another sigh.

10/20/2012: Fixed a bug that caused SciTE to lockup when using CTRL+J to access a native function or ALT+I to access a native include. Also, fixed a bug where if a function name was mentioned in the description for another different function then the calltip for the different function was displayed.

10/13/2012: More efficient and less code.

10/11/2012: Now when you type a new include line that include is added to the list of includes to be searched for function definitions. Also, even more efficient.

10/10/2012: No new features but a few bugs have been squashed and some inefficiencies eliminated. So, one bug was that if you have an include in the main file but not in another file and you use a function from the include in the second file then it wouldn't show the calltip though the function is in scope. That works now. Also, when the include table was generated there were a lot of duplicate entries. No longer! Behold, for they are trimmed (mostly, it's still buggy). Anyhoo, enjoy!

10/07/2012: Now all of the include files in a project are searched for user defined functions!

10/01/2012: Pattern matching allowed for the elimination of several functions. Hopefully more efficient. Also, calltips found in the api files are loaded once at startup into a table. Also, added the same thing but for the list of includes. Also, calltips now self cancel when you move the mouse again because I forgot that I was asked to make it do that.

09/27/2012: Tried my hand at implementing a basic proof of concept for finding function definitions in extralocal au3 files as requested by >D4RKON3. Consider this a beta trial and please tell me your thoughts, problems, etc. One difference now is the calltip window doesn't disappear as soon as you move your mouse. You have to click the mouse first. Also, when you define your own function then a comment at the end of the definition will be displayed as a calltip. Example:

func my_function_name(const $my_parameter) ; This is a description of the function.

Will become:

my_function_name(const $my_parameter)
This is a description of the function.

Here are a set of au3 files to test the latest update:

09/23/2012: I implemented a very basic, rudimentary implementation of a feature requested by trancexx. She wanted calltips for functions which were defined in the currently edited file. Give it a try, it might work! YAY! Using OnUpdateUI eliminates the need to switch buffers on every new session. May not be the most elegant solution. =P

Update: Valik greatly simplified and made it robust. Thank you!

Update: Back in business!

Update: Ah yes, debug statements. I should probably start using more of those.

Edited by jaberwacky
Link to post
Share on other sites
  • Replies 109
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Popular Posts

When ever you hover your mouse over a native function, user defined function, or an AutoItObject method then you will see the calltip for that function.  Click "Like This" if you found this useful!

Good job, a really really really god job. I know it's not your duty to do what others say, but I have a feature request that may be even impossible, but worth hearing! For me, I usually keep my funct

Our chitchat reminded me of Sandra Bullock + Stallone film Demolition Man or something, when she says "Let's blow this guy!", and Stallone says "...away! Dammit away!" So, don't make me blow you.

Can you add a timer or something to make the tip go away after some time if mouse isn't over a function?

I think that's what the OnDwellEnd function is for.

Another thing I thought of though, I think there's a way to use the lexer to tell what kind of word you are hovering. You should restrict the calltips to words the lexer identifies as functions so you don't get random calltips from comments or strings, etc.

Link to post
Share on other sites

That is what onDwellEnd is for but it's either messed up or I am using it wrong (most likely). I'll look into the timer as an alternative.

I looked into that lexer and I can't make heads or tails of it. I kinda have an idea of what's going on. You find out what kind of word you're at in the file (variable, function, comment, etc) and then you give that information to the styler along with a start position which takes over from there.

Edited by LaCastiglione
Link to post
Share on other sites

Here's where the strangeness comes in: you have to switch buffers before it will work on first load.

That's the opposite of the initial behavior. (working on a file/buffer after a file open, but not after switching buffers).

Maybe you need to use both OnOpen() and OnSwitchFile().

"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

Link to post
Share on other sites

I tried this but nothing doing:

MouseHoverCallTips = EventClass:new(Common)



function MouseHoverCallTips:OnOpen(path)

    MouseHoverCallTips:initialize_mouse_dwell()

    return true

end



function MouseHoverCallTips:OnSwitchFile(path)

    MouseHoverCallTips:initialize_mouse_dwell()

    return true

end



function MouseHoverCallTips:initialize_mouse_dwell()

    local mousehover_calltips_dwelltime = tonumber(props["mousehover.calltips.dwelltime"])



    if (mousehover_calltips_dwelltime == nil) then

        mousehover_calltips_dwelltime = 700 -- default

    end



    scite.SendEditor(SCI_SETMOUSEDWELLTIME, mousehover_calltips_dwelltime)



    return true

end



function MouseHoverCallTips:OnDwellStart(position, word)

    if (word == "") then

        return nil

    end



    local directory = props["SciteDefaultHome"] .. "apiau3.api"



    local file = io.open(directory, "r")



    local parens_start

    local parens_end

    local char_start

    local char_end



    for line in file:lines() do

        if (string.find(line, word)) then

            -- filter out entries ending with ?4, ?3, ?2, & ?1

            for var = 1, 4 do

                char_start, char_end = string.find(line, '?' .. var)



                if (char_start ~= nil) then

                    file:close()

                    return nil

                end

            end



            parens_start, parens_end = string.find(line, "%)")

            if (parens_start ~= nil) then

                line = string.gsub(line, "%)", "%)n", 1)

            end



            file:close()



            scite.SendEditor(SCI_CALLTIPSHOW, position, line)



            return true

        end

    end



    file:close()



    return true

end



function MouseHoverCallTips:OnDwellEnd()

    scite.SendEditor(SCI_CALLTIPCANCEL)

    return true

end

Edited by LaCastiglione
Link to post
Share on other sites

I looked into that lexer and I can't make heads or tails of it. I kinda have an idea of what's going on. You find out what kind of word you're at in the file (variable, function, comment, etc) and then you give that information to the styler along with a start position which takes over from there.

You don't have to understand the lexer I think. Just read the style of the first character of your word with SCI_GETSTYLEAT

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to post
Share on other sites

Just read the style of the first character of your word with SCI_GETSTYLEAT

Doh! I understand now. I do that from lua. Excellent. Thank you!

Edit: Ok, I did it and it works great! OP updated.

Edited by LaCastiglione
Link to post
Share on other sites

I tried this but nothing doing: ...

It should. (CQ: working for me.)

- OnOpen(): run's on every file that's loaded while scite is starting. And on files that are user loaded after the scite startup.

But note that OnSwitchFile() is also run on the active file/buffer if its not the last loaded file at scite startup. (and not on user loaded files/buffers ... until you switch buffers of course.)

PS: is OnDwellEnd() active? ... or not yet, as its never executed.on this side.

---

(I'm not sure what behavior's are scite4autoit related or native scites related.)

Edited by MvGulik

"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

Link to post
Share on other sites

AFAIK there is no OnDwellEnd(). OnDwellStart() is called with an empty string to signify that event according to the old documentation I read. If there is an event in later SciTE then the Events class isn't invoking it on inherited classes unless Jos caught it and added it.

Link to post
Share on other sites

Heh. You know something. I'm looking at the documentation again. I have no idea where I got onDwellEnd. Maybe my brain wished for something like that and tried to make it so.

Doh.

"OnDwellStart will receive the position of the mouse and the word under the mouse as arguments and the word will be empty when the mouse starts moving." So I updated the lua in the op.

Edited by LaCastiglione
Link to post
Share on other sites

Optional code suggestion:

-- 'if MouseHoverCallTips:IsAu3File(path) then', or 'if self:IsAu3File(path) then'.
-- Although I'm not sure if there is a significant/important differance between the two. (just to be clear)
function MouseHoverCallTips:IsAu3File(path)
    -- working, but I'm not sure if there is a better way.
    -- note: string.sub(props["au3"]), -4) ... assuming extention is 3 characters. (alt: ditch leading '*' character.)
    if (string.lower(string.sub(path, -4)) == string.lower(string.sub(props["au3"], -4))) then
        return true
    end
    return false
end

PS: Not sure if it matters. But just in case. There is no 'file:close()' after the "for line .." loop in OnDwellStart(). (for all I know the open file might be auto-closed on hitting EOF, or on exiting the function.)

"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

Link to post
Share on other sites

Roger ... Looks a little odd with those comments. ;)

Tried to see if there was a alternative way to get a hold of 'all' the API function definitions that are actively used by the current (local user) scite4autoit setup ... but no luck so far.

Anyone know if there is a other way than doing it the file:open way ?

Anyway ... extended the definition finder a bit to do it anyway. (added+changed functions only) (LC: use as you see fit.)

function MouseHoverCallTips:GetFuncDef(word, filespecList, delim)
    for filespec in string.gmatch(filespecList, "[^;]+") do
        local file = io.open(filespec, "r")
        if file ~= nil then
            local parens_start
            for line in file:lines() do
                if (string.find(line, word)) then
                    parens_start = string.find(line, "%)")
                    if (parens_start ~= nil) then
                        line = string.gsub(line, "%)(.)", "%)n%1") -- changed: was adding a trailing empty line in some cases.
                    end
                    file:close()
                    return line
                end
            end
            file:close()
        end
    end
end

function MouseHoverCallTips:OnDwellStart(position, word)
    if (word == "") then
        if (scite.SendEditor(SCI_CALLTIPACTIVE)) then
            scite.SendEditor(SCI_CALLTIPCANCEL)
        end
    end

    if (scite.SendEditor(SCI_GETSTYLEAT, position) == 4 or scite.SendEditor(SCI_GETSTYLEAT, position) == 15) then
        local funcdef = self:GetFuncDef(word, props["api.$(au3)"], ";")
        if funcdef ~= nil then
            scite.SendEditor(SCI_CALLTIPSHOW, position, funcdef)
        end
    end

    return true
end

"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

Link to post
Share on other sites

What's weird is that OnOpen is called when SciTE is opened and when I switch between buffers. So, I removed OnSwitchFile and restarted SciTE but calltips are still not displayed when I hover over a function even after switching buffers.

Edited by LaCastiglione
Link to post
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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By beautifulsoup
      Hi All,
      I'm not sure if its possible that I'm trying to achieve, I've looked into https://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/AutoIt3Wrapper.html and such resources for help, but I cant really find the answer to my question.
      So upon compiling the script in SciTE, the exe file is given a Description under file Properties>Details. I understand, that  one can enter info manually there and it can even implement the version automatically with each compilation.
       
      What I'm trying to achieve is to somehow include the "@ScriptName" in the Details>File Description Field. But as I see no variable can be taken after "#" in this case.
       
      Do You think its achievable? (Win 10)
       
      Much obliged for taking time on reading this.
       
      Kind Regards,
      Brave


    • By argumentum
      In the console under the editor in SciTE: 
      if I add @@ Debug(line,column) then it goes there.
      if I add "script.au3" (line,column) then it goes there if loaded.
      if I add "c:\path\script.au3" (line,column) then it loads the file and goes there.
      ...so far so good.
      Since I don't know LUA, nor where that is at, my question is ... where is it at ?
      A silly question because once there I would not know what to do, since I don't know LUA.
      What I want to achieve is, that since there is something delimiting the script and editor position (li,co), a way to have, let's say:
      +I like this color and the text that I care for on the left ["c:\path\script.au3" (line,column)]
      and by having this ["" ()] format ( or anything else, it don't have to be this exact format ), the console would know to jump there.
      If DClick to jump/goto Line,Column can trigger an external EXE or script, I'd take it from there. If it all can be done from LUA then, I'd do it there.
      So I don't mind or know how. I just would like that functionality. In a way that don't require a recompile of SciTE.
      Thanks  
    • By BugFix
      The block comment (internal: box comment) in SciTE cannot be toggled.
      I have now created a script that helps. It works with any file type for which the corresponding entries in the properties are created.For toggeling its required to detect, what the user want to do.
      EDIT 2021-04-14 [v0.10]
      In the meantime, I have changed and discarded a few things. But in my opinion, the current variant is much easier to handle:
      Rules for detection: UNSET COMMENT BLOCK - NEW: NONE SELECTION IS REQUIRED! There must exist an comment block near the cursor position (cursor inside the .start line or above). The script detects automatically the "comment.box.start" and the corresponding "comment.box.end" (also if nested) and works until this line. SET COMMENT BLOCK - Some text must selected (at minimum one character) - Starts and/or ends the selection inside of a line, the selection will expanded to full line. - Ends the selection in a line with text, but at line start position so will this line ignored! - Leading and trailing empty lines in selection will ignored! This means that in nested block comments there is at least one more line between two comment.box.start markers.
      It is recommended to write all block comment settings into "SciTEUser.properties". The setting "comment.box.end.au3" from "SciTEGlobal.properties" is incorrect and must be corrected.
      comment.box.start.au3=#cs #~ If you want characters or tab in each line of comment block (middle lines), define it here. #~ If TAB should used as box.middle, set it so: comment.box.middle.au3=@Tab #~ "@Tab" is replaced by a tabulator by the script. comment.box.middle.au3= comment.box.end.au3=#ce additional [optional] property: #~ message for comment block set or unset - output/none (1/0), default=0 (none output) #~ e.g.: "++ COMMENT BLOCK - UNSET [line 103-106]" #~ SET : current line numbers of commented text including the lines with .start .end #~ UNSET: current line number(s) of text that was commented comment.box.output=0 Connection to SciTE
      Search a free command number. Use a Hotkey of your choice. (or use the default shortcut: Ctrl+Shift+Q)
      If you have declared an option for user lua scripts (e.g.: "Lua.User.Scripts.Path=C:\code\lua"), copy the script to this folder.
      Otherwise copy it to a folder of your choice and change the path in the command: "dofile". But backslashes in the path must be masked. ("\\").
      If your path has spaces don't forgot to encapsulate in string delimiters.
      # 24 Toggle Block Comment command.name.24.*=Toggle Block Comment command.24.*=dofile $(Lua.User.Scripts.Path)/BlockComment.lua command.mode.24.*=subsystem:lua,savebefore:no command.shortcut.24.*=Ctrl+Alt+F10  
      Here the lua script:
      -- TIME_STAMP 2021-04-14 17:56:37 v 0.10 --[[ Toggle Block Comments ©BugFix ( autoit[at]bug-fix.info ) For toggeling its required to detect, what the user want to do. Rules for detection: UNSET COMMENT BLOCK - NEW: NONE SELECTION IS REQUIRED! There must exist an comment block near the cursor position (cursor inside the .start line or above). The script detects automatically the "comment.box.start" and the corresponding "comment.box.end" (also if nested) and works until this line. SET COMMENT BLOCK - Some text must selected (at minimum one character) - Starts and/or ends the selection inside of a line, the selection will expanded to full line. - Ends the selection in a line with text, but at line start position so will this line ignored! - Leading and trailing empty lines in selection will ignored! Properties: It is recommended to write all block comment settings into SciTEUser.properties. The setting "comment.box.end.au3" from "au3.properties" is wrong and must be corrected. comment.box.start.au3=#cs #~ If you want characters or tab in each line of comment block (middle lines), define it here. #~ If TAB should used as box.middle, set it so: comment.box.middle.au3=@Tab #~ "@Tab" is replaced by a tabulator by the script. comment.box.middle.au3= comment.box.end.au3=#ce additional [optional] property: #~ message for comment block set or unset - output/none (1/0), default=0 (none output) #~ e.g.: "++ COMMENT BLOCK - UNSET [line 103-106]" #~ SET : current line numbers of commented text including the lines with .start .end #~ UNSET: current line number(s) of text that was commented comment.box.output=0 Example with AutoIt comment: "SelectionStart" = [S] "SelectionEnd" = [E] ---------------------------------------------------------------------- selection: or or 1 [S]line with some text[E] 1 [S] 1 lin[S]e with some text[E] 2 line with some text[E] or or or 1 [S] 1 [S]line with some text 1 [S] 2 line with some text 2 [E] 2 line with so[E]me text 3 [E] or or 1 [S] 1 [S] ... empty lines 2 line with some text 5 ... empty lines 6 line with some text 6 7 [E] 7 [E] result for all: 1 #cs 2 line with some text 3 #ce ---------------------------------------------------------------------- ]] --[[ History v 0.10 - fixed: If last selected line is also last line in editor, the comment.end was set in this line and so was this line deleted if has toggled. v 0.9 - removed: comment.box.ignore.empty.before/after - was not very usefull - added: detection (and excluding) of leading and/or trailing empty lines in selection v 0.8 - fixed: Problem with selection starts/ends in the middle of a line or ends at the first position of the line with text v 0.7 - added: Automatic detection for comment blocks, NO SELECTION REQUIRED to unset a comment block - added: properties comment.box.ignore.empty.before: if first selected line is empty -- don't include in comment block comment.box.ignore.empty.after: if last selected line is empty -- don't include in comment block comment.box.output: if "1" -- write result of proceeding to console, default is "0" - changed: minimum required selection to start block comment: 1 character v 0.6 - fixed: if selection for uncommenting is wrong, leading/trailing empty line will removed v 0.5 - fixed: the trailing line break from comment.end while uncommenting will not removed v 0.4 - added: detection for uncommenting if selection is wrong (starts/ends in empty line) v 0.3 - project new designed (object syntax) v 0.2 - fixed: missed adding of middle marker in first line ]] local BlockComment = { -- variables ext, -- file extension boxStart, -- property: comment.box.start boxMiddle, -- property: comment.box.middle boxEnd, -- property: comment.box.end bMiddle, -- bool: boxMiddle is defined lenEOL, -- length of line break character(s) from file in editor eol, -- the end of line character(s) in this file msg = {}, -- store line numbers (start, end) for proceeding message selS = {}, -- selection start selE = {}, -- selection end -- selection table fields: -- .pos, -- selection position -- .line, -- selection line number newText, -- the text that replaces the selection -- initialize variables Init = function(self) self.ext = props["FileExt"] self.boxStart = props["comment.box.start."..self.ext] self.boxMiddle = props["comment.box.middle."..self.ext] self.bMiddle = not (self.boxMiddle == "") self.boxEnd = props["comment.box.end."..self.ext] if self.boxMiddle == "@Tab" then self.boxMiddle = "\t" end self.selS = self:SelLineData(editor.SelectionStart) self.selE = self:SelLineData(editor.SelectionEnd) self.lenEOL = self:GetEOL() self.eol = "\n" if self.lenEOL == 2 then self.eol = "\r\n" end self.newText = "" end, -- stores #pos and #line from selection position SelLineData = function(self, _selPos) -- _selPos: editor.SelectionStart or editor.SelectionEnd local t = {} t.pos = _selPos t.line = editor:LineFromPosition(t.pos) return t end, -- returns position from start and end (behind last visible char) of a line LineStartEndPos = function(self, _line) local startP = editor:PositionFromLine(_line) local endP = editor.LineEndPosition[_line] return startP, endP end, -- returns the length of EOL (default) or with "_getMode=true": LF/CRLF -- asking the property "eol.mode.type" is not safe, maybe not set and the global value may differ from the file in the editor GetEOL = function(self, _getMode) -- It is possible that another program makes entries (e.g.: version number) at the beginning of the file.. -- ..with a different EOL mode, therefore the second last line (last line with line break) of the file is checked. local l = editor.LineCount -2 local lenEOL if l < 0 then -- the eol.mode from properties will used instead (but not sure, if exists) local mode = props["eol.mode."..self.ext] -- mode for file type (if declared) if mode == "" then mode = props["eol.mode"] end -- otherwise the global mode if mode == "LF" then lenEOL = 1 else lenEOL = 2 end else local textEnd = editor.LineEndPosition[l] -- pos after last visible character local posLineStart = editor:PositionFromLine(l) -- first pos in line local textLen = textEnd - posLineStart -- pure text length local len = editor:LineLength(l) -- length of line including the line break characters lenEOL = len - textLen -- length of line line break characters end if _getMode then if lenEOL == 1 then return "LF" else return "CRLF" end else return lenEOL end end, -- detects if is/not selection IsSelection = function(self) return (self.selS.pos ~= self.selE.pos) end, -- mask magic characters MaskMagic = function(self, _s) if _s == nil then return "" end return _s:gsub('([%(%)%.%%%+%-%*%?%[%^%$])', '%%%1') end, -- checks if line is empty (has only a line break) LineIsEmpty = function(self, _line) -- _line: number or text from "editor:GetLine" if type(_line) == "string" then return (_line:len() == self.lenEOL) end if _line == nil then return true end local len = editor:LineLength(_line) return (len <= self.lenEOL) end, -- checks if line starts with/has box.start -- detects it also, if nested and middle marker(s) before the start marker LineHasStart = function(self, _line) if self:LineIsEmpty(_line) then return false end if type(_line) == "number" then _line = editor:GetLine(_line) end local pattern if self.boxMiddle == '' then pattern = self:MaskMagic(self.boxStart) else pattern = self:MaskMagic(self.boxMiddle)..'*'..self:MaskMagic(self.boxStart) end local n = _line:find(pattern) return (n ~= nil) end, -- checks if line starts with/has box.end -- detects it also if nested, and middle marker(s) before the end marker LineHasEnd = function(self, _line) if self:LineIsEmpty(_line) then return false end if type(_line) == "number" then _line = editor:GetLine(_line) end local pattern if self.boxMiddle == '' then pattern = self:MaskMagic(self.boxEnd) else pattern = self:MaskMagic(self.boxMiddle)..'*'..self:MaskMagic(self.boxEnd) end local n = _line:find(pattern) return (n ~= nil) end, -- remove middle marker/add line UncommentMiddleLine = function(self, _bMiddle, _text) if _bMiddle then self.newText = self.newText.._text:gsub("^("..self:MaskMagic(self.boxMiddle)..")", "") else self.newText = self.newText.._text end end, -- checks if passed line is last line in editor AND selection ends not at line start position IsLastLine = function(self, _line) return (editor.LineCount == (_line + 1)) and (editor:PositionFromLine(_line) ~= self.selE.pos) end, -- the ternary operator ternary = function(self, _condition, _ifTrue, _ifFalse) if _condition == true then return _ifTrue else return _ifFalse end end, -- creates the text to toggle and replace the selection with it Toggle = function(self) self:Init() local firstVisibleLine = editor.FirstVisibleLine local countNesting, bStart, nStart, text, nLine, replS, replE = 0, false, -1 local lineStart, lineEnd, bLastLine local sStart, sEnd = self:MaskMagic(self.boxStart), self:MaskMagic(self.boxEnd) local sMiddle = self:MaskMagic(self.boxMiddle) local bUsedMiddle = false -- (for uncommenting) check if first line after comment.start, starts with comment.box.middle marker local insertMiddle = "" if self.bMiddle then insertMiddle = self.boxMiddle end -- error check if self.boxStart == "" or self.boxEnd == "" then return print("! ERROR - The comment.box properties for *."..self.ext.." files are missing or incomplete.") end -- check for set comment block if (not self:IsSelection()) then -- none selection - means: Unset CommentBlock -- start unset self.msg.action = 'COMMENT BLOCK - UNSET' nLine = self.selS.line while nLine < editor.LineCount do text = editor:GetLine(nLine) -- line with eol if (not bStart) and self:LineHasStart(text) then -- first line with comment.box.start bStart = true self.msg.starts = nLine nStart = nLine replS = editor:PositionFromLine(nLine) -- save the start position for replacing end if nLine == nStart +1 then -- first line after comment.box.start if self.bMiddle then -- check if comment.box.middle is used, if defined local n = text:find(sMiddle) if n == 1 then bUsedMiddle = true end -- true, if starts with it end end if self:LineIsEmpty(text) then -- do nothing with empty lines, add them only if start was detected before if bStart then self.newText = self.newText..text end -- text is only a line break else if self:LineHasEnd(text) then -- the box.end or a nested box.end countNesting = countNesting -1 -- decrease nesting counter if countNesting == 0 then -- it's the corresponding end position self.newText = self.newText:sub(1, -(self.lenEOL +1)) -- ignore text from this line and delete line break from stored line before replE = editor.LineEndPosition[nLine] -- save the end position (w.o. line break) for replacing self.msg.ends = nLine -2 break -- leave the loop else -- will be treated as middle line (it's a nested comment.box.end) self:UncommentMiddleLine(bUsedMiddle, text) end elseif self:LineHasStart(text) then countNesting = countNesting +1 -- increase nesting counter -- countNesting == 1 it's the real start of block comment --> ignore this line if countNesting > 1 then self:UncommentMiddleLine(bUsedMiddle, text) end -- treat it like a middle line else -- all other cases are middle lines but if not start was detected - ignore this line if bStart then self:UncommentMiddleLine(bUsedMiddle, text) end end end nLine = nLine +1 end if (not bStart) then return print("! ERROR - None comment block starts near the cursor.") -- text near Cursor isn't comment block start marker end else -- set comment block self.msg.action = 'COMMENT BLOCK - SET' if self.selS.line == self.selE.line then -- selection is in one line text = editor:GetLine(self.selS.line) lineStart = editor:PositionFromLine(self.selS.line) lineEnd = editor.LineEndPosition[self.selS.line] + self.lenEOL editor:SetSel(lineStart, lineEnd) -- select all text in line bLastLine = self:IsLastLine(self.selE.line) if bLastLine then self.boxEnd = self.eol..self.boxEnd end self.newText = self.boxStart..self.eol..insertMiddle..text..self.boxEnd..self:ternary(bLastLine, '', self.eol) self.msg.starts = self.selS.line self.msg.ends = self.selS.line +2 else -- as 1.: find the last line with text in selection, possibly blank lines are selected at the end local iLineLastText = -1 for i = self.selE.line, self.selS.line, -1 do if (not self:LineIsEmpty(i)) then iLineLastText = i break end end -- none text selected if iLineLastText == -1 then return print("! ERROR - Only empty lines selected.") end if iLineLastText ~= self.selE.line then self.selE.line = iLineLastText self.selE.pos = editor.LineEndPosition[self.selE.line] end bLastLine = self:IsLastLine(self.selE.line) if bLastLine then self.boxEnd = self.eol..self.boxEnd end for i = self.selS.line, self.selE.line do text = editor:GetLine(i) if i == self.selS.line then -- selection start line if (not self:LineIsEmpty(text)) then lineStart = editor:PositionFromLine(self.selS.line) if lineStart ~= self.selS.pos then self.selS.pos = lineStart editor:SetSel(self.selS.pos, self.selE.pos) end self.newText = self.boxStart..self.eol..insertMiddle..text self.msg.starts = i else -- start line is empty - do nothing end elseif i == self.selE.line then -- selection end line if self.newText == "" then -- the last line is the 1st line with text in selection self.newText = self.boxStart..self.eol self.selS.pos = editor:PositionFromLine(i) self.msg.starts = i end lineStart = editor:PositionFromLine(i) lineEnd = editor.LineEndPosition[i] if lineStart == self.selE.pos then -- selection ends at line start position self.newText = self.newText..self.boxEnd..self.eol -- ignore this line self.msg.ends = i +2 break end if lineEnd == self.selE.pos then -- selection ends behind last visible char self.newText = self.newText..insertMiddle..text..self.boxEnd -- without EOL self.msg.ends = i +2 break end if lineEnd > self.selE.pos then -- selection ends inside the line, line will used self.selE.pos = lineEnd + self.lenEOL -- set selE.pos to line end for correct replacing end self.newText = self.newText..insertMiddle..text..self.boxEnd..self:ternary(bLastLine, '', self.eol) self.msg.ends = i +2 else -- middle lines if (not self:LineIsEmpty(i)) and self.newText == "" then -- may be only empty lines in selection before self.newText = self.boxStart..self.eol self.selS.pos = editor:PositionFromLine(i) self.msg.starts = i end if self.newText ~= "" then self.newText = self.newText..insertMiddle..text end end end editor:SetSel(self.selS.pos, self.selE.pos) end end -- replace the selection with the new toggled text if bStart then editor:SetSel(replS, replE) end -- for uncommenting exists none selection - do it here editor:ReplaceSel(self.newText) -- replace the next editor:SetSel(self.selS.pos,self.selS.pos) -- set the cursor to start position editor.FirstVisibleLine = firstVisibleLine -- make the first visible line visible again if props["comment.box.output"] == "1" then print(string.format('++ %s [line %d-%d]', self.msg.action, self.msg.starts +1, self.msg.ends +1)) end end } BlockComment:Toggle() As far as I know, it is not possible to overwrite SciTE internal hotkeys. In this case "Ctrl+Shift+B" for IDM_BLOCK_COMMENT. Therefore I used the connection shown here.
      But if overwriting is possible, I would be interested in this solution.
       
      BlockComment.lua
    • By Dave1
      Hello everyone,
      I have several signals on the screen that need to be monitored while a program is running. These signals are scattered around an image which is maximized on 4  equal resolution screens - the AutoIT Window Info does not recognize any objects on the program meaning that I'm left with the PixelSearch() and PixelCheckSum() functions to monitor the signals:
      The signals are as small as a 5x5 pixel area and their coordinates are known.
      I've been digging around for a while now in this forum about the PixelSearch() and PixelCheckSum()  and found some interesting and useful ideas for the use of them. I also came across some other UDF functions like MultiMon(), FastFind(), TtColXY() and the ImageSearch2015 scripts that might be useful for the final output. I don't know if hovering the mouse by using TtColXY() and output its ToolTip() information onto the log file will be faster than using PixelSearch() and/or PixelCheckSum() in a loop for all signals' coordinates.
      The colours of the signals are below:
      red - 0x00FF00 (opaque red)
      green - 0x00FF00 (opaque green)
      yellow - 0xFFFF00 (opaque yellow)
      black - 0x000000 (opaque black, default colour)
      EDIT:
      The desired output is to monitor and record/log the changes and status of each inside a .txt file or a .csv with the below format: 
      Local Machine Time        Signal,      Change,               delta-t
      14:32:07                  Signal1     Green - Yellow         DELTA-t1
      14:34:02                  Signal1     Yellow - Red           DELTA-t1
      14:35:14                  Signal2     Yellow - Red           DELTA-t2
      ...
      Below is the code I came up with. 
      #include <AutoItConstants.au3> #include <MsgBoxConstants.au3> #include <misc.au3> #include <Date.au3> #include <Array.au3> #include <File.au3> #include <ScreenCapture.au3> #include <WinAPI.au3> #include <WinAPIHObj.au3> Global $program_name, $program_open, $Wname, $tCurrent Global $button_xy[2] = [150, 175] Global $iniColour, $ColourCheck, $NewCheck Global $Red, $Green, $Blue, $Nil Global $sFilePath = @ScriptDir & "\Signals_status.txt" Global $SignalID[10] = ["Signal_1", "Signal_2", "Signal_3", "Signal_4", "Signal_5", "Signal_6", "Signal_7", "Signal_8", "Signal_9", "Signal_10"] $program_name = "Signals.exe" $Wname = "Training Task 3" $program_open = ShellExecute($program_name, @ScriptDir) WinWait($Wname) $iniColour = "0x" & Hex(PixelGetColor($button_xy[0], $button_xy[1]), 6) ;~ $iniChecksum = "0x" & Hex(PixelChecksum($button_xy[0], $button_xy[0] - 5, $button_xy[1], $button_xy[1] + 5), 6) $ColourCheck = "0x" & Hex(PixelChecksum($button_xy[0], $button_xy[0] - 5, $button_xy[1], $button_xy[1] + 5, 1, $Wname), 6) ConsoleWrite(_ColourID($iniColour) & " // " & _ColourID($ColourCheck) & @CRLF) ;~ $ColourCheck = "0x " & Hex(PixelGetColor($button_xy[0], $button_xy[1]), 6) $iniColour = $ColourCheck ;$iniChecksum = $currentCheck Do ;~ While 1 _WindowOnTop() _Close_Notepad() $NewCheck = "0x" & Hex(PixelChecksum($button_xy[0], $button_xy[0] - 5, $button_xy[1], $button_xy[1] + 5, 1, $Wname), 6) $tCurrent = _NowCalc() $LogFile = FileOpen($sFilePath, 2) FileWriteLine($LogFile, "Local Machine Time " & "Signal, " & "Change, " & "delta-t") ;~ $ColourCheck = "0x" & Hex(PixelChecksum($button_xy[0], $button_xy[0] - 5, $button_xy[1], $button_xy[1] + 5, 1, $Wname), 6) If $ColourCheck <> $NewCheck Then ;If there's a colour change from the current colour $ColourCheck = $NewCheck Local $tChange, $NewCheckID, $ColourCheckID, $sLogMsg $tChange = _NowCalc() ConsoleWrite("Colour changed!" & @CRLF) $ColourCheckID = _ColourID($ColourCheck) $NewCheckID = _ColourID($NewCheck) $iTimeDiffh = _DateDiff('h', $tChange, $tCurrent) ; time difference in hours $iTimeDiffm = _DateDiff('n', $tChange, $tCurrent) ; time difference in minutes $iTimeDiffs = _DateDiff('s', $tChange, $tCurrent) ; time difference in seconds $durationCheckSum = $iTimeDiffh & ":" & $iTimeDiffm & ":" & $iTimeDiffs ; Timestamp of the signal until PixelCheckSum $sLogMsg = " " & $SignalID[0] & " " & $ColourCheckID & " - " & $NewCheckID & " " & $durationCheckSum _FileWriteLog($LogFile, $sLogMsg) ElseIf $ColourCheck = $NewCheck Then Local $Colour_check = _ColourID("0x" & Hex(PixelChecksum($button_xy[0], $button_xy[0] - 5, $button_xy[1], $button_xy[1] + 5, 1, $Wname), 6)) ConsoleWrite($tCurrent & " " & $Colour_check & @CRLF) EndIf FileClose($sFilePath) Until Not ProcessExists($program_name) And Not WinExists($Wname) _IsProgramOpen() Func _Close_Notepad() $notepad_open = ProcessExists("notepad.exe") ? ProcessClose("notepad.exe") : ProcessClose("notepad.exe") $notepad_open = WinActive("[CLASS:Notepad]") ? WinClose("[CLASS:Notepad]") : ProcessClose("notepad.exe") EndFunc ;==>_Close_Notepad Func _ColourID($sColour) $Red = Int("0x" & StringRegExpReplace($sColour, "(..)(..)(..)(..)", "\2")) $Green = Int("0x" & StringRegExpReplace($sColour, "(..)(..)(..)(..)", "\3")) $Blue = Int("0x" & StringRegExpReplace($sColour, "(..)(..)(..)(..)", "\4")) If $Green > $Blue And $Red > $Blue And $Green >= 0xB0 And $Red >= 0xB0 Then $sCol = "Yellow" ElseIf $Blue > 0xE0 And $Green > 0xE0 And $Red > 0xE0 Then $sCol = "White" ElseIf $Blue > 0x50 And $Blue = $Green And $Blue = $Red Then $sCol = "Grey" ElseIf $Red > $Green And $Red > $Blue And $Red > 0x70 Then $sCol = "Red" ElseIf $Green > $Red And $Green >= $Blue And $Green > 0x70 Then $sCol = "Green" ElseIf $Blue > $Red And $Blue > $Green And $Blue > 0x70 Then $sCol = "Blue" Else $sCol = "Nil" EndIf Return $sCol EndFunc ;==>_ColourID Func _WindowOnTop() WinActivate($Wname) WinSetOnTop($Wname, "", $WINDOWS_ONTOP) Opt("MouseCoordMode", 0) EndFunc ;==>_WindowOnTop Func _IsProgramOpen() If Not ProcessExists($program_name) And Not WinExists($Wname) Then Break(1) EndIf EndFunc ;==>_IsProgramOpen When the program is running, the window opens in the centre of the screen however, the PixelChecksum function is not looking at the correct area. In addition:
      1 - I'm not sure about how to put the message into the log file.
      2 - I tested this script but it is not recording the message into the log file.
      3 - Is there other way to calculate the duration in these lines?
      $iTimeDiffh = _DateDiff('h', $tChange, $tCurrent) ; time difference in hours $iTimeDiffm = _DateDiff('n', $tChange, $tCurrent) ; time difference in minutes $iTimeDiffs = _DateDiff('s', $tChange, $tCurrent) ; time difference in seconds $durationCheckSum = $iTimeDiffh & ":" & $iTimeDiffm & ":" & $iTimeDiffs ; Timestamp of the signal until PixelCheckSum $sLogMsg = " " & $SignalID[0] & " " & $ColourCheckID & " - " & $NewCheckID & " " & $durationCheckSum _FileWriteLog($LogFile, $sLogMsg) Thanks in advance!
    • By Bhooshan
      I need to mute an ongoing call on Microsoft teams without activating the window. Teams allows us to mute using shortcut key Ctrl+Shift+m but only when the window is active.
      # Used set option as ongoing call can be with any person which leads to change in Title Name.
      AutoItSetOption ( "WinTitleMatchMode", 2 ) 
      # I am not clear with the control ID which will be good to use here and also the key combination of ^M       
      ControlSend ( "Microsoft Teams", "", "[CLASS:Intermediate D3D Window; INSTANCE:1]", "{ctrl down}")
       
      Can anyone help...!!! 
       

×
×
  • Create New...