CLEO SNIPPET [SNIPPET] Set Virtual or Game Key

Parazitas

Well-Known Member
Joined
Jan 2, 2017
Messages
2,329
Likes
485
Points
133
Location
Lithuania
Website
ugbase.eu
#1
100% - Working without SAMPFUNCS

Example.:
PHP:
{$CLEO .cs}

0000: NOP

WAIT 10000

WHILE TRUE
WAIT 0

IF 0AB0:   key_pressed 90 {Z}
THEN
    0AB1: @Set_Virtual_Key 2 KeyOffSet 0x57 state 255
    WAIT 30
    0AB1: @Set_Virtual_Key 2 KeyOffSet 0x57 state 0
END

END

:Set_Virtual_Key
{
    255 = true
    0 = false
    0AB1: @Set_Virtual_Key 2 KeyOffSet 0x57 state 255
}
2@ = 0xB72CC8
0@ *= 2
005A: 2@ += 0@  // (int)
0A8C: write_memory 2@ size 1 value 1@ virtual_protect 0
0AB2: ret 0
Virtual Game key Snippets.:
PHP:
:Set_Virtual_Key
{
    255 = true
    0 = false
    0AB1: @Set_Virtual_Key 2 KeyOffSet 0x57 state 255
}
2@ = 0xB72CC8
0@ *= 2
005A: 2@ += 0@  // (int)
0A8C: write_memory 2@ size 1 value 1@ virtual_protect 0
0AB2: ret 0

:Set_Virtual_Key
// 0AB1: @Set_Virtual_Key 2 KeyOffSet 0x57 time 800
2@ = 0xB72CC8
0@ *= 2
005A: 2@ += 0@  // (int)
0A8C: write_memory 2@ size 1 value 255 virtual_protect 0
wait 1@
0A8C: write_memory 2@ size 1 value 0 virtual_protect 0
0AB2: ret 0

:Set_Virtual_Key
// 0AB1: @Set_Virtual_Key 3 KeyOffSet 0x57 lowerBorder 800 higherBorder 1000
2@ = 0xB72CC8
0@ *= 2
005A:  2@ += 0@  // (int)
0A8C: write_memory 2@ size 1 value 255 virtual_protect 0
0209: 3@ = random_int_in_ranges 1@ 2@
wait 3@
0A8C: write_memory 2@ size 1 value 0 virtual_protect 0
0AB2: ret 0

:Get_Pressed_Virtual_Key
// 0AB1: @Get_Pressed_Virtual_Key 2 KeyOffSet 0@ state 1@
FOR 0@ = 0x01 TO 0xFE STEP 0x01
    0085: 1@ = 0@
    1@ *= 2
    1@ += 0xB72CC8
    0A8D: 2@ = read_memory 1@ size 1 virtual_protect 0
    IF
    2@ == 255
    THEN
        0AB2: ret 2 0@ 2@
    END
END
0AB2: ret 0
SOME KEY OFFSET FOR VIRTUL KEYS
PHP:
ENTER = 0x121
SHIFT = 0x392
CTRL = 0x125
LALT= 0x127
SPACEBAR = 0x20
LEFT ARROW = 0x109
UP ARROW = 0x107
RIGHT ARROW = 0x10A
DOWN ARROW = 0x108
Game key Snippet.:
PHP:
:Set_Game_Key
// 0AB1: @Set_Game_key 2 KeyOffSet 0x57 State 255
2@ = 0xB731A8
0@ *= 2
005A: 2@ += 0@  // (int)
0A8C: write_memory 2@ size 1 value 1@ virtual_protect 0
0AB2: ret 0

:Get_Game_Key
// 0AB1: @Get_Game_key 1 KeyOffSet 0x41 State 0@ // A
2@ = 0xB731A8
0@ *= 2
005A: 2@ += 0@  // (int)
0A8D: 3@ = read_memory 2@ size 1 virtual_protect 0
0AB2: ret 1 3@
Hex Key codes.:
https://docs.microsoft.com/en-us/windows/desktop/inputdev/virtual-key-codes
 
Last edited:

truongvi2013

Well-Known Member
Joined
May 26, 2016
Messages
84
Likes
10
Points
58
Location
Vietnam
#4
what it does exactly?
like Fake Key press?
EDIT:
Its worked even when the game window is not focused.
 
Last edited:

ajom

Well-Known Member
Joined
Apr 14, 2020
Messages
281
Likes
129
Points
43
Location
Pluto
#5
KeyOffset(Hexadecimal) = 0x114 + Virtual Key Code Value

KeyOffset(Decimal) = 276 +
Virtual Key Code Value

PHP:
ENTER = 0x121
SHIFT = 0x392
CTRL = 0x125
LALT= 0x127
SPACEBAR = 0x20
LEFT ARROW = 0x109
UP ARROW = 0x107
RIGHT ARROW = 0x10A
DOWN ARROW = 0x108
Edit:
Im kinda comfused how to compute the Keyoffset of virtual keys, how did you get those offset values?
 
Last edited:
OP
OP
Parazitas

Parazitas

Well-Known Member
Joined
Jan 2, 2017
Messages
2,329
Likes
485
Points
133
Location
Lithuania
Website
ugbase.eu
#6
KeyOffset(Hexadecimal) = 0x114 + Virtual Key Code Value

KeyOffset(Decimal) = 276 + Virtual Key Code Value

Edit:
Im kinda comfused how to compute the Keyoffset of virtual keys, how did you get those offset values?
I did separate search for key, when i found i compared and offset wasn't same.
So i taked key adress which i found and virtual key pointer.
Key adress - virtual key pointer = offset
Since virtual key snippet multiplying offset i also split in half offset which left after all.

Now you see how i did it xD
 
Top