How to read register value using ahk - autohotkey

I used readprocessmemory for get value of address. but it is not read register value.
How to read or write register value using autohotkey?

You can use classMemory from this repo for that.
here's a usage example:
#Include classMemory.ahk
vlc := new _ClassMemory("ahk_exe vlc.exe")
address = % "0x0425A584" ; get the address from Cheat Engine and paste it here
msgbox, % vlc.read(address) ; read volume
vlc.Write(address, 10) ; write
msgbox, % vlc.read(address) ; read again

Related

"Send %variable%" evals my variable before sending it

I have an autohotkey script(A) that write another script(B).
The important line in my script(A):
InputBox variable, Variable
Send %variable%
Then, if i input:
helloworld{enter}
it will write "helloworld" and insert a new line in my script(B) instead of just writing "{enter}"
How do I force it to write %variable% without interpreting it beforehand ?
I agree with the other answer that using FileAppend would be a better method. However, if you truly want to accomplish this using the send command, then you need to use {raw} mode. You can read about {raw} in the documentation:
https://autohotkey.com/docs/commands/Send.htm
InputBox variable, Variable
Send, {raw}%variable%
The simplest way to write another script (scriptB) from scriptA is to use FileAppend:
variable = helloworld
FileAppend,
(
; a line of code
Send %variable%{enter}
; another line of code
)
,C:\scriptB.ahk
Run, edit "C:\scriptB.ahk"
; or:
; Run, C:\scriptB.ahk
or
InputBox variable, Variable, Enter a variable:
if not ErrorLevel
{
FileAppend,
(
; a line of code
Send %variable%{enter}
; another line of code
)
,C:\scriptB.ahk
Run, edit "C:\scriptB.ahk"
; or:
; Run C:\scriptB.ahk
}
return

AHK Load hotstrings without using #Include Subroutines.ahk

I have a txt file named subroutines.ahk in it is the below hotstring.
::btw::Thank you for the help
I know if I want to run my hotstring from another script all I have to do is include it in that script using:
#include subroutines.ahk
But I dont want to do that Instead from another script I want to Loop read the contents of subroutines.ahk and load the hotstring variables that way .
Loop, read,subroutines.ahk
{
Loop, parse, A_LoopReadLine, %A_Tab%
{
MsgBox, Field number %A_Index% is %A_LoopField%.
}
}
I would really appreciate your help on how I can load my hotstring variables into another script that way.
I plan to encode the hotsrings in subroutines.ahk and than decode the contents of the subroutines.ahk in the second program and load it into memory.
In the above example though i am first trying to figure out how I can loop read the txt file and run the hot strings from there.
Demonstrates the use of hotkeys that map to dynamic values
; Replace hash values with whatever method you use to decrypt your hotstrings
decrypted := {abc: "alpha", def: "beta"}
::abc::
Send % decrypted["abc"]
return
::def::
Send % decrypted["def"]
return
When you type "abc", "alpha" appears instead
# directives are processed only once when the script is launched. To work around this limitation, you can use reload to execute dynamically generated script that includes # directives.
Code sample:
When F1 is pressed, use the contents of "subroutines.ahk" to generate and run code that utilizes # directives:
F1:: reload_hotstrings()
#Include temp.ahk
reload_hotstrings()
{
FileDelete temp.ahk
loop read, subroutines.ahk
{
MsgBox Hotstring number %A_Index% is %A_LoopReadLine%.
FileAppend %A_LoopReadLine%`n, temp.ahk
}
reload
}
Alternatively, if you want to automatically generate hotkeys code whenever autohotkey starts:
I'm using source.dat for your subroutines.ahk file
Code sample:
FileGetTime source_time, source.dat
FileGetTime compiled_time, compiled.ahk
; calculate time difference between source and compiled files
EnvSub source_time, %compiled_time%, Seconds
; compile and run if source newer
if source_time > 0
{
FileDelete compiled.ahk
loop read, source.dat
{
FileAppend %A_LoopReadLine%`n, compiled.ahk
}
reload
}
#Include compiled.ahk

