[Plugin] IsKeyDown(vkey) function in PAWN
#1

This is a SERVER-ONLY key detection plugin. it detects only if the keys are pressed on the SERVER and not clients. This will NOT detect keypresses from people's games.


FIXED VERSION COMING SOON
Description

Hi, today I want to release my first plug-in. It was VERY EASY to make, and I didn't understand why no-one made a plugin like this.

The function is:

pawn Код:
IsKeyDown(vkey);
And it detects most of the keys on your keyboard. I tested it with OnPlayerUpdate, and it worked fine.

Example gamemode

pawn Код:
// Example/Test of IsKeyDown plug-in

#include <a_samp>
#include <IsKeyDown>

main() {}

public OnGameModeInit()
{
    SetGameModeText("PluginTest");
    AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 38, 1000, 0, 0, 0, 0);
    return 1;
}

public OnPlayerUpdate(playerid)
{
  if(IsKeyDown(VK_ALT)) SendClientMessage(playerid, 0x00FF00FF, "You are holding ALT");
  if(IsKeyDown(VK_CTRL)) SendClientMessage(playerid, 0x00FF00FF, "You are holding CTRL");
  return 1;
}
This is not the best example, because it spams a lot of time that message, but it would work great with other functions. You can also make your own callback with this function to replace OnPlayerKeyStateChange.

Defined Keys

I haven't defined all the keys, but the most important are in the include file:

pawn Код:
//Mouse
#define VK_LEFTBUTTON 0x01
#define VK_RIGHTBUTTON 0x02
#define VK_MIDBUTTON 0x04

//Keyboard
#define VK_CANCEL 0x03
#define VK_BACKSPACE 0x08
#define VK_TAB 0x09
#define VK_CLEAR 0x0C
#define VK_ENTER 0x0D
#define VK_SHIFT 0x10 //Any of the 2 shift keys
#define VK_LSHIFT 0xA0 //Left Shift Key
#define VK_RSHIFT 0xA1 //Right shift key
#define VK_CTRL 0x11 //Any of the 2 control keys
#define VK_LCTRL 0xA2 //Left control key
#define VK_RCTRL 0xA3 //Right control key
#define VK_ALT 0x12
#define VK_CAPSLOCK 0x14
#define VK_ESCAPE 0x1B
#define VK_SPACE 0x20
#define VK_LEFT 0x25
#define VK_UP 0x26
#define VK_RIGHT 0x27
#define VK_DOWN 0x28
#define VK_SELECT 0x29
#define VK_INSERT 0x2D
#define VK_DELETE 0x2E
#define VK_HELP 0x2F

//Keyboard Numbers
#define VK_KEYB0 0x30
#define VK_KEYB1 0x31
#define VK_KEYB2 0x32
#define VK_KEYB3 0x33
#define VK_KEYB4 0x34
#define VK_KEYB5 0x35
#define VK_KEYB6 0x36
#define VK_KEYB7 0x37
#define VK_KEYB8 0x38
#define VK_KEYB9 0x39

//Numpad
#define VK_NUMLOCK 0x90
#define VK_NUMPAD0 0x60
#define VK_NUMPAD1 0x61
#define VK_NUMPAD2 0x62
#define VK_NUMPAD3 0x63
#define VK_NUMPAD4 0x64
#define VK_NUMPAD5 0x65
#define VK_NUMPAD6 0x66
#define VK_NUMPAD7 0x67
#define VK_NUMPAD8 0x68
#define VK_NUMPAD9 0x69
#define VK_MULTIPLY 0x6A
#define VK_ADD 0x6B
#define VK_SEPARATOR 0x6C
#define VK_SUBTRACT 0x6D
#define VK_DECIMAL 0x6E
#define VK_DIVIDE 0x6F

//Function Keys
#define VK_F1 0x70
#define VK_F2 0x71
#define VK_F3 0x72
#define VK_F4 0x73
#define VK_F5 0x74
#define VK_F6 0x75
#define VK_F7 0x76
#define VK_F8 0x77
#define VK_F9 0x78
#define VK_F10 0x79
#define VK_F11 0x7A
#define VK_F12 0x7B
#define VK_F13 0x7C
#define VK_F14 0x7D
#define VK_F15 0x7E
#define VK_F16 0x7F
#define VK_F17 0x80
#define VK_F18 0x81
#define VK_F19 0x82
#define VK_F20 0x83
#define VK_F21 0x84
#define VK_F22 0x85
#define VK_F23 0x86
#define VK_F24 0x87

//Letters
#define VK_A 0x41
#define VK_B 0x42
#define VK_C 0x43
#define VK_D 0x44
#define VK_E 0x45
#define VK_F 0x46
#define VK_G 0x47
#define VK_H 0x48
#define VK_I 0x49
#define VK_J 0x4A
#define VK_K 0x4B
#define VK_L 0x4C
#define VK_M 0x4D
#define VK_N 0x4E
#define VK_O 0x4F
#define VK_P 0x50
#define VK_Q 0x51
#define VK_R 0x52
#define VK_S 0x53
#define VK_T 0x54
#define VK_U 0x55
#define VK_V 0x56
#define VK_W 0x57
#define VK_X 0x58
#define VK_Y 0x59
#define VK_Z 0x5A
Download

Source + DLL + Include

Pastebin

Credits

