How do i Submit something to a .txt file in a GUI Edit Box? - autohotkey

So I had a question about this AHK Script it's basically an encrypter and decrypter. If you run the program you will need to input a password first and then you get to the real program so if you input a string inside of there and "Encode" it is there any way you can Save the "Encoded" string into a .txt with just a button?
I tried some stuff I found on the Internet with Submit and so but i didn't really figure it out. So I am kinda stuck here!
SetBatchLines -1
StringCaseSense Off
AutoTrim Off
Hotkey, !x, Exit
InputBox, pass ,Encrypter 1.0, Please enter the Password , HIDE, 190, 140
ifEqual pass, pass, GoSub, key
IfNotEqual, pass, pass, MsgBox , 0, Wrong Password, The password was incorrect please try again or press "ESC" to Exit the Programm
IfNotEqual, pass, pass, Reload
Sleep, 100
;----------------Interface--------------
Gui, 1: Add, Edit, x10 y10 w280 r8 vEncDec
Gui, 1: Font, bold
Gui, 1: Add, Text,, Copy and paste your raw text here to encrypt it.
Gui, 1: Color, d80101
Gui, 1: Add, Button, x10 y150 w75 gENCRYPT, Encode
Gui, 1: Add, Button, x10 y178 w75 gDELETE, Delete
Gui, 1: Add, Button, x110 y150 w75 gDECRYPT, Decode
Gui, 1: Add, Button, x110 y178 w75 gOPEN, Save
Gui, 1: Add, Button, x215 y150 w75 gExit, Exit
Gui, 1: Add, Button, x215 y178 w75 gCREATE, Create
Gui, 1: Show, w300 h208, Encrypter v1.0
Return
;------------------MANAGMENT---------------
DELETE:
MsgBox, 262208, WARNING!, If you delete the .txt all your Saved Passwords will be deleted!
Sleep 500
MsgBox, 262196, WARNING!, Do you really want to delete the .txt?
IfMsgBox Yes
FileDelete, %Temp%\ttcrashes.txt
return
CREATE:
MsgBox, 262208, WARNING!, If you create a new .txt your old .txt file may get deleted!
Sleep 500
MsgBox, 262196, WARNING!, Do you really want to create a new .txt?
IfMsgBox Yes
FileAppend,ENCODED:, %Temp%\ttcrashes.txt
return
OPEN:
Run, %Temp%\ttcrashes.txt
return
;-------------------Key--------------------
key:
k1 := 0x5025124 ;in each of these 5 keys edit the last 10 0s to random numbers so that they are each different and look something like this: 0x1928374659
k2 := 0x0681035170
k3 := 0x9704313523
k4 := 0x0427880892
k5 := 0x8754345242
return
;----------------Exit HK--------------------
Exit:
ExitApp
return
;-----------------------------------------------
;#############################################################################################################
ENCRYPT:
encrypt = 1
decrypt = 0
GoSub, EncryptDecrypt
Return
DECRYPT:
decrypt = 1
encrypt = 0
GoSub, EncryptDecrypt
Return
;#############################################################################################################
EncryptDecrypt:
Gui, 1: Submit, NoHide
i = 9
p = 0
L =
Loop % StrLen(EncDec)
{
i++
If i > 8
{
u := p
v := k5
p++
TEA(u,v, k1,k2,k3,k4)
Stream9(u,v)
i = 0
}
StringMid c, EncDec, A_Index, 1
a := Asc(c)
If a between 32 and 126
{
If encrypt = 1
{
a += s%i%
IfGreater a, 126, SetEnv, a, % a-95
c := Chr(a)
}
If decrypt = 1
{
a -= s%i%
IfLess a, 32, SetEnv, a, % a+95
c := Chr(a)
}
}
L = %L%%c%
}
GuiControl,, EncDec, %L%
Return
;#############################################################################################################
TEA(ByRef y,ByRef z,k0,k1,k2,k3) ; (y,z) = 64-bit I/0 block
{ ; (k0,k1,k2,k3) = 128-bit key
IntFormat = %A_FormatInteger%
SetFormat Integer, D ; needed for decimal indices
s := 0
d := 0x9E3779B9
Loop 32
{
k := "k" . s & 3 ; indexing the key
y := 0xFFFFFFFF & (y + ((z << 4 ^ z >> 5) + z ^ s + %k%))
s := 0xFFFFFFFF & (s + d) ; simulate 32 bit operations
k := "k" . s >> 11 & 3
z := 0xFFFFFFFF & (z + ((y << 4 ^ y >> 5) + y ^ s + %k%))
}
SetFormat Integer, %IntFormat%
y += 0
z += 0 ; Convert to original ineger format
}
Stream9(x,y) ; Convert 2 32-bit words to 9 pad values
{ ; 0 <= s0, s1, ... s8 <= 94
Local z ; makes all s%i% global
s0 := Floor(x*0.000000022118911147) ; 95/2**32
Loop 8
{
z := (y << 25) + (x >> 7) & 0xFFFFFFFF
y := (x << 25) + (y >> 7) & 0xFFFFFFFF
x = %z%
s%A_Index% := Floor(x*0.000000022118911147)
}
}
Esc::
ExitApp
return```
Well my expected result would be that if you press the "Save" Button on the GUI you the "Encoded" string gets saved into the .txt

As stated above by Yane, the correct syntax is FileAppend [, Text, Filename, Encoding]
Using one of the below should create/modify the file as intended.
FileAppend,ENCODED: %VariableName%, %Temp%\ttcrashes.txt
or
FileAppend,%VariableName%, %Temp%\ttcrashes.txt

Related

Remap key in Autohotkey but wrong tone mark

I useUnikey program to write Vietnamese, when i try to use autohotkey program to remap key, when writing letters, the tone mark is not displayed correctly, can anyone help.Ex:
1::Send, p
2::Send, o
3::Send, i
4::Send, u
5::Send, y
RESULT: caí, gaí, thaỏ...(wrong)-->cái, gái, thảo...(right)
I use code in this link, it's very well written, but I have to type the space key too much, so I was going to remap some keys to make it easier to type but got this error.
mirror_1 = 6
mirror_2 = 7
mirror_3 = 8
mirror_4 = 9
mirror_5 = 0
mirror_q = 1
mirror_w = 2
mirror_e = 3
mirror_r = 4
mirror_t = 5
mirror_a = `;
mirror_s = l
mirror_d = k
mirror_f = j
mirror_g = h
mirror_z = /
mirror_x = .
mirror_c = ,
mirror_v = m
mirror_b = n
mirror_6 = 5
mirror_7 = 4
mirror_8 = 3
mirror_9 = 2
mirror_0 = 1
mirror_y = 5
mirror_u = 4
mirror_i = 3
mirror_o = 2
mirror_p = 1
mirror_h = g
mirror_j = f
mirror_k = d
mirror_l = s
mirror_n = b
mirror_m = v
return
; This key may help, as the space-on-up may get annoying, especially if you type fast.
Control & Space::Suspend
; These keys are optional, but they may help if you are typing on the left-hand side.
CapsLock::Send, {BackSpace}
Space & CapsLock::Send, {Enter}
; If spacebar didn't modify anything, send a real space keystroke upon release.
space::
Send {space}
return
space & 1::
space & 2::
space & 3::
space & 4::
space & 5::
space & q::
space & w::
space & e::
space & r::
space & t::
space & a::
space & s::
space & d::
space & f::
space & g::
space & z::
space & x::
space & c::
space & v::
space & b::
space & `;::
space & ,::
space & .::
space & /::
space & 6::
space & 7::
space & 8::
space & 9::
space & 0::
space & y::
space & u::
space & i::
space & o::
space & p::
space & h::
space & j::
space & k::
space & l::
space & n::
space & m::
; Determine the mirror key, if there is one:
if A_ThisHotkey = space & `;
MirrorKey = a
else if A_ThisHotkey = space & ,
MirrorKey = c
else if A_ThisHotkey = space & .
MirrorKey = x
else if A_ThisHotkey = space & /
MirrorKey = z
else ; To avoid runtime errors due to invalid var names, do this part last.
{
StringRight, ThisKey, A_ThisHotkey, 1
StringTrimRight, MirrorKey, mirror_%ThisKey%, 0 ; Retrieve "array" element.
if MirrorKey = ; No mirror, script probably needs adjustment.
return
}
Modifiers =
GetKeyState, state1, LWin
GetKeyState, state2, RWin
state = %state1%%state2%
if state <> UU ; At least one Windows key is down.
Modifiers = %Modifiers%#
GetKeyState, state1, Control
if state1 = D
Modifiers = %Modifiers%^
GetKeyState, state1, Alt
if state1 = D
Modifiers = %Modifiers%!
GetKeyState, state1, Shift
if state1 = D
Modifiers = %Modifiers%+
Send %Modifiers%{%MirrorKey%}
return
1::p
2::o
3::i
4::u
5::y
return

