Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
string to keycode (keypress)
#1
Sorry for this really simple question, but I couldn't find it in the help section 'key'
If I put ALT + F8 in a string "AF8" how do I translate it to a hotkey press (which also works in compiled exe).

Function Function12
Code:
Copy      Help
str s="AF8" ;; [ALT] + [F8]

key s
key (s)
key(s)
key(F"{s}")
key (F"{s}")

;; ... ?


The goal is to use it in a dialog where the user can input a key press combination in an inputfield.
Examples:
AF8, = ALT+F8
CSF2 = CTRL+SHIFT+F2
...etc...
#2
QM2 can't do it very easily.
To convert simple strings to virtual-key codes, can be used function QmKeyCodeToVK. Then function SendInput.
Or use C# SendKeys. But its keys syntax is different. Reference.

Function CSharpSendKeys
Code:
Copy      Help
;/
function $keys

;Sends keys specified in string.
;Calls .NET function SendKeys.SendWait.
;Syntax reference: <google>C# SendKeys.Send</google>.

;EXAMPLE
;CSharpSendKeys "^a" ;;Ctrl+A


opt noerrorshere 1
CsScript x.AddCode("")
x.Call("Class1.Key" keys)


#ret
//C# code
using System;
using System.Windows.Forms;

public class Class1
{
public static void Key(string keys)
{
,SendKeys.SendWait(keys);
}
}
#3
Ok! Thank you!!!


Forum Jump:


Users browsing this thread: 1 Guest(s)