How to read a number from text file via Matlab

I have 1000 text files and want to read a number from each file.
format of text file as:
af;laskjdf;lkasjda123241234123
$sakdfja;lskfj12352135qadsfasfa
falskdfjqwr1351
##alskgja;lksjgklajs23523,
asdfa#####1217653asl123654fjaksj
asdkjf23s#q23asjfklj
asko3
I need to read the number ("1217653") behind "#####" in each txt file.
The number will follow the "#####" closely in all text file.
"#####" and the close following number just appear one time in each file.
clc
clear
MyFolderInfo = dir('yourpath/folder');
fidin = fopen(file_name,'r','n','utf-8');
while ~feof(fidin)
tline=fgetl(fidin);
disp(tline)
end
fclose(fidin);
It is not finish yet. I am stuck with the problem that it can not read after the space line.
This is another approach using the function regex. This will easily provide a more advanced way of reading files and does not require reading the full file in one go. The difference from the already given example is basically that I read the file line-by-line, but since the example use this approach I believe it is worth answering. This will return all occurences of "#####NUMBER"
function test()
h = fopen('myfile.txt');
str = fgetl(h);
k = 1;
while (isempty(str) | str ~= -1 ) % Empty line returns empty string and EOF returns -1
res{k} = regexp(str,'#####\d+','match');
k = k+1;
str = fgetl(h);
end
for k=1:length(res)
disp(res{k});
end
EDIT
Using the expression '#####(\d+)' and the argument 'tokens' instead of 'match' Will actually return the digits after the "#####" as a string. The intent with this post was also, apart from showing another way to read the file, to show how to use regexp with a simple example. Both alternatives can be used with suitable conversion.
Assuming the following:
All files are ASCII files.
The number you are looking to extract is directly following #####.
The number you are looking for is a natural number.
##### followed by a number only occurs once per file.
You can use this code snippet inside a for loop to extract each number:
regx='#####(\d+)';
str=fileread(fileName);
num=str2double(regexp(str,regx,'tokens','once'));
Example of for loop
This code will iterate through ALL files in yourpath/folder and save the numbers into num.
regx='#####(\d+)'; % Create regex
folderDir='yourpath/folder';
files=cellstr(ls(folderDir)); % Find all files in folderDir
files=files(3:end); % remove . and ..
num=zeros(1,length(files)); % Pre allocate
for i=1:length(files) % Iterate through files
str=fileread(fullfile(folderDir,files{i})); % Extract str from file
num(i)=str2double(regexp(str,regx,'tokens','once')); % extract number using regex
end
If you want to extract more ''advanced'' numbers e.g. Integers or Real numbers, or handle several occurrences of #####NUMBER in a file you will need to update your question with a better representation of your text files.

Wait while variable does not exist MATLAB

I need to suspend the program until the variable is created. I point to the data file, then open uiimport to specify the range of data. And at this moment I have to suspend the program until the variable is created.
%find file
[FileName,PathName] = uigetfile({'*.xls;*.xlsx', 'Excel files(*.xls, *.xlsx)'},'Укажите Excel-файл с данными');
%open import wizard
uiimport(strcat(PathName, FileName));
% here i need to suspend the program until the variable is created
You must specify an output variable when calling uiimport. If you do this, no lines after your call to uiimport will be executed until uiimport has completed (the user has chosen data to import or not).
data = uiimport(fullfile(PathName, FileName));
% Do stuff with data
disp(data.value)
If for some reason, you did need to wait until a variable existed, you could use a while loop combined with exist, but in general this is a marker of poor program design.
while ~exist('variablename', 'var')
% Do something that may define the variable
end
Update
If you're simply reading an excel file, it is likely easier to use xlsread to do so:
data = xlsread(filename, -1);

Displaying List of AutoHotkey Hotkeys