How to reset a key sequence with a specific key?

So this sequence resets itself after 1.5 sec (t:=1500) which means if i dont hit the left mouse button for 1.5 sec it always sends A. Otherwise it sends the next letter after each click.
I want to further tweak this code with another function which is to be able to reset the sequence with right mouse button too. So if i hit RButton any time it should reset to A.
Thx.
global s:=0, c:=0, t:=1500
*LButton::
Send % Seqkeys("A","B","C")
KeyWait, LButton
Send, R
return
Seqkeys(params*) {
global s, c, t
max := params.MaxIndex()
(A_TickCount-s<=t && (c+=1)<=max) ? c : c:=1
s := A_TickCount
return params[c]
}
Merely reset the current key index 'c', and the last clicked time 's':
*RButton::
c := 1
s := 0
return
I think your script would benefit with more meaningful variable names:
global lastClickedTime:=0, currentKeyIndex:=0, clickThreshold:=1500
*LButton::
Send % Seqkeys("A","B","C")
KeyWait, LButton
Send, R
return
*RButton::
currentKeyIndex := 1
clickThreshold := 0
return
Seqkeys(params*) {
global lastClickedTime, currentKeyIndex, clickThreshold
max := params.MaxIndex()
currentKeyIndex += 1
if((A_TickCount - lastClickedTime) <= clickThreshold && currentKeyIndex <= max) {
; Do nothing
} else {
currentKeyIndex := 1
}
lastClickedTime := A_TickCount
return params[currentKeyIndex]
}

