I would like to turn F15 into a macro key. Pressing another key while F15 is held should call a function that will read a .ini file for instructions.
I know that I can it this like this, but I'd rather not have the giant list:
DoMacro(key) { ... }
F15 & a::DoMacro('a')
F15 & b::DoMacro('b')
F15 & c::DoMacro('c')
.
.
.
I tried fiddling around with Input, but I couldn't figure out any way to capture (or even pass through) non-character keys. Is there any alternative to the long list?
Unfortunately there is no 100% nice way to do this in AHK (unless you know a way to do it through API calls which I don't).
I think the best you could make out of this situation is this:
GetAnyKey(timeout) {
Input, PressedKey, T%timeout% L1, {F1}{F2}{F3}{F4}{F5}{F6}{F7}{F8}{F9}{F10}{F11}{F12}{F14}{F15}{F16}{F17}{F18}{F19}{F20}{F21}{F22}{F23}{F24}{PrintScreen}{Del}{Home}{End}{PgUp}{PgDn}{ScrollLock}{Pause}{Ins}{BS}{Space}{Left}{Right}{Up}{Down}{Left}{Right}{NumLock}{NumPad1}{NumPad2}{NumPad3}{NumPad4}{NumPad5}{NumPad6}{NumPad7}{NumPad8}{NumPad9}{NumPad0}{NumPadAdd}{NumPadSub}{NumPadMult}{NumPadDiv}{NumPadEnter}{NumPadDot}{NumPadEnd}{NumPadHome}{NumPadPgDn}{NumPadPgUp}{NumpadClear}{NumpadDown}{NumpadIns}{NumpadLeft}{NumpadRight}{AppsKey}{LShift}{RShift}{LCtrl}{RCtrl}{LAlt}{RAlt}{LWin}{RWin}
If (ErrorLevel = "Timeout")
Return
If PressedKey
Key := PressedKey
Else
Key := SubStr(ErrorLevel,8)
Return Key
}
F13::
Key := GetAnyKey(1)
If (Key && GetKeyState("F13", "P")) {
DoMacro(Key)
}
Return
DoMacro(Key) {
MsgBox, F13 and %Key% have been pressed!
}
I removed the hotkey (F13) from the Input key list, so that it doesn't trigger the Input when you wait too long.
So, if you change the hotkey you have to change the input list accordingly.
Related
I have a very simple AutoHotKey script which I wish to introduce a visible delay between the characters typed ...I have read the documentation on SetKeyDelay but the example below does not seem to provide any key delay ...any thoughts ? I would expect that when I type rpa and the hit enter key, the characters would type slowly ...more like a human typing.
SetKeyDelay ,3000,200
::rpa::
Send {Text}
(
while ( iterator?.hasNext() ) {
def comp = iterator.next()
if (comp.sku != null ) {
def row = [
"sku" : comp.sku,
"ProductGroup": comp.attribute1,
"BusinessUnit": comp.attribute2
]
}
}
)
return
When a new script is created the SendMode Input; line is automatically inserted.
Remove the SendMode Input; fixed the issue.
I'm new to AutoHotKey and I wanted to create a script macro for a flash game but when I run it, it creates an error.
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
condChecker := false
state := true
Mine()
{
Sleep, rand(10,80)
Send, {Space}
while(state = true)
{
PixelGetColor, gemColor, 982, 433
if(gemColor = B93557)
{
state := true
{
else(gemColor = 96885A)
{
state := false
}
Sleep, rand(90,120)
}
}
^-::
loop 10000
{
getState()
if(state = true)
{Mine()}
else
{Sleep, rand(70,150)}
}
When I press Run Script on the ahk file, a menu pops up saying
Error at line 20.
Line Text else(gemColor = 96885A)
Error: Functions cannot contain functions.
The program will now exit.
I don't know where to start with this error and I read up on other forums saying that my formatting was incorrect.
A couple of various things:
The curly brace after state := true should be the other way (}, not {)
There is no default rand function in AHK, you are probably either looking for Random, or you have a custom function called rand that you is not shown in your question. In any case, I'll write a function rand(a,b) that will return an integer value between a and b
rand(a, b)
{
Random, rand, a, b
return rand
}
Additionally, there is another function getState() that is being invoked inside the loop 10000. I'm not sure what it is supposed to do (or if you meant something like GetKeyState instead), but I'll assume that you have that covered on your end.
As #Pranav Hosangadi mentioned, you likely wanted an else if statement instead of just an else statement on this line: else(gemColor = 96885A)
Are you sure you want SendMode Input? Although it does have superior speed than standard Send, its use is normally limited to typing text in a text box. It seems that you are trying to send a keystroke to a flash game, so you might want to check whether that functioning as you intend it to.
When writing a end curly brace (}) to conclude an if() or else() clause, you need to put it on its own line. (i.e. change
if(state = true)
{Mine()}
else
{Sleep, rand(70,150)}
to something like
if(state = true)
{
Mine()
}
else
{
Sleep, rand(70,150)
}
or even (since the if and else statements here only trigger one line of code each)
if(state = true)
Mine()
else
Sleep, rand(70,150)
So, that was a bit long, but here is the final code:
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
; ---> Double check this! ---> SendMode Input
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
condChecker := false
state := true
Mine()
{
Sleep, rand(10,80)
Send, {Space}
while(state = true)
{
PixelGetColor, gemColor, 982, 433
if(gemColor = B93557)
{
state := true
}
else if(gemColor = 96885A)
{
state := false
}
Sleep, rand(90,120)
}
}
rand(a, b)
{
Random, rand, a, b
return rand
}
^-::
loop 10000
{
;getState()
if(state = true)
Mine()
else
Sleep, rand(70,150)
}
lmk if something doesn't work properly, and I'll try to update this response
I added my scraping code below, I would in theory, start on a page with 25 values for me to pull, and appends the way I want it too.
Some pages have less than 25 and gives me error's and blank lines on my .txt. Can smarter minds help me clean this up?
Here is the scraping code for me to use for another area that is working fine.
F3::Loop_Scrape()
Loop_Scrape() {
If ErrorLevel
return
else
prop_1=,prop_2=,prop_3=,prop_4=,prop_5=,prop_6=,prop_7=,prop_8=,prop_9=,prop_10=,prop_11=,prop_12=,prop_13=,prop_14=,prop_15=,prop_16=,prop_17=,prop_18=,prop_19=,prop_20=,prop_21=,prop_22=,prop_23=,prop_24=,prop_25=
Sleep,150
IfWinExist,ahk_class IEFrame
{
pwb:=WBGet()
WinActivate
}
Sleep,350
prop_1:=pwb.document.GetElementsByTagName("TD")[1].innerText
prop_2:=pwb.document.GetElementsByTagName("TD")[12].innerText
prop_3:=pwb.document.GetElementsByTagName("TD")[23].innerText
prop_4:=pwb.document.GetElementsByTagName("TD")[34].innerText
prop_5:=pwb.document.GetElementsByTagName("TD")[45].innerText
prop_6:=pwb.document.GetElementsByTagName("TD")[56].innerText
prop_7:=pwb.document.GetElementsByTagName("TD")[67].innerText
prop_8:=pwb.document.GetElementsByTagName("TD")[78].innerText
prop_9:=pwb.document.GetElementsByTagName("TD")[89].innerText
prop_10:=pwb.document.GetElementsByTagName("TD")[100].innerText
prop_11:=pwb.document.GetElementsByTagName("TD")[111].innerText
prop_12:=pwb.document.GetElementsByTagName("TD")[122].innerText
prop_13:=pwb.document.GetElementsByTagName("TD")[133].innerText
prop_14:=pwb.document.GetElementsByTagName("TD")[144].innerText
prop_15:=pwb.document.GetElementsByTagName("TD")[155].innerText
prop_16:=pwb.document.GetElementsByTagName("TD")[166].innerText
prop_17:=pwb.document.GetElementsByTagName("TD")[177].innerText
prop_18:=pwb.document.GetElementsByTagName("TD")[188].innerText
prop_19:=pwb.document.GetElementsByTagName("TD")[199].innerText
prop_20:=pwb.document.GetElementsByTagName("TD")[210].innerText
prop_21:=pwb.document.GetElementsByTagName("TD")[221].innerText
prop_22:=pwb.document.GetElementsByTagName("TD")[232].innerText
prop_23:=pwb.document.GetElementsByTagName("TD")[243].innerText
prop_24:=pwb.document.GetElementsByTagName("TD")[254].innerText
prop_25:=pwb.document.GetElementsByTagName("TD")[265].innerText
Sleep,350
FileAppend,%prop_1%`n%prop_2%`n%prop_3%`n%prop_4%`n%prop_5%`n%prop_6%`n%prop_7%`n%prop_8%`n%prop_9%`n%prop_10%`n%prop_11%`n%prop_12%`n%prop_13%`n%prop_14%`n%prop_15%`n%prop_16%`n%prop_17%`n%prop_18%`n%prop_19%`n%prop_20%`n%prop_21%`n%prop_22%`n%prop_23%`n%prop_24%`n%prop_25%`n,Docs/MyFile2.txt
return
}
dude you should try creating a dict
here's my python version of what you should do hope it helps
props = {}#Create dictionary
index = 1 #index of the elements
for i in range(1,26): #goes from 1-25
#getting the element and put it in the dictionary
props['prop'+str(i)] = pwb.document.GetElementsByTagName("TD")[index].innerText
#incrementing the index
index +=11
for key, value in props.iteritems():
if value != "":
file.append(value)
sorry i dont know c++ i just saw your question but if you get the idea you can make it
I am trying to read a INI file and get the values from it using AHK. However, the read is not successful and I am getting the default value from the call every time.
Here is the code I used :-
ReadIniFile(IniFileName, SectionName, KeyName,ByRef Value)
{
If FileExist(IniFileName)
{
MsgBox File found ; this comes
}
IniRead, Value, IniFileName, SectionName, KeyName , Default
MsgBox %Value% %IniFileName% %KeyName% %SectionName% ; Value comes as 'Default'
}
The output is :-
Default C:\Users\barmans\Desktop\ECU.h ININame GeneralSettings
The function call is :
ReadIniFile(HeaderFileName, "GeneralSettings", "ININame", AutoTestScript)
The INI is in format :-
[GeneralSettings]
ECU=ABS8_B
ININame=ABS8_B_Test.ini
KBDiagPath=C:\KBApps\Knorr-Bremse\KB Diag
RunCount=0
[LogSettings]
LogFileName=ABS8_B_Report.log
TraceLevel=1
Any guidance is appreciated.
As you did in MsgBox, you have to enclose your variables with % percent signs.
If the documentation tells you to state a "name", "value" or anything like that, you'll need an actual string or integer. Other than that, sometimes you're asked to state a "variable name", in which case you obviously must not use % - as in function calls.
So, your iniread will look like:
IniRead, Value, %IniFileName%, %SectionName%, %KeyName%, Default
for more detailed information, visit http://ahkscript.org/docs/Variables.htm. Tho I do not see anything about the use of variables in command there
I have a Map function in MongoDB which I'm later using Reduce on. I use a collection which has a bunch of users in it and users own some channels. However, there are users that do not have any channels and the Map/Reduce function raises an error in my script.
map = Code("function () {"
" if(!this.channels) continue;"
" this.channels.forEach(function(z) {"
" emit(z, 1);"
" });"
"}")
When I use return instead of continue to quit the function it works flawlessly except that I don't want to end the loop. Is there any smart way around this?
Thanks for your advice and better widsom.
If you return from map, it returns only from map for this document. Maps for other documents will be executed regardless of that.
I suggest rewriting your map to this form
function () {
if(this.channels) {
this.channels.forEach(function(z) {
emit(z, 1);
});
}
}
I think, this form is more clear. It will emit something for users that have channels, and skip those that don't have any.