Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
output key's pressed at beginning of script
#1
Is there a way to output what key is pressed at the beginning of a macro/function.
Including the modifiers and working in compiled to .exe

For example:
Macro/function is compiled to .exe. User presses [CTRL]+[SHIFT]+[ALT]+[WIN] when double clicking the compiled exe and then the VK value of the pressed keys will be output.
I can then use that value to apply "FormatKeyString" to make it human readable or do other actions based on the VK value.

The closest things are (of what I know)
- ifk
- if((GetMod&2)&&(GetMod&1)) .... to check if CTRL and SHIFT is pressed

But they are not the best way to approach this (I think).
Chances are big that this has been covered in a forum thread but I couldn't find it.
#2
OS has 2 functions to get logical key pressed state: GetKeyState and GetAsyncKeyState. Both have different advantages and disadvantages. Also there is GetKeyboardState, gets states of all keys and works like GetKeyState. And no functions to get physical state.

QM function RealGetKeyState uses GetKeyState or GetAsyncKeyState depending on key, and also does workarounds for some problems. QM function ifk is the same but uses QM key codes instead of virtual-key codes, eg S instead of VK_SHIFT. QM function GetMod gets states of 4 modifier keys, and is used like if(GetMod&3=3) .... to check if CTRL and SHIFT is pressed .

To get state of non-modifier keys at thread startup, it's better to use GetAsyncKeyState or QM functions.
Code:
Copy      Help
out F"GetKeyState: Shift={GetKeyState(VK_SHIFT)&0x8000!=0}, K={GetKeyState('K')&0x8000!=0}" ;;problem: does not see K if pressed before starting this thread
out F"GetAsyncKeyState: Shift={GetAsyncKeyState(VK_SHIFT)&0x8000!=0}, K={GetAsyncKeyState('K')&0x8000!=0}" ;;problem: does not see any keys if the foreground window is admin and we not. Other functions at least work with modifier keys.
out F"RealGetKeyState: Shift={RealGetKeyState(VK_SHIFT)}, K={RealGetKeyState('K')}"
out F"ifk: Shift={ifk(S)}, K={ifk(k)}"
#3
Thank you!!!
I can work with this!


Forum Jump:


Users browsing this thread: 1 Guest(s)