Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Predefined variable for the mouse pointer
#1
I suggest that QM can contain a predefined variable of the mouse pointer, for example: _cursor , this function is very useful in automatic text, autohotkey has this function

In the following example, if I use this variable, after the character is entered, the mouse cursor jumps to the position of the variable.

In QM2, how to use code to achieve? thanks

Autotext Autotext1
Trigger $t     Help - how to add the trigger to the macro
Code:
Copy      Help
/b/i/c/m

text :key F"hello {_cursor}, thank you!"
#2
How to achieve the following functions, Please see the picture below

The name after %input_****% will appear in the input dialog box in order,and finally, it will be filled in automatically.

The mouse cursor will eventually stop at the variable %Cursor%

These features are very useful.

thank you very much
#3
If QM, can achieve the same function through the following code, it would be great.
This feature greatly improves the efficiency of inputting AutoText Idea


Autotext Autotext3
Trigger $t     Help - how to add the trigger to the macro
Code:
Copy      Help
/b/i/c/m
cme :sub.Sub1 ;;Customer Mail Example


#sub Sub1 m
_s=
F
;Dear Mr. $inp_Customer$,
;
;thank you for contacting us. The price is $$inp_Price$. Let's meet next $inp_Day$.
;
;Thanks and best regards,
;$cur$
;
;$A_ShortDate$

key (_s)
#4
Function AutoInputDialog
Code:
Copy      Help
;/
function'str $template [int&nLeft]

;Shows an auto-created dialog containing Edit and ComboBox controls specified in template text like $inp_Label$.
;Returns template text where these substrings are replaced with user input.
;Also can contain variables like $var_Name$ that are replaced by your callback function.

;REMARKS
;Special substrings:
;$inp_Label$ - creates an Edit control and static text Label.
;$sel_Label$ - creates a ComboBox control and static text Label. To get ComboBox items, calls your function named AID_sel. See examples there.
;$var_Name$ - calls your function named AID_var. See examples there.
;$set_CaretHere$ - removes and sets nLeft = the number of Left keys to move the caret (text cursor) here.

;On Cancel ends this thread.

;Example - code in function KeyAutoInputDialog.
;In scripts you'll probably use KeyAutoInputDialog, not this function. Use this function only to create functions similar to KeyAutoInputDialog, for example to use paste instead of key.


ARRAY(str) a
if(!findrx(template "\$(?:inp|sel)_(.+?)\$" 0 4 a)) ret template

ARRAY(str) c.create(a.len+1)
c[0]="3"
str dd
dd.formata("BEGIN DIALOG[]0 '''' 0x90C80AC8 0x0 0 0 224 %i ''Manual Text Input''[]" a.len*30+40)
int i idEdit(3) idStatic(503) y(8)
for i 0 a.len
,dd.formata("%i Static 0x54000000 0x0 8 %i 214 10 ''%s''[]%i " idStatic y a[1 i].escape(1) idEdit)
,sel a[0 i][1]
,,case 'i'
,,dd.formata("Edit 0x54030080 0x200 8 %i 208 13[]" y+12)
,,case 's'
,,dd.formata("ComboBox 0x54230242 0x0 8 %i 208 213[]" y+12)
#ifdef AID_sel
,,c[i+1]=a[0 i]
,,AID_sel c[i+1]
#endif
,if(i) c[0].formata(" %i" idEdit)
,y+30
,idEdit+1
,idStatic+1
y+10
dd.formata("1 Button 0x54030001 0x4 116 %i 48 14 ''OK''[]2 Button 0x54030000 0x4 168 %i 48 14 ''Cancel''[]END DIALOG" y y)
;out dd

if(!ShowDialog(dd 0 &c[0])) end

str r
ARRAY(POINT) b
findrx(template "\$(?:inp|sel)_.+?\$" 0 4 b)
int j
for i 0 b.len
,POINT& p=b[0 i]
,r.geta(template j p.x-j)
,int u=0; if(template[p.x+1]='s') val(c[i+1] 0 u); u+1
,r+c[i+1]+u
,j=p.y
r.geta(template j)

#ifdef AID_var
REPLACERX k2.frepl=&sub.RRX
r.replacerx("\$var_\w+\$" k2)
#endif

if &nLeft
,nLeft=0
,i=find(r "$set_CaretHere$")
,if i>=0
,,r.remove(i 15)
,,for(i i r.len) if(r[i]!13) nLeft+1

ret r


