-
[2.0] VB6 to C#
How does this if statement translate to C# (I dont get the And &H8000 )
Private Declare Function GetAsyncKeyState Lib "user32.dll" (ByVal vKey As Long) As Integer
Private Sub Timer1_Timer()
Dim keystate(1) As Integer
keystate(0) = GetAsyncKeyState(vbKeyControl)
keystate(1) = GetAsyncKeyState(vbKeyTab)
If keystate(0) And keystate(1) And &H8000 Then
'If hotkey is pressed
End If
End Sub
-
Re: [2.0] VB6 to C#
Code:
using System.Runtime.InteropServices;
using System.Windows.Forms;
// ...
[DllImport("user32")] private static extern int GetAsyncKeyState(long vKey);
private void Timer1_Timer()
{
int[] keystate = new int[2];
keystate[0] = GetAsyncKeyState(Keys.Control);
keystate[1] = GetAsyncKeyState(Keys.Tab);
if (keystate[0] & keystate[1] & 0x8000) {
// hotkey is pressed
}
}
edit: you'll need to modify the signature of the tick event handler as appropriate.
-
Re: [2.0] VB6 to C#
Remember that VB6 numbers are half the width of .NET numbers, so it should be:
Code:
private static extern short GetAsyncKeyState(int vKey);
-
Re: [2.0] VB6 to C#
Ah, yes. I read VB.NET by mistake.
Change the array to shorts as well.