Mouse being controlled my arrow keys

This is a discussion on Mouse being controlled my arrow keys within the Windows Programming forums, part of the Platform Specific Boards category; Hi, I'm trying to write a code where I can use the arrow keys to move the mouse cursor. I've ...

  1. #1
    Registered User
    Join Date
    Jul 2007
    Posts
    53

    Mouse being controlled my arrow keys

    Hi,

    I'm trying to write a code where I can use the arrow keys to move the mouse cursor. I've written my own code, but it doesn't seem to work.

    Can someone show me what my problem is?

    Here's my code:
    Code:
    LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
    	HDC	hdc;
    	PAINTSTRUCT ps ;
    	static RECT rect;
    	static int cxClient; 
    	static int cyClient; 
    	HCURSOR hCursor ;
    	
    	switch (message)
    	{
    		case WM_CREATE:
    			return 0;
    
    		case WM_KEYDOWN:
    			switch (wParam)
    			 {
    				 case VK_SHIFT:
    					 SendMessage (hwnd, WM_LBUTTONDOWN, wParam, lParam) ;
    					 return 0;
    				 case VK_LEFT:
    					 SendMessage (hwnd, WM_MOUSEMOVE, wParam, lParam);
    					 return 0;
    				 case VK_RIGHT:
    					 SendMessage (hwnd, WM_MOUSEMOVE, wParam, lParam);
    					 return 0;
    				 case VK_UP:
    					 SendMessage (hwnd, WM_MOUSEMOVE, wParam, lParam);
    					 return 0;
    				 case VK_DOWN:
    					 SendMessage (hwnd, WM_MOUSEMOVE, wParam, lParam);
    					 return 0;
    				 default:
    					 return 0;
    			 }
    			return 0;
    
    		case WM_PAINT:
    			hdc = BeginPaint(hwnd, &ps);
    			SetWindowExtEx(hdc, 1600, 1200, NULL);
    			SetViewportExtEx (hdc, cxClient, cyClient, NULL) ;
    			EndPaint(hwnd, &ps);
    			return 0;
    
    		case WM_DESTROY:
    			PostQuitMessage(0);
    			return 0;
    	}
    	return DefWindowProc(hwnd, message, wParam, lParam);
    }

  2. #2
    Registered User
    Join Date
    Mar 2007
    Posts
    416
    Can we see the WM_MOUSEMOVE message?

    I would think within the WM_MOUSEMOVE message you'd need some if statements to determine the keys that are being pressed, and move the mouse according to that.

    EDIT: Add the WM_MOUSEMOVE message to your WndProc(), and do what I said above. Also look in to simulating mouse/keyboard events on msdn.

  3. #3
    Registered User
    Join Date
    Jul 2007
    Posts
    53
    Arrite thanks for the advice, I think I have something working now.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Movement with arrow keys
    By louis_mine in forum C Programming
    Replies: 3
    Last Post: 02-06-2005, 03:35 PM
  2. Interfacing with arrow keys...
    By adityakarnad in forum Game Programming
    Replies: 1
    Last Post: 08-30-2003, 10:25 PM
  3. Ascii code for arrow keys
    By beginner in forum C Programming
    Replies: 1
    Last Post: 11-07-2002, 12:29 PM
  4. msdos arrow keys?
    By seditee in forum Game Programming
    Replies: 3
    Last Post: 05-07-2002, 11:29 PM
  5. Arrow keys
    By Nutshell in forum C Programming
    Replies: 5
    Last Post: 03-27-2002, 10:49 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21