#sub RRX
function# REPLACERXCB&x

AID_var(x.match)
Function KeyAutoInputDialog
Code:
Copy      Help
;/
function $template

;Calls <help>AutoInputDialog</help> and types the text. Also sets caret if need.

;EXAMPLE
;_s=
;F
;;Dear Mr. $inp_Customer$,
;;
;;thank you for contacting us. The price is $$inp_Price$. Let's meet next $inp_Day$.
;;
;;Thanks and best regards,
;;$set_CaretHere$
;;
;;$var_ShortDate$
;;
;KeyAutoInputDialog(_s)


int nLeft
str s=AutoInputDialog(template nLeft)
spe 10
key (s)
if(nLeft) key L(#nLeft)

AID_var example
Function AID_var
Code:
Copy      Help
;/
function str&s

sel s
,case "$var_ShortDate$"
,s.timeformat("{D}")
,
,case "$var_PcName$"
,GetUserInfo s 1

;add more case "$var_Something$" if need

AID_sel example
Function AID_sel
Code:
Copy      Help
;/
function str&s

sel s
,case "$sel_Call$"
,s="Mrs[]Mr"
,
,case "$sel_Country$"
,s="United States[]United Kingdom[]France"

;add more case "$sel_Something$" if need

example
Macro Macro365
Code:
Copy      Help
out

str s=
;Dear $sel_Call$. $inp_Customer$,
;
;thank you for contacting us. The price is $$inp_Price$. Let's meet next $inp_Day$.
;
;Our office is at $sel_Country$
;
;Thanks and best regards,
;$set_CaretHere$
;
;$var_ShortDate$
;
KeyAutoInputDialog s


#ret
#5
Thank you very much for your help, this is a great feature, Smile

I have encountered two problems in the test:

1. How to make the edit box support drag and drop, for example, when I drag the file onto the edit box, automatically enter the filefullpath of the file

2.I added a custom variable $var_pcname$ but after the output, there is no blank line


Function AutoInputDialog
Code:
Copy      Help
;/
function'str $template [int&nLeft]

;Shows an auto-created dialog containing Edit and Static controls specified in template text like $inp_Label$. The Label part sets static text.
;Returns template text where these substrings are replaced with user input.

;REMARKS
;Special strings:
;$var_ShortDate$ - replaces with current date.
;$set_CaretHere$ - removes and sets nLeft = the number of Left keys to move the caret (text cursor) here.

;On Cancel ends this thread.

;Example - KeyAutoInputDialog code.


ARRAY(str) a
if(!findrx(template "\$inp_(.+?)\$" 0 4 a 1)) ret template

ARRAY(str) c.create(a.len+1)
c[0]="3"
str dd
dd.formata("BEGIN DIALOG[]0 '''' 0x90C80AC8 0x0 0 0 224 %i ''Manual Text Input''[]" a.len*30+40)
int i idEdit(3) idStatic(503) y(8)
for i 0 a.len
,dd.formata("%i Static 0x54000000 0x0 8 %i 214 10 ''%s''[]%i Edit 0x54030080 0x200 8 %i 208 13[]" idStatic y a[0 i].escape(1) idEdit y+12)
,if(i) c[0].formata(" %i" idEdit)
,y+30
,idEdit+1
,idStatic+1
y+10
dd.formata("1 Button 0x54030001 0x4 116 %i 48 14 ''OK''[]2 Button 0x54030000 0x4 168 %i 48 14 ''Cancel''[]END DIALOG" y y)
;out dd

if(!ShowDialog(dd 0 &c[0])) end

str r
ARRAY(POINT) b
findrx(template "\$inp_.+?\$" 0 4 b)
int j
for i 0 b.len
,POINT& p=b[0 i]
,r.geta(template j p.x-j)
,r+c[i+1]
,j=p.y
r.geta(template j)

i=find(r "$var_ShortDate$")
if(i>=0) r.replace(_s.timeformat("{D}") i 15)

;$var_pcname$
str s2
GetUserInfo s2 1
i=find(r "$var_pcname$")
if(i>=0) r.replace(s2 i 15)

if &nLeft
,nLeft=0
,i=find(r "$set_CaretHere$")
,if i>=0
,,r.remove(i 15)
,,for(i i r.len) if(r[i]!13) nLeft+1

ret r


Autotext Autotext3
Trigger $t     Help - how to add the trigger to the macro
Code:
Copy      Help
/b/i/c/m
cme :sub.Sub1 ;;Customer Mail Example


#sub Sub1 m
_s=
F
;Dear Mr. $inp_Customer$,
;
;thank you for contacting us. The price is $$inp_Price$. Let's meet next $inp_Day$.
;
;Myfile is here "$inp_Filepath$"
;
;Thanks and best regards,
;$set_CaretHere$
;
;pcname is $var_pcname$
;
;$var_ShortDate$
;
KeyAutoInputDialog(_s)
#6
I updated the code.
Now supports ComboBox controls and callback functions for replacing variables and getting ComboBox items.
With ListBox would need more work. Need to calculate height.
#7
I have encountered two interesting questions. Big Grin

I am using AutoText3 to add items to AID_sel

1. How to perform internal escaping of statements

2. How to keep the original TAB indentation (Excess tab indentation will also cause variable ($set_CaretHere$) errors)

Please see the GIF image below

Autotext Autotext3
Trigger $t     Help - how to add the trigger to the macro
Code:
Copy      Help
/b/i/c/m
var :sub.Sub2 ;;var_sel_add


#sub Sub2 m
_s=
F
;,case "$sel_$inp_Name$$"
;,s="$inp_item1$[]$inp_item2$[]$inp_item3$"
KeyAutoInputDialog(_s)
#8
to make that work do this

Code:
Copy      Help
#sub Sub2 m
_s=
;,case "$inp_Name$"
;s="$inp_item1$[]$inp_item2$[]$inp_item3$"
KeyAutoInputDialog(_s)

then fill out form like so

   
#9
I changed s to c and changed it back later.  Big Grin

#sub Sub2 m
_s=
F
     case "$cel_$inp_Name$$
     s="$inp_item1$[]$inp_item2$[]$inp_item3$"
KeyAutoInputDialog(_s)
#10
easier to do my way. No need to change later or fix indentation

also the F parameter is not needed at all in your sub function
#11
thanks,

Can really solve the indentation problem, Smile

it is a bit inconvenient , I think there may be a better way Cool
#12
the indentation problem has been explained to you before. The KeyAutoInputDialog use key to place the text so a new line will create extra indentation
#13
I think that the above Functions and  (Add AutoText dialog) can create countless possibilities. Smile
#14
sorry posted wrong code

here is correct code will work without having to worry about indentation issues
 
Code:
Copy      Help
#sub Sub2 m
_s=
;,case "$inp_Name$"
;,s="$inp_item1$[]$inp_item2$[]$inp_item3$"
str s=AutoInputDialog(_s)
paste s
#15
thanks, In the add autotext dialog I understand the wrong, Confused

the above code can really solve the indentation problem.  Can you add this code to the add autotext dialog?

Now there is only a problem of escaping.
#16
the above code is not for everything.If you want to place the cursor the above code will not work
#17
I think it is possible to add a judgment condition to the function body. If a new line is created, the tab is deleted first.

I have found this problem only in the QM editor, there is no problem in Notepad.

I very much hope that the indentation and escaping problems can be solved elegantly and thoroughly.

This will solve many headaches.  Shy
#18
If a code editor auto-indents code and you want to avoid it, use paste, not key.

Function PasteAutoInputDialog
Code:
Copy      Help
;/
function $template

;Calls <help>AutoInputDialog</help> and pastes the text. Also sets caret if need.

;EXAMPLE
;_s=
;F
;;Dear Mr. $inp_Customer$,
;;
;;thank you for contacting us. The price is $$inp_Price$. Let's meet next $inp_Day$.
;;
;;Thanks and best regards,
;;$set_CaretHere$
;;
;;$var_ShortDate$
;;
;PasteAutoInputDialog(_s)


int nLeft
str s=AutoInputDialog(template nLeft)
spe 10
paste s
if(nLeft) key L(#nLeft)

Other option - before key insert opt keychar 1. Then some code editors, including QM, will not auto-indent when previous line is tab-indented. But still will auto-indent after lines such as 'if', 'sel', 'rep'. Better paste.
#19
Thanks for your help, tab indentation has been resolved

I just discovered a new feature, which is another feature that creates unlimited possibilities. It can also solve the problem of escaping indirectly. Idea

Can I run macros inside QM AutoText? Please see the animated GIF below

If this is possible, I will execute the macro c2s after the AutoText, replacing $cel with $sel  Tongue



Autotext Autotext3
Trigger $t     Help - how to add the trigger to the macro
Code:
Copy      Help
/b/i/c/m
var :sub.Sub2 ;;var


#sub Sub2 m

_s=
F
;,case "$cel_$inp_Name$$"
;,s="$inp_item1$[]$inp_item2$[]$inp_item3$"
;$mac_c2s$
PasteAutoInputDialog(_s)
#20
Macros inside text - no.
#21
@kevin

I solved the escaping problem successfully with a single line of code.  Smile

Function PasteAutoInputDialog add code:
s.findreplace("$cel" "$sel")

This is probably the easiest way


Autotext Autotext3
Trigger $t     Help - how to add the trigger to the macro
Code:
Copy      Help
/b/i/c/m
var :sub.Sub2 ;;var


#sub Sub2 m

_s=
F
;,case "$cel_$inp_Name$$"
;,s="$inp_item1$[]$inp_item2$[]$inp_item3$"
PasteAutoInputDialog(_s)



Function PasteAutoInputDialog
Code:
Copy      Help
;/
function $template

;Calls <help>AutoInputDialog</help> and pastes the text. Also sets caret if need.

;EXAMPLE
;_s=
;F
;;Dear Mr. $inp_Customer$,
;;
;;thank you for contacting us. The price is $$inp_Price$. Let's meet next $inp_Day$.
;;
;;Thanks and best regards,
;;$set_CaretHere$
;;
;;$var_ShortDate$
;;
;PasteAutoInputDialog(_s)


int nLeft
str s=AutoInputDialog(template nLeft)

;Indirectly solve the escaping problem (replace $cel with $sel)
s.findreplace("$cel" "$sel")
spe 10
paste s
if(nLeft) key L(#nLeft)
#22
Cannot call AID_sel while editing in AID_sel. Unless you edit after #ret line.
#23
Thanks for your reminder, I first type var in other macros, then return to AID_sel, the input is successful.  Smile


In the code below, I use AutoText to insert the path for a file or folder in Notepad,

but the Browse Folder dialog is always not at the top,  Causes the acquired path to not be returned to the insertion point

The browse file dialog is always at the top level,  insertion path Is successful
​​​​​​​
why? I did not find the relevant parameters  Huh



Autotext Autotext1
Trigger $t     Help - how to add the trigger to the macro
Code:
Copy      Help
/b/i/c/m
pa :sub.Sub1 ;;open file path
pa :sub.Sub2 ;;open folder path  

#sub Sub1 m

str s
if(!OpenSaveDialog(0 s "Text files[]*.txt[]Image files[]*.bmp;*.gif[]All Files[]*.*[]")) ret
paste s


#sub Sub2 m

str s
if(!BrowseForFolder(s "$desktop$" 4)) ret
paste s
#24
As more and more items in AutoText, I need to manage them,

I need a function to implement it. Below is the schematic. When I press alt+spacebar, it will be displayed. It has no title bar.

This feature can be used under all programs, it can even manage all macros indirectly

My current level of programming is still not reaching the goal. It contains a lot of programming skills that I have never touched before, for example, displaying search results instantly when entering keywords

Although there are a lot of software that can do this, I really want to know how to implement it using QM code. Can you provide an example? thank you very much Heart


Attached Files Image(s)
   
#25
Found in archive.qml
http://www.quickmacros.com/forum/showthr...p?tid=2852
Function Edit_AutoComplete
Code:
Copy      Help
;/
function hEdit $items

;Automatically completes when you type in edit control.
;Call from dialog procedure, on EN_CHANGE. For grid control (edit or combo cell), call on GRID.LVN_QG_CHANGE.

;hEdit - edit control handle.
;items - list of items.

;EXAMPLE
,;case EN_CHANGE<<16|3
,;Edit_AutoComplete lParam "one[]two[]three"


ifk(B) ret
ifk(X) ret

str s1 s2

s1.getwintext(hEdit)
if s1.len
,foreach s2 items
,,if(s2.begi(s1) and s1.len<s2.len)
,,,s2.setwintext(hEdit)
,,,SendMessage hEdit EM_SETSEL s1.len s2.len
,,,break
Function dlg_edit_autocomplete
Code:
Copy      Help
\Dialog_Editor
function# hDlg message wParam lParam
if(hDlg) goto messages

str controls = "3"
str qmg3x
if(!ShowDialog("" &dlg_edit_autocomplete &controls)) ret

;BEGIN DIALOG
;0 "" 0x90C80A48 0x100 0 0 220 132 "Form"
;1 Button 0x54030001 0x4 120 116 48 14 "OK"
;2 Button 0x54030000 0x4 170 116 48 14 "Cancel"
;3 Edit 0x54030080 0x200 2 2 96 14 ""
;4 QM_Grid 0x56031041 0x0 2 18 168 78 "0x0,0,0,0,0x0[]A,,,[]combo,,1,"
;END DIALOG
;DIALOG EDITOR: "" 0x2030208 "" "" ""

ret
;messages
sel message
,case WM_INITDIALOG
,str-- t_data
,t_data="one[]two[]three[]four[]five[]six[]seven[]eight[]nine"
,case WM_DESTROY
,case WM_COMMAND goto messages2
,case WM_NOTIFY goto messages3
ret
;messages2
sel wParam
,case EN_CHANGE<<16|3
,Edit_AutoComplete lParam t_data
,case IDOK
,case IDCANCEL
ret 1

;messages3
NMHDR* nh=+lParam
sel nh.idFrom
,case 4
,GRID.QM_NMLVDATA* cd=+nh
,sel nh.code
,,case GRID.LVN_QG_COMBOFILL ;;when user clicks combo box arrow
,,;out "combo fill: item=%i subitem=%i" cd.item cd.subitem
,,if cd.subitem=1
,,,TO_CBFill cd.hcb t_data
,,
,,case GRID.LVN_QG_CHANGE ;;when user changes grid content
,,;out "text changed: item=%i, subitem=%i, text=%s, newtext=%s" cd.item cd.subitem cd.txt _s.getwintext(cd.hctrl)
,,if cd.hctrl and cd.subitem=1
,,,Edit_AutoComplete cd.hctrl t_data
Function dlg_combo_autocomplete
Code:
Copy      Help
\Dialog_Editor
function# hDlg message wParam lParam
if(hDlg) goto messages

str controls = "3"
str cb3
cb3="&one[]two[]three[]four[]five[]six[]seven[]eight[]nine"
if(!ShowDialog("dlg_combo_autocomplete" &dlg_combo_autocomplete &controls)) ret

;BEGIN DIALOG
;0 "" 0x90C80A48 0x100 0 0 220 132 "Form"
;1 Button 0x54030001 0x4 120 116 48 14 "OK"
;2 Button 0x54030000 0x4 170 116 48 14 "Cancel"
;3 ComboBox 0x54230342 0x0 6 4 96 213 ""
;END DIALOG
;DIALOG EDITOR: "" 0x2010900 "" ""

ret
;messages
sel message
,case WM_INITDIALOG
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case CBN_EDITCHANGE<<16|3
,CB_AutoComplete lParam
,case IDOK
,case IDCANCEL
ret 1
Function CB_AutoComplete
Code:
Copy      Help
;/
function hcb

;Automatically completes when you type in combo box.
;Call from dialog procedure, on CBN_EDITCHANGE.
;hcb - combo box handle (use lParam).

;EXAMPLE
,;case CBN_EDITCHANGE<<16|3
,;CB_AutoComplete lParam


ifk(B) ret
ifk(X) ret

str s ss; int i

s.getwintext(hcb)
if(s.len)
,i=CB_FindItem(hcb s)
,if(i>=0)
,,CB_GetItemText(hcb i ss)
,,if(ss.len>s.len)
,,,ss.setwintext(hcb)
,,,SendMessage(hcb CB_SETEDITSEL 0 ss.len<<16|s.len)
#26
Thank you for your help, I still can't finish this function, some details don't understand Confused

This function is very useful for managing:  macros, or Autotext, and items in Autotext. If developer can add this function to the basic functions of QM, it would be great.  Heart

detailed description :

1. Press the alt+space hotkey first, the search menu will pop up.

2. Then enter the keyword and the search results will be displayed in real time.

3. If the abbreviations is repeatedly defined, the list is displayed and can be selected.

Because I can add the recorded code or macro code to the sub-process of AutoText item, so I think the above functions are much more convenient than creating toolbars, shortcuts, Hotkey, triggers, etc.

It doesn't need to remember what the hotkeys are, nor does it have to do too many settings like creating a toolbar or Set a trigger. Just press alt+spacebar when you need it, then search(
Can see the description of the acronym) and click or enter.

Please see the animated GIF below


Attached Files Image(s)
   


Forum Jump:


Users browsing this thread: 1 Guest(s)