I’ve written script that contains numerous hotkeys (general structure is as below). I would like to create another one that when pressed displays a list of all of the hotkeys and their corresponding descriptions that the script contains in a nice, formatted table.
The formatting and display are tenuous since AutoHotkey’s output is limited to message-boxes, but possible. More problematic is getting the hotkeys and corresponding descriptions.
The hotkeys all call the same function with different arguments. I considered adding a variable to the function so that depending on the value, the function either performs the normal function when triggered by the normal hotkeys, or builds a string or something when triggered from the special display hotkey.
I cannot figure out a way to programmatically access the script’s hotkeys at all. I checked the docs and there don’t seem to be any A_ variables that can be used for this purpose, nor does the Hotkey command lend itself well (it can be used to test if a hotkey exists, but looping through the innumerable combinations is, at best, tedious).
Failed attempts:
I tried using Elliot’s suggestion of parsing the script itself (replacing the path with %A_ScriptFullPath%, and while it does work for a raw script, it does not when the script is compiled
I tried assigning the entire hotkey section of the script to a variable as a continuation section and then parsing the variable and creating hotkeys using the Hotkey command. This worked well right up until the last part because the Hotkey command cannot take arbitrary commands as the destination and requires existing labels.
The ListHotkeys command is not applicable because it only displays the hotkeys as plain text in the control window.
Does anyone know how I can display a list of the hotkeys and either their corresponding arguments or comments?
Example script:
SomeFunc(foobar)
{
MsgBox %foobar%
}
!^#A::SomeFunc("a") ; blah
^+NumpadMult::SomeFunc("c") ; blivet
^+!#`::SomeFunc("b") ; baz
^#Space::SomeFunc("d") ; ermahgerd
…
Example desired “outputs”:
C+A+ W+ A a | C+ S+ NumpadMult b
------------------+----------------------
C+A+S+W+ ` c | C+ W+ Space d
    or
Ctrl Alt Shift Win Key Action
-----------------------------------------
× × × A blah
× × NumpadMult baz
× × × × ` blivet
× × Space ermahgerd
etc.
The only thing I can think of is to read each line of your script individually and parse it. This code reads your script (script.ahk) one line at a time and parses it. This should get you started. Additionally, you could parse the line to check for the modifiers as well.
Loop
{
FileReadLine, line, C:\script.ahk, %A_Index%
if ErrorLevel
break
If Instr(line, "::")
{
StringSplit, linearray, line, ::,
key := linearray1
StringSplit, commandarray, linearray3, `;
action := commandarray2
hotkeyline := "key: " . key . "`tAction: " . action
final .= hotkeyline . "`r"
}
}
msgbox % final
return
I found a solution. It is not perfect (or ideal), and hopefully a proper, built-in method will become available in the future, but it works well (enough) and for raw and compiled scripts.
What I did was to use the FileInstall command which tells the compiler to add a file to the executable (and extract it when run).
Sadly, the FileInstall command will not allow the use of variables for the source file, so I cannot simply include the script itself (FileInstall, %A_ScriptFullPath%, %A_Temp%\%A_ScriptName%, 1).
As a work-around, I ended up extracting all of the desired hotkeys to a second file which I then parse as Elliot suggested, then delete, and #Include at the end of my script (it must be at the end since hotkeys will terminate the autoexecute section).
;;;;; Test.ahk ;;;;;
; Add hotkey file to executable and extract to Temp directory at runtime
FileInstall, Hotkeys.ahk, %A_Temp%\Hotkeys.ahk, 1
Loop
{
;Read a line from the extracted hotkey script and quit if error
FileReadLine, line, %A_Temp%\Hotkeys.ahk, %A_Index%
if ErrorLevel
break
;Trim whitespace
line=%line%
; Parse the line as in Elliot’s answer, but with tweaks as necessary
ParseHotkey(line)
…
}
FileDelete, %A_Temp%\Hotkeys.ahk ; Delete the extracted script
DisplayHotkeys() ; I ended up bulding and using a GUI instead
#Include, Hotkeys.ahk ; It is included at compile-time, so no A_Temp
;;;;; Hotkeys.ahk ;;;;;
z::MsgBox foo
y::MsgBox bar