Inserir automaticamente pontos, e vírgula, ao digitar números

Tire suas dúvidas sobre programação em AutoHotkey

Moderator: Gio

rubbioli
Posts: 36
Joined: 14 Sep 2019, 17:55

Inserir automaticamente pontos, e vírgula, ao digitar números

Post by rubbioli » 30 Aug 2023, 11:38

Boa tarde!
Comprei um teclado que não tem o botao "." no teclado numérico e queria saber se é possível criar uma regra para inserir pontos, e vírgulas, no seguinte formato: "1.234.567,89" quando eu digitar 123456789 (ou qualquer número para o formato brasileiro).
Desde já, obrigado!!!
garry
Posts: 3795
Joined: 22 Dec 2013, 12:50

Re: Inserir automaticamente pontos, e vírgula, ao digitar números

Post by garry » 30 Aug 2023, 14:46

converter

Code: Select all

x:="123456789"
l:=SubStr(x,-1)
StringTrimRight,x,x,2
n:= ThousandsSep(x)
t:=n . "," . l
MsgBox,%t%          ;- 1.234.567,89

ThousandsSep(x, s=".") {
   return RegExReplace(x, "\G\d+?(?=(\d{3})+(?:\D|$))", "$0" s)
}
rubbioli
Posts: 36
Joined: 14 Sep 2019, 17:55

Re: Inserir automaticamente pontos, e vírgula, ao digitar números

Post by rubbioli » 31 Aug 2023, 14:10

garry wrote:
30 Aug 2023, 14:46
converter

Code: Select all

x:="123456789"
l:=SubStr(x,-1)
StringTrimRight,x,x,2
n:= ThousandsSep(x)
t:=n . "," . l
MsgBox,%t%          ;- 1.234.567,89

ThousandsSep(x, s=".") {
   return RegExReplace(x, "\G\d+?(?=(\d{3})+(?:\D|$))", "$0" s)
}

Unfortunately, it didn't work! Could it be because of the version I use (Version 1.0.48.05)?
I simply type de nubers and send an enter?
I really need this!
tks!
garry
Posts: 3795
Joined: 22 Dec 2013, 12:50

Re: Inserir automaticamente pontos, e vírgula, ao digitar números

Post by garry » 01 Sep 2023, 08:33

Download > ;-- version 1 ... https://www.autohotkey.com/download/ last version is 1.1.37.01 20230901

2 exemplos

enviar para o bloco de notas

Code: Select all

;-- version 1 ... https://www.autohotkey.com/download/   last version is 1.1.37.01   20230901
;-
;--- use F8 -------------------
#Requires AutoHotkey v1.1
#Warn
#Singleinstance,force
SetKeyDelay, 80, 10
run,notepad                 ;- abra o bloco de notas para teste  /  então use F8
#If WinActive("ahk_exe notepad.exe")
return
;-------------
~$F8::
InputBox,x,enviar para o bloco de notas,escrever dígitos ...,, 225, 125,400,100,Locale,,123456789
clipboard=
l:=SubStr(x,-1)
StringTrimRight,x,x,2
n:= ThousandsSep(x)
t:=n . "," . l
If !ErrorLevel && x != "" {
 clipboard=%t%
 send,^v`n
 }
#if
return
;-------------
ThousandsSep(x, s=".") {
   return RegExReplace(x, "\G\d+?(?=(\d{3})+(?:\D|$))", "$0" s)
}
;------------
esc::exitapp
;===========================

escrever no arquivo

Code: Select all

;- use F9 to run ...
#Requires AutoHotkey v1.1
#Warn
#Singleinstance,force
Filename :="digits.txt"
dir1:= a_desktop . "\My Digits Folder"
F1:= dir1 . "\" . filename
ifnotexist,%dir1%
 FileCreateDir % dir1
return
;-------------
~$F9::
InputBox,x,escrever no arquivo,escrever dígitos ...,, 225, 125,400,100,Locale,,123456789
l:=SubStr(x,-1)
StringTrimRight,x,x,2
n:= ThousandsSep(x)
t:=n . "," . l
If !ErrorLevel && x != "" {
 RunWait, %Comspec% /U /C echo %t%>>"%f1%"
 try,
   run,%F1%
}
return
;-------------
ThousandsSep(x, s=".") {
   return RegExReplace(x, "\G\d+?(?=(\d{3})+(?:\D|$))", "$0" s)
}
--------------
esc::exitapp
;=============
Post Reply

Return to “Ajuda e Suporte Geral”