Why when I run application it just skip some ifs

As I said text that is bolded doesn't work, it just skip it (it worked without those ifs) could you help me? Please, I'm doing that few hours but it still doesn't work. I tried to add this if not in this loop and it worked, please give me a hand, I spent so much time
on it ;(
Gui, Add, CheckBox, x405 y317 w15 h15 vwyrzucaniediax gZapisz,
Gui, Show, h500 w800, Skrypt Na Kopanie
Return
Zapisz:
Gui, Submit , NoHide
return
F8::
WinMove, Minecraft, , , , 1280, 720
sleep 1000
Loop
{
if poziome
{
}
if pionowe
{
}
Checker()
}
Checker()
{
x := 503
y := 385
l := 0
i := 0
Send e
loop, 27{
if(i = 9){
i := 0
l++
}
Sleep 100
MouseMove, x +36*i, y + 36*l
**if wyrzucaniediax // all strong text is just skipped idk why
{
Dropdiax()
}
**
i++
}
Send e
Sleep 50
}
dropdiax(){
diaxcolor := 0x80ĄFFE
color:= getColor()
if(color == diaxcolor){
Send {LCtrl down}
Send q
Sleep 50
Send {LCtrl up}
}
}```
Your wyrzucaniediax variable (maybe you could use better variable names when asking for help?) isn't defined in that function's scope.
To tell the function you're using a variable from outside of its scope, you can use the Global keyword.
Checker()
{
global wyrzucaniediax
x := 503
y := 385
l := 0

AHK Script to send different button with each successive press

Okay so I wrote this script in AHK to press 2 on the first press of the mouse button and 3 on the second and so on, yet it doesnt work. Any ideas why ?
XButton1::Send, 1;
XButton2::
x:=1
if (x = 1){
Send, 2
x+=1
} else if (x = 2) {
Send, 3
x+=1
} else if (x = 3) {
Send, 4
x+=1
} else if (x = 4) {
Send, 5
x = x - 3
}
Everytime you press XButton2, you reset the value of x to 1....x:=1. So it will obviously only send 2. You need to set the value of x outside of XButton2. This will work:
x := 1
XButton2::
x += 1
SendInput, %x%
return

Is it possible for autohotkey to write inside its own script thats running?

I have a script with a list of words inside. I want to create a gui that opens up and allows users to enter words to the list and remove them aswell. Is it possible for the script to edit itself while running? If so, how would I go about doing this. Here is my current script.
Word1 = This
Word2 = Is
Word3 = A
Word4 = Test
Word5 = Script
Word6 = And
Word7 = I
Word8 = Like
Word9 = Apple
Word10 = Pie
Min := 1
Max := 10
Gui, New
Gui, Add, Text,, Please enter a word you wish to add:
Gui, Add, Edit, Word
Gui, Show
MButton::
RandWords := ""
loop,
{
Random N, %Min%, %Max%
if( Last != N )
{
Last := N
break
}
}
RandWords .= Word%N%
Send %RandWords%{!} {enter}
Return
Here is an example how to use arrays to store user input:
store :=
counter := 0
loop, 3
{
InputBox , here , User input , Please enter some text!
store%counter% := here
counter++
}
store1 = This element was deleted!
counter := 0
loop, 3
{
str := store%counter%
MsgBox, %str%
counter++
}
As you can see, store is used as a pseudo array, and is indexed using counter, or integer values.
There is a line that deletes (actually just changes, but you get the idea) the second element. It could have been written like this:
counter := 1
store%counter% = This element was deleted!