Autoit 3 Generic Keypress - keyboard-shortcuts

It seems like there should be a generic keypress listener, something like this:
hotkeysset("listener")
func listener(key)
msgbox(0, "Key", "You pressed " & key)
endfunc
while true
sleep(100)
wend
But short of writing a script that generates the appropriate hotkeyset calls for each key on my keyboard, I can't figure out how to do that. Any thoughts?

Check out this UDF (User-Defined Function), IsPressed_UDF.

Related

How to invoke GUI thread in VB.NET from SignalR Hub

I have a problem concerning following piece of code (C#):
stockTickerHub.On("notify", () =>
Context.Post(delegate
{
mainForm.textBox1.Text += "Notified!\n";
}, null)
);
Above code runs in an async Sub in a VB.NET Module. I am not allowed to access the Text-Property of textBox1. How does the above code look like in VB.NET?
I tried:
myHub.On(Of String, String)("addMessagea", _
Sub(nam, param)
mainForm.textBox1.Text = param.ToString()
Console.WriteLine("Should have append '" + nam.ToString() + param.ToString() + "'")
End Sub)
SignalR is a framework released by Microsoft.
Thanks in advance!
You need to use the Invoke method on the control. It will make sure that the delegate you supply is invoked on the main thread.
This is one of the reasons why WPF is nicer to work with, when you data-bind and NotifyPropertyChanged triggers the framework will fix that for you

Infinite loop that reads stdin in JScript

I'm trying to create an infinite loop to poll for midi input. The loop I have here is technically infinite but I think what's happening is it's getting stuck on the WScript.StdIn.ReadLine() method. It seems that it waits each time for the user to enter something before it continues. I think this because when I enter a character, any midi input in that instance will get routed and the WScript.Echo message will go off.
How can I get it to not wait but check in that instance if there's a character or not? so that the loop doesn't get stopped waiting for input. Is there another ReadLine() method that would work for what I'm looking for?
Here's the code:
while (true) {
str = WScript.StdIn.ReadLine();
if (str == 'q')
break;
// WScript.StdOut.Write("the while loop continues..."
WScript.Echo("the while loop continues...")
msgStr = mox.GetMidiInput()
if (msgStr !== "") {
msgArray = msgStr.split(",")
tStamp = msgArray[0]
port = msgArray[1]
stat = msgArray[2]
data1 = msgArray[3]
data2 = msgArray[4]
mox.OutputMidiMsg( 3, stat, data1, data2);
} else {
continue;
}
}
EDIT:
Right now I just got rid of the ReadLine() because I read on MSDN that it waits for an enter keypress before it returns and I don't think there are any arguments to change that... so I have an infinite loop like I want but I have to resort to ctrl+c to exit it. Anybody have any ideas for a construct that would allow me to quit via the keyboard somehow?
EDIT 2:
I found out that midiox actually provides a method to be polled to exit the script and it works great.

Key input functions for a VB class file

I am working on a little framework and I want to have a class file that contains functions I can run to check if a certain key has been pressed so other events can be run. The only code I have found online for similar things are written into the form itself and use something like "Handles Me.KeyPress". However, this handle function can't be used in a class file.
Public Function OnKeyPress(KeyToCheck As Keys)
If KeyPressed = KeyToCheck then
return true
else
return false
End If
End Function
I have tried:
Public Function OnKeyPress(KeyToCheck As Keys)Handles Formname.Keypress
If KeyPressed = KeyToCheck then
return true
else
return false
End If
End Function
However, this does not work. Any suggestions or work arounds would be greatly appreciated.
To get keyboard input, you need to have a window. All input goes to a window, and that window can then check for key presses that are sent to it.
To get global information, you'd need to install a hook, but those should generally be avoided.

Threading in VB.net

I have a very basic doubt in vb.net threading.
I am having a function MyFunc1() which actually launches a form and asks for input from the user and returns a string. The return must be done only when user clicks a button called 'return' in the Form.
So I framed the function like this.
Public done as Boolean = true
Public str as String
Function MyFunc1() As String
Start Thread1 //launch UI as seperate thread
While done
End While //Infinite loop to hold the parent loop till done is made as false
return str
End Function
Function Thread1
//code to launch UI
End Function
Function onClickReturn //Function triggered when 'return' is pressed
str = EditText.text
done = false
End Function
The problem right now is Thread1 launches the UI but once the UI is launched Thread1 dies and so does the UI Panel.
Any ways to fix this?
I think what you are trying to do doesn't event need threads. Since your blocking the original thread anyways, there is really no need to create a second thread. Typically you just call
MyForm.ShowDialog()
That shows a modal dialog and will block the calling code at that line, allowing the UI to be displayed and used until the user dismisses it.
If you have a .Net thread object, you can block by calling Thread.Join.

Simulate keydown event

How can I simulate a key (ctrl) being hold down while some other code is executed? What would be the implementation of the following method?
self ctrlDownWhile: [self doSomething]
You could try to "trick" the input state, by changing its "ctrlDown" state.
The bad news is that it does not have a setter-method to access it (maybe only in my version), so you may have to get there with a trick:
ctrlDownWhile:aBlock
"aBlock will see ctrlDown as true"
|indexOfCtrlState|
indexOfCtrlState := InputState allInstVarNames indexOf:'ctrlState'.
InputState default instVarAt:indexOfCtrlState put:1.
aBlock
ensure: [
InputState default instVarAt:indexOfCtrlState put:0.
].
an alternative is to create keyPress & keyRelease-events for the CTRL-key, and enqueue them into the WindowSensor, before and after the block's evaluation.