Question regarding c#
#1

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.
Reply
#2

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

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
Reply
#4

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;
Reply
#5

Okey, just worked it out.
Thanks!


// This thread can be locked!
Reply
#6

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

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

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

EDIT: removed.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)