- [GF]Sasino97 for the plug-in
- Microsoft for Visual Studio 2010
- RyDeR' for the tutorial
- SA-MP for existing
- Mediafire
Reply
#2

Looks cool could you make setplayerkey to ? ( pleeeeeeaaassseee) XD
Reply
#3

Quote:
Originally Posted by boelie
Посмотреть сообщение
Looks cool could you make setplayerkey to ? ( pleeeeeeaaassseee) XD
Set player key I didn't understand... How can I make a player's keyboard press key automatically?
Reply
#4

well nvm..but i know it is possible to make a plugin that makes you able to simulate a key being pressed ingame.
i saw it on the removed cnpc plugin.
Reply
#5

With this you can check only default keys?
Reply
#6

__
But where is parameter playerid? When other player press .. I, the message("You are holding I") show to me too.
___
I think this work only for console xD
pawn Код:
public OnFilterScriptInit(){
    SetTimer("CheckKeys",100,1);
    return 1;
}
forward CheckKeys();
public CheckKeys()
{

  if(IsKeyDown(VK_ALT)) printf("You are holding ALT");
  if(IsKeyDown(VK_CTRL)) printf("You are holding CTRL");
  if(IsKeyDown(VK_I)) printf( "You are holding I");
}
Reply
#7

Hehe ^^.
But why are you using these libraries ?
#include "iostream"
#include "fstream"
You don't need them.

And actually, you can make a callback too.
Reply
#8

Does this need the player side to have any kind of modifications?
Reply
#9

OK, LoL I forgot to add the playerid parameter.... I'll update it now.
Reply
#10

It works only for the man who runs a Windows server, not for other players. Not bad for first plugin though. If you want it to work for all players you need to make a client-side plugin (see Audio Plugin's code) and tell them to install it.
Reply
#11

Nice done. I'm waiting a long time for this.

I will test it, and hope it will works in a good way.
Reply
#12

Quote:
Originally Posted by 0x5A656578
Посмотреть сообщение
It works only for the man who runs a Windows server, not for other players. Not bad for first plugin though. If you want it to work for all players you need to make a client-side plugin (see Audio Plugin's code) and tell them to install it.
OK, I tought it was working, but now you've reported this bug too...
I'll do that the player who presses the key must have the client-side program that sends the data from their PC to the server.


Quote:
Originally Posted by BlackBank3
Посмотреть сообщение
Nice done. I'm waiting a long time for this.

I will test it, and hope it will works in a good way.
Thanks, but there's a little bug. I'm going to fix it now.
Reply
#13

I love you so much, I don't know how I can thank you for this lol

EDIT: If you can please get the playerid parameter to work, that'd be much better

(NO HOMO)
Reply
#14

Quote:
Originally Posted by Lorenc_
Посмотреть сообщение
I love you so much, I don't know how I can thank you for this lol

EDIT: If you can please get the playerid parameter to work, that'd be much better

(NO HOMO)
I know, there's this problem, I'm making a working version now
Reply
#15

If you will do it like audio plugin, I mean you will need to install something - add callback or smth like in Audio Plugin OnClientConnect, Disconnect. I would need it for checking is player installed client or not
Reply
#16

Quote:
Originally Posted by BaubaS
Посмотреть сообщение
If you will do it like audio plugin, I mean you will need to install something - add callback or smth like in Audio Plugin OnClientConnect, Disconnect. I would need it for checking is player installed client or not
I'll also do that callbacks.

-------------------

Do I need to use a winsock library to do that?
Reply
#17

Quote:
Originally Posted by [GF]Sasino97
Посмотреть сообщение
I'll also do that callbacks.

-------------------

Do I need to use a winsock library to do that?
when I saw this I finally thouth somebody released it but lol, not xD
I'm a bit dissapointed but I can't wait for a release, I don't know how to establish a connection and the Audio plugins (client) source code is a hell of work to figure out how it works for me. But I did ****** 'Simple TCP server' etc, maybe I can help youu with making such plugin? If I ffigure some things out I can contribute some code, finally the 'open source' here will get some meaning for me
Reply
#18

Quote:
Originally Posted by Gamer_Z
Посмотреть сообщение
when I saw this I finally thouth somebody released it but lol, not xD
I'm a bit dissapointed but I can't wait for a release, I don't know how to establish a connection and the Audio plugins (client) source code is a hell of work to figure out how it works for me. But I did ****** 'Simple TCP server' etc, maybe I can help youu with making such plugin? If I ffigure some things out I can contribute some code, finally the 'open source' here will get some meaning for me
Sure , If you want to help me, I'll put lots of credits for you too

----

Before the release of this, I tought it was working, but I didn't test on more than 1 PC.
Now I understood the bug: The plugin I created processes on "samp-server.exe", so it won't work for other people.
Now the objective is to make a clientside plugin that operates on "samp.exe" in the GTA folder of a client, checks for a server connection, gets its IP and port, and on a key pression it will send to the server the pressed key, the server will recieve the message with the serverside plug-in and then pushes it to the scripts and does the functions.
Reply
#19

Nice work, but.... i need linux version
Reply
#20

Quote:
Originally Posted by Makar93
Посмотреть сообщение
Nice work, but.... i need linux version
client can be only windows, server will be linux and windows but then I need to see what type of TCP server the audio plugin uses.. sockets? or maybe something other?
Well first I will learn a bit c++ in the networking direction ^^ to make a smillar connection like client <->server
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)