SA-MP Forums Archive
Question regarding c# - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: Other (https://sampforum.blast.hk/forumdisplay.php?fid=7)
+--- Forum: Everything and Nothing (https://sampforum.blast.hk/forumdisplay.php?fid=23)
+--- Thread: Question regarding c# (/showthread.php?tid=397185)



Question regarding c# - GWMPT - 03.12.2012

Hello all.
On the last week, i have started learning c#.
And today, i have a small question, which i can't find the answer, or at least, it don't explain anything to me.
How can i check if the user is pressing the up / down key's?


On C, i could easly do:
PHP код:
#include <stdio.h>
#include <conio.h>
int main(void)
{
     while(
1)
     {
          if(
kbhit())
          {
                
int key getch();
                
printf("%d"key);
          }
     }
     return 
1;

And check if the key "80" and "72"(if i'm not changing the numbers for the left / right) have been "hitted" by the user.

Regards!

Ps: If you have any online link, which i could follow to my answer, i would be glad to have it.


Re: Question regarding c# - Lorenc_ - 03.12.2012

pawn Код:
protected override bool ProcessCmdKey( ref Message msg, Keys keyData )
{
    if( Keys.Up == keyData )
    {
        //Code
    }
    // Do the same thing.
    return true;
}
There.


Re: Question regarding c# - GWMPT - 03.12.2012

Quote:
Originally Posted by Lorenc_
Посмотреть сообщение
pawn Код:
protected override bool ProcessCmdKey( ref Message msg, Keys keyData )
{
    if( Keys.Up == keyData )
    {
        //Code
    }
    // Do the same thing.
    return true;
}
There.
Thanks for the answer.
A question related to that, which "directive" do we need to run the code above? It is currently giving me a error:
Код:
The type or namespace name 'Message' could not be found (are you missing a using directive or an assembly reference?)
The type or namespace name 'Keys' could not be found (are you missing a using directive or an assembly reference?)
The name 'Keys' does not exist in the current context



Re: Question regarding c# - Lorenc_ - 03.12.2012

Quote:
Originally Posted by klklt0
Посмотреть сообщение
Thanks for the answer.
A question related to that, which "directive" do we need to run the code above? It is currently giving me a error:
Код:
The type or namespace name 'Message' could not be found (are you missing a using directive or an assembly reference?)
The type or namespace name 'Keys' could not be found (are you missing a using directive or an assembly reference?)
The name 'Keys' does not exist in the current context
Hmm... Are you sure that you placed it inside the form's class?

You might be missing a library here.

pawn Код:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;



Re: Question regarding c# - GWMPT - 03.12.2012

Okey, just worked it out.
Thanks!


// This thread can be locked!


Re: Question regarding c# - Lorenc_ - 03.12.2012

Just realised, it looks like c++ not c#, lol.


Re: Question regarding c# - Bakr - 03.12.2012

Quote:
Originally Posted by Lorenc_
Посмотреть сообщение
Just realised, it looks like c++ not c#, lol.
How does it look like C++..?


Re: Question regarding c# - Gh05t_ - 03.12.2012

Quote:
Originally Posted by Bakr
Посмотреть сообщение
How does it look like C++..?
How doesn't it!


Re: Question regarding c# - Bakr - 04.12.2012

EDIT: removed.