[SNIPPET] Set Virtual or Game Key

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 0 _Returned: 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:
RIGHT-MOUSE = 0x3CE
LEFT-MOUSE = 0x3D9
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:

Parazitas

God
Joined
Jan 2, 2017
Messages
3,116
Solutions
5
Reaction score
882
Location
Lithuania
Added virtual game key snippets.:
1. Possibility set time.
2. Possibility set random time.
 
Last edited:

truongvi2013

Active member
Joined
May 26, 2016
Messages
82
Reaction score
10
Location
Vietnam
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
389
Solutions
2
Reaction score
268
Location
Pluto
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:

Parazitas

God
Joined
Jan 2, 2017
Messages
3,116
Solutions
5
Reaction score
882
Location
Lithuania
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
 

SamThapa

Active member
Joined
Jan 22, 2018
Messages
38
Reaction score
1
hey there :)

is it possible to set control keys ? example

Space is sprint and shift is jump

what i need is to swap them space to jump and shift to sprint when game starts if possible them please help
 
Top