Programming Input Devices. Getting the device state Schemes for processing input – Polling – Callbacks Ways to intercept messages from input devices –

Slides:



Advertisements
Similar presentations
Instruction: Use mouses left button. Use mouses left button. If mouse buttons dont work, use arrow keys of keyboard for slide show. If mouse buttons dont.
Advertisements

Instruction: Use mouses left button. Use mouses left button. If mouse buttons dont work, use arrow keys of keyboard for slide show. If mouse buttons dont.
Prof. Muhammad Saeed. Procedure-Driven Programming Event-Driven Programming Events Messages Event Handlers GUI Windows and Multitasking Queues ( System.
Intro to Computers!.
The New User Interface MEDITECH Training & Education.
Word Moving the Insertion Point. Using the Arrows  Moves one character to the right  Moves one character to the left  Moves one line up  Moves one.
DEVELOPING ICT SKILLS PART -TWO
CS7026 jQuery Events. What are Events?  jQuery is tailor-made to respond to events in an HTML page.  Events are actions that can be detected by your.
1 Computer Graphics Chapter 2 Input Devices. RM[2]-2 Input Devices Logical Input Devices  Categorized based on functional characteristics.  Each device.
EXCEL BASICS WELCOME  TODAY’S CLASS WILL COVER :  Moving Around Excel – CELLS  Highlighting, Editing, Formatting.
Key Applications Module Lesson 12 — Word Essentials
Week 3 C For Win Lecture :.  Mouse Message  Keyboard Message.
PowerPoint Lesson 2 Notes Working With Slides. Creating a New Presentation From a Theme 1.When preparing for a presentation, the best place to start is.
CHARACTERS Data Representation. Using binary to represent characters Computers can only process binary numbers (1’s and 0’s) so a system was developed.
COMPREHENSIVE Excel Tutorial 8 Developing an Excel Application.
1 Advanced Features of Keyboard Processing Suthida Chaichomchuen
Copyright 2007, Paradigm Publishing Inc. Word 2007 Chapter 3 BACKNEXTEND 3-1 LINKS TO OBJECTIVES Numbering and BulletsNumbering and Bullets Borders and.
Did you know? A few SAM Tips This presentation will review some of the tips and tricks that might enhance your SAM experience.
SDL Programming Introduction. Initialization 2  The first thing you must do is initialize SDL  int SDL_Init( SDL_INIT_EVERYTHING )  This will return.
© 2008 The McGraw-Hill Companies, Inc. All rights reserved. WORD 2007 M I C R O S O F T ® THE PROFESSIONAL APPROACH S E R I E S Lesson 22 Macros.
Events and Coordinates Lecture 5 Fri, Sep 5, 2003.
Keyboard In computing, a keyboard is an input device, partially modeled after the typewriter keyboard, which uses an arrangement of buttons or keys, to.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Typing Application Introducing Keyboard Events, Menus, Dialogs and the Dictionary.
Prepared by Fareeha Lecturer DCS IIUI 1 Windows API.
Overview of Previous Lesson(s) Over View  Visual C++ provides us with 3 basic ways of creating an interactive Windows application  Using the Windows.
Chapter 1: Hello, MFC Windows Programming Model Department of Digital Contents Sang Il Park.
Basic Computer and Word Functions, part 1 Read the information and use to answer the questions in the Basic Computer and Word Functions Study Guide.
Keyboard and Events. What about the keyboard? Keyboard inputs can be used in many ways---not just for text The boolean variable keyPressed is true if.
1. Chapter 4 Customizing Paragraphs 3 More Paragraph Changes Highlight a paragraph in Word by applying borders and shading. Sort paragraphs to control.
CSE3AGT Paul Taylor Stupid Conventions! l = Long p = Pointer h = handle g = global wnd = Windows WM = Windows Message d3d = Direct3D hr = HRESULT.
EVENT-DRIVEN PROGRAMMING. โปรแกรมและอุปกรณ์ส่วนมากที่ใช้ใน ชีวิตประจำวัน จะตอบสนองกับเหตุการณ์ที่ เกิดขึ้น ตัวอย่างของเหตุการณ์ อาทิ การเคลื่อน หรือ คลิกเมาส์
CS 480/680 Computer Graphics Programming with Open GL Part 7: Input and Interaction Dr. Frederick C Harris, Jr. Fall 2011.
Unit 1. Alternate Key Also called ALT key Executes commands with other key(s)
Direct3D Workshop November 17, 2005 Workshop by Geoff Cagle Presented by Players 2 Professionals.
Chapter 3 The mouse and the Keyboard. Getting input from the Mouse.
Basic Computer and Word Functions, part 1 Read the information and use to answer the questions in the Basic Computer and Word Functions Study Guide.
Menu Messages  Besides the all-important WM_COMMAND message, window provides five other messages at various stages of menu selection:  WM_SYSCOMMAND.
Interacting with your Computer Chapter 2 Learning Objectives Identify five key groups on standard computer keyboard Name six special purpose keys.
GUI-Based Programming ECE 417/617: Elements of Software Engineering Stan Birchfield Clemson University.
Dialog boxes Modal and modeless dialog boxes Displaying about dialog box: case WM_COMMAND : switch (LOWORD (wParam)) { case IDM_APP_ABOUT : DialogBox (hInstance,
Lesson 1 - Understanding the Word Window and Creating a New Document
Copyright 2002, Paradigm Publishing Inc. CHAPTER 13 BACKNEXTEND 13-1 LINKS TO OBJECTIVES Table Concepts Creating a Table Creating a Table Entering Text.
Computer Vocabulary Computer
The WM_NCHITTEST Message  This is an internal message used by Windows for generating all the other mouse messages.  Though it almost never needs to be.
1 Microsoft Word — Editing Rich Malloy Tech Help Today
Implement User Input Windows Development Fundamentals LESSON 2.4A.
Key Applications Module Lesson 12 — Word Essentials Computer Literacy BASICS.
Chapter 12. Copyright 2003, Paradigm Publishing Inc. CHAPTER 12 BACKNEXTEND 12-2 LINKS TO OBJECTIVES Create a Table Enter and Edit Text Delete a Table.
COMPUTER INPUT DEVICE Keyboard. Keyboard cont…… Print Screen Print contents of screen Pause/Break Terminate/Interrupt Scroll Lock Modify behavior of the.
Standard Input Devices
Programming Input Devices
Interfacing.
Windows Programming Lecture 09.
Jim Fawcett Derived from a presentation by Dmitri Volper Su ‘2001
Window.
Summer 2001 James Amyot Robert Gowans
A keyboard generates two scan codes when the user types a key
The User Interface Lecture 2 Mon, Aug 27, 2007.
GETTING TO KNOW YOUR KEYBOARD
The slides must be understood in Lecture 5
Queued and Nonqueued Messages
The program in traditional OS
CREATING, PRINTING, AND EDITING DOCUMENTS
Windows Programming Lecture 12
Benchmark Series Microsoft Word 2016 Level 2
Windows Programming Lecture 13
Moving the Insertion Point
Microsoft Excel 2007 – Level 1
Windows Development Dynadata Copyright, 2014 © DynaData S.A. 1/10.
Graphics Laboratory Korea University
Presentation transcript:

Programming Input Devices

Getting the device state Schemes for processing input – Polling – Callbacks Ways to intercept messages from input devices – WM_INPUT – WM_MOUSEMOVE – DirectInput

Basic Mouse Interaction Double Click – WM_LBUTTONDBLCLK – WM_MBUTTONDBLCLK – WM_RBUTTONDBLCLK Button Press – WM_LBUTTONDOWN – WM_MBUTTONDOWN – WM_BBUTTONDOWN Button Release – WM_LBUTTONUP – WM_MBUTTONUP – WM_RBUTTONUP WM_MOUSEMOVE WM_NCMOUSEMOVE

Keyboard Input Key inputs are handled through windows messages: – WM_KEYDOWN – WM_KEYUP – WM_CHAR The way the application uses the keyboard input will dictate which of these three inputs will be used – Using only WM_CHAR can enable Windows to factor in other events or keystrokes such as Ctrl or Shift keys being pressed

Working with Keyboard Character Code – ASCII or Unicode char. It is usually the value returned by the C function getchar() Virtual scan code – This is the value sent in the wParam variable for WM_CHAR, WM_KEYDOWN and WM_KEYUP messages OEM scan code – This is the scan code provided by the OEM. It is useful only if a code is required for a particular type of keyboard.

The lParam Variable This 32-bit variable, with 6 fields, is passed to the WndProc() – Bit 0-15 Repeat count; the number of times of keystroke is repeated – Bit bit OEM scan code – Bit 24 Extended key flag: 1 – extended key; 0 – otherwise – Bit Reserved – Bit 29 Context code: 1 – if Alt key is pressed; 0 – otherwise – Bit 30 Previous key state: 0 -- previous key up, 1 – previous key down – Bit 31 Transition state: 0 – WM_KEYDOWN, 1 – WM_KEYUP

Keystroke Messages Keystroke messages come in the form of – WM_KEYDOWN – WM_KEYUP – WM_SYSKEYDOWN – WM_SYSKEYUP All keys produce WM_KEYDOWN and WM_KEYUP messages, except – Alt and F10

Keystroke Messages cont. OEM – identifies the key to the keyboard BIOS Extended key flag – allows application to recognize duplicate keys. For these, the value is 1 – Ctrl key on right side of keyboard – Home, End, Insert, Delete, Page Up, Page Down – Number and arrow keys – Enter and forward slash (/) Transition state, previous key state, and context code are generally disregarded

Key Handling Notes WM_SYSKEYDOWN and WM_SYSKEYUP should not be processed in most cases by your code – These must eventually get to ::DefWindowProc, system keyboard commands such as Alt-Tab and Alt-Esc will stop working Failure to pass these messages to the system can result in unusual and unreliable behavior

Capturing Special keys Ctrl keys – wParam and extended bit Shift keys – wParam and Virtual key mapping Alt keys – Listen to WM_SYSCOMMAND

LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { int x=0,y=0; int repeat=0,extended=0,ext = 0,scanCode =0, wasDown=0; char text[100]; switch(message) {

case WM_CHAR: { repeat = LOWORD(lParam); scanCode = HIWORD(lParam)&0x00FF; extended = (HIWORD(lParam) >>8 ) &1; wasDown = (HIWORD(lParam)>>30)&1; sprintf(text,"WM_CHAR : Code == %d '%c' Repeat == %d SCANCODE == %d Extended = %d wasDown == %d ",wParam,wParam,repeat,extended,wasDown); MessageBox(hWnd, text,"Keyboard Event Handling",MB_OK|MB_ICONINFORMATION); } break;

case WM_KEYDOWN: { repeat = LOWORD(lParam); scanCode = HIWORD(lParam)&0x00FF; extended = (HIWORD(lParam)>>8)&1; wasDown = (HIWORD(lParam)>>30)&1; if(wParam == 17) // for Ctrl key if(extended == 1) MessageBox (hWnd, "Right control key Pressed", "Title", MB_OK|MB_ICONINFORMATION); else MessageBox (hWnd, "Left control key Pressed", "Title", MB_OK|MB_ICONINFORMATION);

if(wParam == 16) {// Shift key UINT virtualKey = MapVirtualKey(scanCode,3); if(virtualKey == VK_RSHIFT) MessageBox( hWnd,"Right Shift key Pressed","Title", MB_OK|MB_ICONINFORMATION); if(virtualKey == VK_LSHIFT) MessageBox(hWnd,"Left Shift key Pressed","Title", MB_OK|MB_ICONINFORMATION); } else { sprintf(text,"WM_KEYDOWN : Code == %d '%c' Repeat == %d scancode = %d Extended = %d ",wParam, wParam, repeat, extended); MessageBox(hWnd, text,"Keyboard Event Handling", MB_OK|MB_ICONINFORMATION); } } break;

case WM_SYSCOMMAND: MessageBox(hWnd,"Alt Key pressed", "Title", MB_OK|MB_ICONINFORMATION); break; case WM_NCMOUSEMOVE: MessageBox(hWnd,"Moved on the Title bar","Mouse Event", MB_OK|MB_ICONINFORMATION); break;

case WM_LBUTTONDOWN:{ x = LOWORD(lParam); y = HIWORD(lParam); sprintf(text,"Mouse left Click x == %d, y == %d",x,y); MessageBox(hWnd, text, "Mouse Event", MB_OK|MB_ICONINFORMATION); } break;