Reputation: 85
I want to bind some variable textcontent to an specific key (example on key p)
For example:
First press on p: "hannes1"
second press on p: "hannes2"
third press on p: "hannes3"
And so on. Thanks for any help.
Upvotes: -1
Views: 43
Reputation: 56208
It isn't clear from your question if you want a fixed string hannes
with a counter or "the next string from a list", so I added both options (available via p
and P
; Global $aVars[3] = ["hannes1", "hannes2", "hannes3"]
HotKeySet("p", "_SendVarArray")
HotKeySet("P", "_sendvarCount")
While True
Sleep(25)
WEnd
Func _SendVarArray() ; write strings from an array; rotating
Local $aVars[3] = ["One", "Two", "Three"] ; define EITHER here as Local OR in main program as Global
Local Static $x = UBound($aVars) - 1 ; initial value for next line to be changed as start value '0'
$x = Mod($x + 1, UBound($aVars))
Send($aVars[$x])
EndFunc ;==>_SendVarArray
Func _SendVarCount()
Local Static $x = 0 ; 'Static' to remember value with next execution
$x += 1
Send("hannes" & $x)
EndFunc ;==>_SendVarCount
NOTE: an ordinary letter is a bad choice for a hotkey, because if a string you send()
contains that letter, it will activate the hotkey function too (I kept it anyway, leaving it to you to find a better key(combination)).
The advantage of HotKeySet()
is that your program can do other things while waiting for the hotkey being pressed.
Upvotes: 1
Reputation: 2151
Try this: Change the ConsoleWrite to Send if you want to send the keys to any application.
#include <Misc.au3>
#include <MsgBoxConstants.au3>
Local $hDLL = DllOpen("user32.dll")
Local $counter = 0
While 1
If _IsPressed("50", $hDLL) Then
; Wait until key is released.
While _IsPressed("50", $hDLL)
Sleep(25)
WEnd
ConsoleWrite("Hannes" & $counter & @CRLF)
$counter +=1
ElseIf _IsPressed("1B", $hDLL) Then
MsgBox($MB_SYSTEMMODAL, "_IsPressed", "The Esc Key was pressed, therefore we will close the application.")
ExitLoop
EndIf
Sleep(25)
WEnd
DllClose($hDLL)
Upvotes: 1