Jump to content

Recommended Posts

Posted (edited)

This simple dllcall gives me error 5, access denied,

Func _WinAPI_VkKeyScan($__key)
    _WinAPI_SetLastError(0)
    $res = DllCall('User32.dll', 'SHORT', 'VkKeyScan', 'CHAR', $__key)
    _xConsole('res: '&$res)
    $_LastErr = _WinAPI_GetLastError()
    If $_LastErr <> 0 Then _xConsole('Err: {' & $_LastErr & '}> ' & _WinAPI_GetLastErrorMessage())
    Return $res
EndFunc

Am i doing something wrong?

Also tried VkKeyScanA and W

Edit:

I want to send `:` via PostMessage() WM_KEYDOWN

Edited by xYuri
Missing Info
Posted

@KaFu Thank you very much for your answer,

Sorry that i forgot to include this in my question,

But it still not doing what i really wanted, in first place i used `VkKeyScan` to get the shift+ code for `;` which makes it `:`, 

Now even after using ProgAndy's code it still send `;` , which i can get from https://docs.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes,

 

Also `GetLastError()` still gives error code 5, which is weird cuz it give a VKCode to a key.

Screenshot_1.png

Posted (edited)

@Nine Yes i am aware of that, and i am sending to the right control as it show ;;;; in notepad i think?

Anyway here is the code,

Func _WinAPI_VkKeyScanW($__key)
    _WinAPI_SetLastError(0)
    $res = DllCall('User32.dll', 'SHORT', 'VkKeyScanW', 'USHORT', AscW($__key))
    _xConsole('res: ' & $res[0])
    $_LastErr = _WinAPI_GetLastError()
    If @error Then _xConsole('Err: {' & @error & '}> ' & _WinAPI_GetLastErrorMessage())
    Return SetExtended(BitShift($res[0], 8), BitAnd($res[0], 0xFF))
EndFunc   ;==>_WinAPI_VkKeyScan

$h = WinGetHandle('[CLASS:Notepad]')
MsgBox(0, '', $h)
$C_H = ControlGetHandle($h, '', '[CLASS:Edit; INSTANCE:1]')
_WinAPI_PostMessageW($C_H, $WM_KeyDown, _winapi_VkKeyScanW(':'), 2)

 

Result:

Screenshot_1.png

Edited by xYuri
Posted
Posted

@Nine

Oh well, thanks very much, it worked as expected,

I feel really dumb as i tried sending WM_CHAR before, but without passing it thru Asc() :frantics:.

Again THANKS!

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...