|
-
Mar 7th, 2013, 06:55 PM
#1
Thread Starter
New Member
MDX, SlimDX, SharpDX Tutorials, Sample Codes, Documentations and Links - for Newbies
Although years rolled by, there is still pretty much low support for beginners on this area, especially as for VB.NET, so I've decided to start a thread here and would like to ask everyone who has stuff to share in the topic to add it here. My initial contribution to the thread is a very simple and basic SharpDX VB.NET (VS 2010) keyboard reading example, here it is:
vb Code:
Imports SharpDX.DirectInput
Imports System.Windows.Forms
Module Module1
Public ApplicationWindow As New Form1
Public UserQuitted As Boolean
Sub Main()
Dim SharpDXDirectInput As New DirectInput
Dim SharpDXKeyboard As Object
Dim SharpDXKeyboardState As KeyboardState
Dim PreviousScrollLockStatePressed As Boolean = False
Dim ScrollLockStatePressed As Boolean
ApplicationWindow.Show()
SharpDXKeyboard = New Keyboard(SharpDXDirectInput)
With SharpDXKeyboard
.SetCooperativeLevel _
(ApplicationWindow, _
CooperativeLevel.Background Or CooperativeLevel.NonExclusive)
.Acquire()
End With
Console.WriteLine("Current State of the Scroll Lock key: Released")
Console.Write(StrDup(46, "-") & vbCrLf & "Press 'Q' to quit.")
Do
SharpDXKeyboardState = SharpDXKeyboard.GetCurrentState()
ScrollLockStatePressed = SharpDXKeyboardState.IsPressed(Key.ScrollLock)
If ScrollLockStatePressed <> PreviousScrollLockStatePressed Then
Console.SetCursorPosition(38, 0)
If ScrollLockStatePressed Then
Console.Write("Pressed ")
Else
Console.Write("Released")
End If
PreviousScrollLockStatePressed = ScrollLockStatePressed
End If
Application.DoEvents()
Loop Until SharpDXKeyboardState.IsPressed(Key.Q) Or UserQuitted
ApplicationWindow.Close()
SharpDXKeyboard.Unacquire()
End Sub
End Module
You need to dl and extract SharpDX to a local folder and compile the code above as a Console Application (VS 2010) in order to run it.
The following .NET references are required to be added to this project :
SharpDX.dll (SharpDXInstallFolder\Bin\Standard-net40\SharpDX.dll)
SharpDX.DirectInput.dll (SharpDXInstallFolder\Bin\Standard-net40\SharpDX.DirectInput.dll)
System.Windows.Forms - can be added from .NET reference list
Additionally, you need to add a Form named Form1 to the project with the following Form code:
vb Code:
Public Class Form1
Private Sub Form1_FormClosing(sender As Object, e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
UserQuitted = True
End Sub
End Class
This code demonstrates 3 things:
1.) Receiving keyboard input using SharpDX
2.) Using Console Applications for test purposes (coz this example could be written as a simple Windows Application, it intentionally isn't)
3.) Don't be scared of this "VS 2010 is for object oriented coding" thing 
The code itself does only 2 things:
1.) Detects the state of the ScrollLock key (pressed or released) and displays it on the Console.
2.) Quits when the user closes the appwindow (not the Console window but the Form) or presses the Q key.
To create this simple code, I used the following:
- SharpDX C# sample codes (only Joystick DirectInput Sample is present in the currently distributed pack)
- "Managed DirectX 9 Kick Start: Graphics and Game Programming" - a book by Tom Miller, also in C#
- Visual Studio 2010 Objectbrowser
Another Initial Contribution To The Topic
There's a small but pretty much interesting 'lil sample set for SlimDX, downloadable from here :
http://www.ventsim.com/files/samplesvb.zip
P.s: I know about tutorials and samples available on the official sites of SlimDX and SharpDX.
Last edited by Visualizer; Mar 7th, 2013 at 07:39 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|